Java Basic Interview Questions for Freshers
Q 1: What is the most
Important feature of java?
Ans: Java is
platform independent language.
Q 2: What do you mean
by Platform Independence?
Ans: Platform
Independence you can run and compile
program in one platform and can execute in any other platform.
Q 3: What is JVM?
Ans: The Java
interpreter along with the runtime environment required to run the Java
application in called as Java virtual machine(JVM)
Q 4: What is the
difference between a JDK and a JVM?
Ans: JDK is Java
Development Kit which is for development purpose and it includes execution
environment also. But JVM is purely a run time environment and hence you will
not be able to compile your source files using a JVM.
Q 5: What is the base
class of all classes?
Ans: java.lang.Object
Q 6: What is JIT
Compiler?
Ans: Just-In-Time(JIT)
compiler is used to improve the
performance. JIT compiles parts of the byte code that have similar
functionality at the same time,
Q 7: Are JVM's
Platform Independent?
Ans: JVM'S are not platform Independent. JVM'S are platform
Specific.
Q 8: What is are
packages?
Ans: A package is
a collection of related classes and interfaces providing access protection and
namespace management.
Q 9: What if main
method declare as private?
Ans: No,It will
compile fine but in run time it will error like main method should be in
public.cannot find main method.
Q 10: What is
platform?
Ans: A platform
is basically the hardware or software environment in which a program runs.There
are two types of platforms software and hardware.Java provides software-based
platform.
Q 11: What is meant
by Inheritance and what are its advantages?
Ans: Inheritance is the process of inheriting all the features from
a class. The advantages of inheritance are reusability of code and
accessibility of variables and methods of the super class by subclasses.
Q 12: What is the
difference between superclass and subclass?
Ans: A super class is a class that is inherited whereas sub class
is a class that does the inheriting.
Q 13: What all memory
areas are allocated by JVM?
Ans: Heap, Stack,
Program Counter Register and Native Method Stack
Q 14: What is javac ?
Ans: It produces
the java byte code from *.java file.It is the intermediate representation of
your source code that contains instructions.
Q 15: Can we mark
constructors final?
Ans: No,
Constructor cannot be declared final.
Q 16: What are two
different ways to call garbage collector?
Ans: System.gc()
OR Runtime.getRuntime().gc().
Q 17: What is the
difference between superclass and subclass?
Ans: A super class is a class that is inherited whereas sub class
is a class that does the inheriting.
Q 18: What is an
abstract class?
Ans: An abstract
class is a class designed with implementation gaps for subclasses to fill in
and is deliberately incomplete.
Q 19: What are the
states associated in the thread?
Ans: Thread
contains ready, running, waiting and dead states.
Q 20: What is the
difference between a constructor and a method?
Ans: A
constructor is a member function of a class that is used to create objects of
that class. It has the same name as the class itself, has no return type, and
is invoked using the new operator.
A method is an ordinary member function of a class. It has
its own name, a return type (which may be void), and is invoked using the dot
operator.
Q 21: What is the
difference between an Interface and an Abstract class?
Ans: An abstract
class can have instance methods that implement a default behavior. An Interface
can only declare constants and instance methods, but cannot implement default
behavior and all methods are implicitly abstract.
An interface has all public members and no implementation.
An abstract class is a class which may have the usual flavors of class members
(private, protected, etc.), but has some abstract methods.
Q 22: Can we override
a static method?
Ans: No, we
cannot override a static method. Static means class level.
Q 23: What is
synchronization?
Ans: Synchronization
is the mechanism that ensures that only one thread is accessed the resources at
a time.
Q 24: What is
deadlock?
Ans: When two
threads are waiting each other and can’t precede the program is said to be
deadlock.
Q 25: Use of
finalize() method in java?
Ans: finalize() method is used to free the allocated resource.
Q 26: Is it possible
to overload main() method of a class?
Ans: Yes, we can
overload main() method as well. But every time public static main(String[]
args) will be called automatically by JVM.Other methods need to call
explicitly.
Q 27: What is static
in java?
Ans: Static means
one per class, not one for each object no matter how many instance of a class
might exist. This means that you can use them without creating an instance of a
class.Static methods are implicitly final, because overriding is done based on
the type of the object, and static methods are attached to a class, not an
object.
A static method in a superclass can be shadowed by another
static method in a subclass, as long as the original method was not declared
final. However, you can't override a static method with a nonstatic method. In
other words, you can't change a static method into an instance method in a
subclass.
Q 28: Can I declare a
data type inside loop in java?
Ans: Any Data
type declaration should not be inside the loop. Its possible but not
recommended.
Q 29: What is final
class?
Ans: A final
class can't be extended ie., final class may not be subclassed. A final method
can't be overridden when its class is inherited. You can't change value of a
final variable (is a constant).
Q 30: Can we inherit
the constructors?
Ans: No, we
cannot inherit constructors. We can call super class constructors from subclass
constructor by using super() call.
~~~~~~ Best Of Luck ~~~~~
Post a Comment