Java Ques
Java Ques
1. Pointers
2. Platform dependence
3. Multiple inheritance
4. Nearness to hardware
5. Compiled vs compiled+interpreted
It is used to provide the runtime environment. It is the implementation of JVM. It physically exists. It
contains a set of libraries + other files that JVM uses at runtime.
JDK is an acronym for Java Development Kit. It is a software development environment which is used to
develop Java applications and applets. It physically exists. It contains JRE + development tools
What gives Java its 'write once and run anywhere' nature?
The bytecode. Java compiler converts the Java programs into the class file (Byte Code) which is the
intermediate language between source code and machine code. This bytecode is not platform specific and
can be executed on any computer. Java compilers are designed in such a way that converts source
code into platform independent form i-e byte codes. These byte codes are then converted to
machine code by interpreter.
What is classloader?
Classloader is a subsystem of JVM which is used to load class files. Whenever we run the java program, it is
loaded first by the classloader.
If I don't provide any arguments on the command line, then what will the
value stored in the String array passed into the main() method, empty or
NULL?
Empty, but not null
What is an object?
The Object is the real-time entity having some state and behavior. In Java, Object is an instance of the class
having the instance variables as the state of the object and the methods as the behavior of the object.
yes, The constructor implicitly returns the current instance of the class (You can't use an explicit return type
with the constructor).
By constructor
By assigning the values of one object into another
By clone() method of Object class
What are the restrictions that are applied to the Java static methods?
Two main restrictions are applied to the static methods.
The static method cannot use non-static data member or call the non-static method directly.
this and super cannot be used in static context as they are non-static.
Static methods cannot be overriden
Interfaces
If a class implements an interface and does not provide method bodies for all
functions specified in the interface, then the class must be declared abstract.
Interfaces are used to implement abstraction. So the question arises why use
interfaces when we have abstract classes. The reason is, abstract classes may
contain non-final variables, whereas variables in interface are final, public and
static.
All the methods are public and abstract. And all the fields are public, static, and
final.