Please enable JavaScript.
Coggle requires JavaScript to display documents.
CAREER - INTERVIEW - Java - questions prep (Most Popular Java Interview…
CAREER - INTERVIEW - Java - questions prep
Source
https://www.softwaretestinghelp.com/core-java-interview-questions/
Most Popular Java Interview Questions
1. What is Java?
Java is a
high-level programming language
and is
platform independent
.
Java is a collection of objects. It was developed by Sun Microsystems. There are a lot of applications, websites and Games that are developed using Java.
Platform independent = programming language or framework that will work on any OS (Java is, but C and C++, for instance, are not).
2. What are the features in Java?
Platform independent
OOPS concepts
OO
inheritance
encapsulation
polymorphism
abstraction
JIT
Just In Time compiler
enables high performance in Java
JIT converts the bytecode into machine language and then the JVM starts the execution
Multi-threaded
thread = one flow of execution
JVM = creates a thread called main thread
user can create multiple threads by extending the thread class or by implementing a runnable interface
3. How does Java enable high performance?
Java uses Just In Time compiler to enable high perf. JIT is used to convert the instructions into bytecodes.
Warning
: is JIT used to convert instruction > bytecodes or bytecodes to machine language (as mentioned in Q2)
4. What are the Java IDE's?
Eclipse & NetBeans
5. What do you mean by Constructor?
When a new object is created in a program a constructor gets invoked corresponding to the class.
The constructor is a method which has the same name as class name.
If a user doesn’t create a constructor implicitly a default constructor will be created.
The constructor can be overloaded.
If the user created a constructor with a parameter then he should create another constructor explicitly without a parameter.
Should not return a value, not even void
Constructor overloading is a technique in Java in which a class can have any number of constructors that differ in parameter list. The compiler differentiates these constructors by taking into account the number of parameters in the list and their type.
6. What is meant by local variable and instance variable?
Local variable
defined in the method and scope of the variables that have existed inside the method itself.
Instance variable
defined inside the class and outside the method and scope of the variables exist throughout the class.
7. What is a class?
All Java codes are defined in a class. A class has variables and methods.
Variables
are attributes which define the state of a class.
Methods
are the place where the exact business logic has to be done. It contains a set of statements (or) instructions to satisfy the particular requirement.
8. What is an object?
An
instance of a class
is called object. The object has a
state and behavior
. Whenever the JVM reads the "
new()
" keyword, then it will create an instance of that class.
9. What are the OOPS concepts?
interface
abstraction
polymorphism
inheritance
encapsulation
10. What is inheritance?
Inheritance means one class can extend to another class. So that the code can be reused from one class to another class. Existing class is known as
super class
whereas the derived class is known as a
sub class
.
Inheritance is applicable for
public
and
protected
members only.
Private
members
cannot be inherited
.
11. What is encapsulation?
Why?
protects the code from others
code maintainability
How?
make the variable
private
or
protected
use public accessors methods such as
set<property>
and
get<property>
12. What is polymorphism?
A single object can refer to the
super class
or
sub-class
depending on the reference type which is called polymorphism. Polymorphism is applicable for
overriding
and not for
overloading
.
13. What is meant by method overriding?
Conditions (sub/super class)
return type should be the same
method name should be the same
argument(s) should be the same
14. What is meant by overloading?
Rem: can happen for different classes or within the same class
Conditions
same method name
different argument type
possibly different return types
15. What is meant by interface?
Multiple inheritance cannot be achieved in Java. To overcome this problem, the interface concept has been introduced.
An
interface
is a
template
which has only
method declarations
and no
method implementation
.
The class which implements the interface should provide implementation for all the methods declared in the interface.
16. What is meant by abstract class?
We can create an abstract class by using the "abstract" keyword before the class name. An abstract class can have bot
abstract
methods and
non-abstract
methods that are a concrete class.
The concrete sub-class which extends an abstract class should provide the implementation for abstract methods.
not finished