0% found this document useful (0 votes)
50 views

Java Ques

The document discusses differences between C++ and Java, components of the Java development kit (JDK), Java virtual machine (JVM) memory areas, how Java achieves platform independence, classloaders, and other Java concepts. It provides definitions and explanations of terms like JDK, JRE, JVM, classloader, bytecode, and how Java's write once run anywhere nature works. It also answers questions about Java keywords, variables, objects, access specifiers, static methods/variables, packages, constructors, interfaces and more.

Uploaded by

Shashank Pandey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views

Java Ques

The document discusses differences between C++ and Java, components of the Java development kit (JDK), Java virtual machine (JVM) memory areas, how Java achieves platform independence, classloaders, and other Java concepts. It provides definitions and explanations of terms like JDK, JRE, JVM, classloader, bytecode, and how Java's write once run anywhere nature works. It also answers questions about Java keywords, variables, objects, access specifiers, static methods/variables, packages, constructors, interfaces and more.

Uploaded by

Shashank Pandey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

What are the differences between C++ and Java?

1. Pointers
2. Platform dependence
3. Multiple inheritance
4. Nearness to hardware
5. Compiled vs compiled+interpreted

What is the difference between JDK, JRE, and JVM?


JVM is an acronym for Java Virtual Machine; it is an abstract machine which provides the runtime
environment in which Java bytecode can be executed.

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

How many types of memory areas are allocated by JVM(jvm


architecture)?
 Class (Method) Area : stores pre class structures eg runtime constant pool
 Heap : objects
 Stack : frames of methods/variables
 Program Counter Register : address of currently executing instruction
 Native Method Stack : contains native methods(refer JNI)

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.

 Bootstrap Class Loader: rt.jar files


 Extension Class Loader: loads libraries from extension folder of java directory
 System/Application Class Loader: loads classes from classpath

Is delete, next, main, exit or null keyword in java?


 NO

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 the default value of the local variables?


 The local variables are not initialized to any default value, neither primitives nor object
references.

What will be the initial value of an object reference which is defined as an


instance variable?

 All object references are initialized to null in Java.

 What are the various access specifiers in Java?


What is the purpose of static methods and variables?
The methods or variables defined as static are shared among all the objects of the class. The static
is the part of the class and not of the object. The static variables are stored in the class area, and
we do not need to create the object to access such variables. Static variable gets memory only
once in the class area at the time of class loading.

What are the advantages of Packages in Java?

 Packages avoid the name clashes.


 The Package provides easier access control.
 It is easier to locate the related classes.

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.

What is the difference between an object-oriented programming language


and object-based programming language?

 Object based do not have inheritance and polymorphism


 Object based have inbuilt objects but object oriented don’t
 Eg of object based – javascript, VBscript

What is the purpose of a default constructor?


The purpose of the default constructor is to assign the default value to the objects. The java
compiler creates a default constructor implicitly if there is no constructor in the class.

Does constructor return any value?

 yes, The constructor implicitly returns the current instance of the class (You can't use an explicit return type
with the constructor).

Is constructor inherited and can you make a constructor final?


No, the constructor is not inherited. No, the constructor can't be final.
What do you understand by copy constructor in Java?
There is no copy constructor in java. However, we can copy the values from one object to another
like copy constructor in C++.There are many ways to copy the values of one object into another in
java. They are:

 By constructor
 By assigning the values of one object into another
 By clone() method of Object class

What are the differences between the constructors and methods?

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

Java static block


 Is used to initialize the static data member.
 It is executed before the main method at the time of classloading.

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.

You might also like