File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes void Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "void" Watch "void" New topic
Author

void

anuj thite
Ranch Hand

Joined: Apr 14, 2009
Posts: 49
Hello all members,

I am new to java programming.

i know that constructor can't return any value not even void.

what does it mean ???
Can you tell me the difference between "void" and no return value.

Please help.

Thanks in advance.
Pawan Arora
Ranch Hand

Joined: Sep 14, 2008
Posts: 105

you cannot represent 'void' it is just a keyword in the java language

a method with void in its declartion does not return a 'void' it returns nothing
Brian Legg
Ranch Hand

Joined: Nov 07, 2008
Posts: 488
All methods must have a return type. I believe that "void" is just to allow the compiler know that a particular method will have a return type of nothing aka will not return any data. A constructor on the other hand is not a method, even though they are similar... therefor you can't declare one as having a return type, including void. The compiler already knows what a constructor does so it does not need void added.

That's my understanding on it anyways.


SCJA
~Currently preparing for SCJP6
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19685
    
  20

Brian Legg wrote:All methods must have a return type. I believe that "void" is just to allow the compiler know that a particular method will have a return type of nothing aka will not return any data. A constructor on the other hand is not a method, even though they are similar... therefor you can't declare one as having a return type, including void. The compiler already knows what a constructor does so it does not need void added.

That's my understanding on it anyways.

In fact, if you add void to a constructor, it becomes an ordinary method - that just happens to have the same name as the class:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Brian Legg
Ranch Hand

Joined: Nov 07, 2008
Posts: 488
I completely forgot about that Rob. Funny how many things are allowed in programming languages which are terrible ideas
anuj thite
Ranch Hand

Joined: Apr 14, 2009
Posts: 49
Rob Prime wrote:
Brian Legg wrote:All methods must have a return type. I believe that "void" is just to allow the compiler know that a particular method will have a return type of nothing aka will not return any data. A constructor on the other hand is not a method, even though they are similar... therefor you can't declare one as having a return type, including void. The compiler already knows what a constructor does so it does not need void added.

That's my understanding on it anyways.

In fact, if you add void to a constructor, it becomes an ordinary method - that just happens to have the same name as the class:



Thanks a lot Rob.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: void