- What is constant variable in Java?
The constant variable should be declared as static and final. So only one copy of the variable exists for all instances of the class and the value can't be changed.
- Should a main method be mandatory declared in all java classes?
No it is not required. main method should be defined only if the source class is a java application.
- What is the return type of the main method?
Main method doesn't return anything therefore it declared void.
- Why is the main method declared static?
main method is called by the JVM yet before the instantiation of the class hence it is declared as static.
- What is the argument of main method?
The main method accepts an array type of String object as an argument.
- Can main method be overloaded?
Yes. You can have any number of main methods with different method signature and implementation in the class.
- Can a main method be declared final?
Yes. Any inheriting class will not be able to have it's own default main method.
- Why isn’t there operator overloading? - Because C++ has proven by example that operator overloading makes code almost impossible to maintain. In fact there very nearly wasn’t even method overloading in Java, but it was thought that this was too useful for some very basic methods like print(). Note that some of the classes like DataOutputStream have unoverloaded methods like writeInt() and writeByte().
- How do I convert a numeric IP address like 192.168.10.204 into a hostname like javasks.blogspot.com?
String hostname = InetAddress.getByName("192.168.10.204").getHostName();
- Why do threads block on I/O? - Threads block on I/O (that is enters in the waiting state) so that other threads may execute while the I/O operation is performed.