Java equivalent of .NET constructs?

Java from a C# developer's perspective Although for you its the other way round :).

To answer your specific questions: Properties By convention, Java uses "get" or "set" followed by the variable name in upper camel case. For example, "getUserIdentifier()". Booleans often will use "is" instead of "get" Constructors In Java, superclass constructors are called first, descending down the type hierarchy.

Events By convention (this is the one you'll get the least agreement on...different libraries do it slightly differently), Java uses methods named like "addEventTypeListener(EventTypeListener listener)" and "removeEventTypeListener(EventTypeListener listener)", where EventType is a semantic name for the type of event (like MouseClick for addMouseClickListener) and EventTypeListener is an interface (usually top-level) that defines the methods available on the receivers - obviously one or more of those references is essentially a "fire" method. Additionally, there is usually an Event class defined (for example, "MouseClickEvent"). This event class contains the data about the event (perhaps x,y coordinates, etc) and is usually an argument to the "fire" methods.

Wikipedia has a nice in depth comparison here: en.wikipedia.org/wiki/Comparison_of_C_Sh....

That page, while informative, does not answer his specific questions. It does not detail the behavior of java constructors or the conventions of java bean properties, and doesn't touch on event handling. – Jherico Jun 4 '09 at 19:25.

A bean property in java is preceeded by a get followed by the bean name starting with a capital letter. For instance the property 'color' would be associated with the methods 'getColor()' and 'setColor(int color)' (assuming the property is of type int). There is a special case for boolean properties, the getter will be called 'is'... as in 'isWhite()', 'isBlack()'.

The setter remains the same. When a class is created in java, all its parent class constructors are called in order, parents before children. Events in Java are specific to a given event model, and not a core part of the language.

Examine the documentation for Swing or SWT for information on the event models of those GUI toolkits.

Sun's Code Conventions are a great reference for the Java way of doing and naming things.

Property getters and setters can go by whichever naming convention you desire, or that your organization has standardized. A good naming convention is simply one that is common among those who will use/see it. That said, most in the Java community use 'getSomething/setSomething' as the naming convention on getters and setters.

Base constructors are called automatically, just like C#.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions