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
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
Joined: Aug 27, 2003
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
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
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:
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.