Tuesday, September 10, 2019

Java Interview Question

Q #1) What is JAVA?
Ans: 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.
Q #2) What are the features in JAVA?
Ans: Features of Java:
  • Oops concepts
    • Object-oriented
    • Inheritance
    • Encapsulation
    • Polymorphism
    • Abstraction
  • Platform independent: A single program works on different platforms without any modification.
  • High Performance: JIT (Just In Time compiler) enables high performance in Java. JIT converts the bytecode into machine language and then JVM starts the execution.
  • Multi-threaded: A flow of execution is known as a Thread. JVM creates a thread which is called main thread. The user can create multiple threads by extending the thread class or by implementing Runnable interface.
Q #3) How does Java enable high performance?
Ans: Java uses Just In Time compiler to enable high performance. JIT is used to convert the instructions into bytecodes.
Q #4) What are the Java IDE’s?
Ans: Eclipse and NetBeans are the IDE's of JAVA.
Q #5) What do you mean by Constructor?
Ans: The points given below explain what a Constructor is in detail:
  • 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.
Q #6) What is meant by Local variable and Instance variable?
Ans: Local variables are defined in the method and scope of the variables that have existed inside the method itself.
An instance variable is defined inside the class and outside the method and scope of the variables exist throughout the class.
Q #7) What is a Class?
Ans: 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.
Example:
1public class Addition{ //Class name declaration
2int a = 5//Variable declaration
3int b= 5;
4public void add(){ //Method declaration
5int c = a+b;
6}
7}
Q #8) What is an Object?
Ans: An instance of a class is called object. The object has state and behavior.
Whenever the JVM reads the “new()” keyword then it will create an instance of that class.
Example:
1public class Addition{
2public static void main(String[] args){
3Addion add = new Addition();//Object creation
4}
5}
The above code creates the object for the Addition class.
Q #9)What are the Oops concepts?
Ans: Oops concepts include:
  • Inheritance
  • Encapsulation
  • Polymorphism
  • Abstraction
  • Interface
Q #10) What is Inheritance?
Ans: Inheritance means one class can extend to another class. So that the codes 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.
Example:
1Super class:
2public class Manupulation(){
3}
4Sub class:
5public class Addition extends Manipulation(){
6}
Inheritance is applicable for public and protected members only. Private members can’t be inherited.

No comments:

Post a Comment

Which Python course is best for beginners?

Level Up Your Python Prowess: Newbie Ninjas: Don't fret, little grasshoppers! Courses like "Learn Python 3" on Codecade...