• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

signed float & double

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Deep that was helpful
 
Ranch Hand
Posts: 8946
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1090
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 8946
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The big question is who is going to use the return value of main ?
 
Thomas Paul
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 8946
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic