File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

signed float & double

 
nandini paruchuri
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 133
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Deep that was helpful
 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JavaRanch newsletter had an article about numbers are stored in floats.
http://www.javaranch.com/newsletter/July2003/newsletterjuly2003.jsp#a4
 
nandini paruchuri
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1090
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8927
Firefox Browser Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The big question is who is going to use the return value of main ?
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8927
Firefox Browser Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13974
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic