This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Constructor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Constructor" Watch "Constructor" New topic


Sherman Hung

Joined: Dec 15, 2001
Posts: 17
In my reading, there are lots of references to CONSTRUCTOR. What exactly does the word constructor mean? Sometimes, it means a class, a object. . .
Valentin Crettaz
Gold Digger

Joined: Aug 26, 2001
Posts: 7610
Basically, a constructor is used to construct a new object, i.e. an new instance of a class.
This link will help you understand what a constructor is:
JLS 8.8 Constructor Declarations

[Blog] [Blogroll] [My Reviews] My Linked In
Pradeepa Battina

Joined: Jan 08, 2002
Posts: 3
1.A constructor is a method with the same name as that of the class.
2.It doesn't have any return type.
3.It is generally used for initialization of instance variables.
This are the basic things about a constructor.
Shivaji Marathe
Ranch Hand

Joined: Jan 11, 2002
Posts: 203
Check out the Java tuotrial at
You can also search the tutorial site for the word Constructor.
Valentin Crettaz
Gold Digger

Joined: Aug 26, 2001
Posts: 7610
Just adding my $0.02 to what Pradeepa said:
A constructor IS NOT a method. It looks like one (without the return type, though). The difference lies in the way constructor are invoked, a constructor is NEVER invoked the same way as a method. Constructors are invoked by class instance creation expressions (JLS 15.9, Dave Vick's article in the January Newsletter). Constructors are NEVER invoked by method invocation expressions (JLS 15.12 + article in the February Newsletter).
Sorry for being picky...
Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521
Just to make things muddier . . . We were discussing the same topic in Beginner.

"JavaRanch, where the deer and the Certified play" - David O'Meara
I agree. Here's the link:
subject: Constructor
It's not a secret anymore!