This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes signed float & double Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "signed float & double" Watch "signed float & double" New topic
Author

signed float & double

nandini paruchuri
Greenhorn

Joined: Aug 27, 2003
Posts: 13
Hi all:
Are Java types float and double signed???
Why should the return type of main() method should always be "void"???
I kind of know answers for both the questions but I just want to confirm.
TIA
nandini
swetha shah
Greenhorn

Joined: Aug 21, 2003
Posts: 7
Hi
Both float and double are signed data types in java.
The signature of main method to start execution is

public static void main(String a[]).
The return type of main is always void.
Regards
S S
nandini paruchuri
Greenhorn

Joined: Aug 27, 2003
Posts: 13
I do understand its the main() signature but I just wanted to know why??
I mean public and static make perfect sense but why void??
And how do we represent float and double in byte format i.e
i.e for integer 1 can represented in 0000 0001
Thanks
nandini
Deep Chand
Ranch Hand

Joined: Dec 17, 2002
Posts: 133
Nandini: And how do we represent float and double in byte format i.e
i.e for integer 1 can represented in 0000 0001
The floats are represented using 32 bits. The left most (bit 31) is sign bit. Then bit 23-30 are used for mantissa (decimal portion of number) and bits 0-22 are the magnitude.
Thanks,
Deep
nandini paruchuri
Greenhorn

Joined: Aug 27, 2003
Posts: 13
Thanks Deep that was helpful
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8904

The main method serves as the starting point of a program execution and it is not expected to return anything. Every method in java requires a return type and since main returns nothing the retrun type is "void".
Does this help?
:roll:


Groovy
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
The JavaRanch newsletter had an article about numbers are stored in floats.
http://www.javaranch.com/newsletter/July2003/newsletterjuly2003.jsp#a4


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
nandini paruchuri
Greenhorn

Joined: Aug 27, 2003
Posts: 13
Pradeep:
Yeah it surely helps but I just wanted to understand the logic behind main() method not returning anything.
Thanks
nandini
Anupam Sinha
Ranch Hand

Joined: Apr 13, 2003
Posts: 1088
Hi Nandini
I don't really know the logic behind it but I guess the following might be :
1. Generally main() method is the last method to return so there is not much point in returning anything.
2. Generally no one calls the main() method during execution except in the begining.
3. Even if main was to return anything then what would it be? int, float, String ...
Let's say we have few main() methods for the primitive data types and one for the Object i.e. few return primitive data type and one version returns Object. Then in case if you wish to overload the main() method in your program how would you do it. The compiler would not be able to determine the entry point for the application.
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8904

The big question is who is going to use the return value of main ?
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Since the main method is the starting point, what would it be returning to? If the Java program is part of a script then you can use System.exit(int) to send a message to the script.
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8904

If the Java program is part of a script then you can use System.exit(int) to send a message to the script.

But aren;t we talking about the return type of main method and not about JVM extit ?
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Originally posted by Pradeep Bhat:
But aren;t we talking about the return type of main method and not about JVM extit ?

Yes. I was just showing that if you did need to somehow return a value from the main method to an invoking script that it can be done.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: signed float & double
 
Similar Threads
Float wrapper from double. Bonkers?
Widening
Can anyone tell the result of this code.
Why char doesn't take byte
Implicit casting Q