6

Before the introduction of annotations in Java, how was the same functionality achieved?

Such a huge portion of what I do every day in Java involves annotations that I can't imagine what it would be like to program without them.

What would be an alternative way of achieving the same functionality without annotations?

Dieter Gantz
  • 195
  • 2
  • 3
  • 7
  • This is a very open-ended question, as annotations can be used to do dozens of things. Exactly what are you doing with annotations that you want to ask about? – Darron Sep 22 '10 at 13:04
  • 3
    Dunno. I grew up before annotations, so I very rarely use them. It's one of those things where occasionally it's useful, but I often wonder why they bothered to add them. :-) You just get used to what's available at the time. – Brian Knoblauch Sep 22 '10 at 13:04
  • 2
    @Brian: that sounds pretty dysfunctional. I grew up before annotations as well, but I am very aware that they turned some aspects of Java programming (Most notably EJBs) from a horrible, inhumane brain-torture into something simple and downright pleasant. – Michael Borgwardt Sep 22 '10 at 13:18
  • @Dieter Gantz: Honestly I don't know, even though I've been coding in Java since 1999. The thing is, you need to realize that **today** most Java programmers are still not using @NotNull and dealing with countless pointless NullPointerException that would never happen in the first place should they use the @NotNull annotation. I guess 98% of the Java programs out there aren't using @NotNull, which is mindboggling. – SyntaxT3rr0r Sep 22 '10 at 14:06
  • You could emulate annotations in javadoc if you had to. Early versions of TestNG did that for java 4 compatibility. You had to point the runtime towards the source directory. – Bill Michell Sep 22 '10 at 14:35
  • Extensive use of base classes. Cf the difference between JUnit 3 and JUnit 4 annotations. – Bill Michell Sep 22 '10 at 14:37
  • Conventional naming. Test methods in JUnit starting with test, for example. – Bill Michell Sep 22 '10 at 14:38
  • 1
    this is a legitimate question, people understand what it refers to and there are informative answers. DON'T BE A NAZI. Just because you don't get it, doesn't mean it's meaningless. – irreputable Sep 22 '10 at 21:51
  • Some of us *still* don't know how Java programmers survive. I was going to ask how Java programmers survived before closures, but some quick googling shows that's still the case. :-) – Ken Sep 24 '10 at 17:08

8 Answers8

6

Alex, I would take XML for $400.

Alexander Pogrebnyak
  • 44,836
  • 10
  • 105
  • 121
6

They where two techniques:

  • One was to use XML configuration files, related to your Java classes (an example is JPA XML configuration files).
  • In some cases, where your just needed a marker on a class, marker interfaces where used. Is consists in having an interface with no methods, and you can check at runtime if a given object implements this interface. One pretty common sample is Serializable.
Vivien Barousse
  • 20,555
  • 2
  • 63
  • 64
4
  • XDoclet - basically a code generator that takes information from the Java source code and custom javadoc tags.
  • Marker interfaces like Serializable
  • Naming conventions (test methods in JUnit)
  • And yes, lots of XML config files. Be very glad you haven't had to live with those.
Michael Borgwardt
  • 342,105
  • 78
  • 482
  • 720
3

By writing a lot of xml configuration files.

Giorgos Dimtsas
  • 12,019
  • 3
  • 29
  • 40
3

I don't know what you mean; I don't use annotations, but here I am still alive as ever.

jonescb
  • 22,013
  • 7
  • 46
  • 42
3

Other ways (beside XML config files--which probably also includes use of Spring) would be lots of properties files.

Chris Aldrich
  • 1,904
  • 1
  • 22
  • 37
2
  • Properties file.
  • XML configurations
  • Text-based custom files.
  • Interface class file with many constant fields....
Buhake Sindi
  • 87,898
  • 29
  • 167
  • 228
0

They are very nice features but they are creating more confusion for me as I used to define them in comments e.g. @author, @return, and @deprecated etc. I skip most of the comments and therefore, It creates more confusion rather than a convenience for me.

Ibrahim
  • 1,247
  • 3
  • 13
  • 21
  • 3
    Annotations and Javadoc tags are two totally different things even though they look similar. A good editor should use syntax highlighting to make them look clearly different. – Michael Borgwardt Sep 22 '10 at 13:34
  • I know they are different and coloring them might work for some people, but I also do programming in Perl and my eyes are trained for symbols like @, $, and %. It is because of this @ that ignore some important piece of code. – Ibrahim Sep 22 '10 at 14:13