Interview Question of Java: Most Asked Questions In Interview Set: 1

0
19749
Interview Question of Java
Interview Question of Java

Interview Question of Java: Most Asked Questions In Interview Set: 1

Interview Question of Java Set 1:

1. What do you understand by Java?

  • Java is an object-oriented computer language.
  • It is a high-level programming language developed by James Gosling in Sun Microsystems in the year 1995.
  • Java is a fast, secure, and reliable language used for many games, devices, and applications.

2. Describe Major Features of Java.

  • Object-oriented: Java is based on object-oriented programming where the class and methods describe the state and behavior of an object.
  • Portable: A Java program gets converted into Java bytecodes that can be executed on any platform without any dependency.
  • Platform independent: Java works on the ‘write once, run anywhere’ principle as it supports multiple platforms like Windows, Linux, Mac, Sun Solaris, etc.
  • Robust: Java has strong memory management as there are no pointer allocations. It has an automatic garbage collection that prohibits memory leaks.
  • Interpreted: As mentioned, Java compiler converts the codes into Java bytecodes which are then interpreted and executed by Java Interpreter.

3. What do you mean by an object?

An object consists of methods and classes that depict its state and perform operations. A Java program contains a lot of objects instructing each other their jobs. This concept is part of core Java.

4. What is a class in Java?

Java encapsulates codes in various classes that define new data types. These new data types are used to create objects.

5. Differentiate between JDK, JRE, and JVM.

  • JVM stands for Java Virtual Machine which provides the runtime environment for Java bytecodes to be executed.
  • JRE (Java Runtime Environment) includes the sets of files required by JVM during runtime.
  • JDK (Java Development Kit) consists of JRE along with the development tools required to write and execute a program.

6. What is Inheritance in Java?

Java includes the feature of inheritance which is an object-oriented programming concept. Inheritance lets a derived class inherit the methods of a base class, This is Important Interview Question of Java.

7. What is Method Overloading in Java

When a Java program contains more than one method with the same name but with different properties, then it is called method overloading.

8. Compare overloading with overriding concept in Java.

Overloading refers to the case of having two methods of the same name but different properties whereas, overriding occurs when there are two methods of the same name and properties, but one is in the child class and the other is in the parent class.

9. What are the various access specifiers for Java classes?

  • In Java, access specifiers are the keywords used before a class name which defines the access scope. The types of access specifiers for classes are:
  • Public: Class,Method,Field is accessible from anywhere.
  • Protected: Method,Field can be accessed from the same class to which they belong or from the sub-classes,and from the class of same package,but not from outside.
  • Default: Method,Field,class can be accessed only from the same package and not from outside of it’s native package.
  • Private: Method,Field can be accessed from the same class to which they belong.

10. What’s the purpose of Static methods and static variables?

When there is a requirement to share a method or a variable between multiple objects of a class instead of creating separate copies for each object, we use static keyword to make a method or variable shared for all objects.

11. What is a singleton class in Java?

A singleton class in java can have only one instance and hence all its methods and variables belong to just one instance. Singleton class concept is useful for the situations when there is a need to limit the number of objects for a class.

12. What do you mean by Constructor?

Constructor gets invoked when a new object is created. Every class has a constructor. If we do not explicitly write a constructor for a class the java compiler builds a default constructor for that class. This is Important Interview Question of Java

13. Can we declare the main method of our class as private?

In java, main method must be public static in order to run any application correctly. If main method is declared as private, developer won’t get any compilation error however, it will not get executed and will give a run time error.

14. How an object is serialized in Java?

In java, to convert an object into byte stream by serialization, an interface with the name Serializable is implemented by the class. All objects of a class implementing Serializable interface get serialized and their state is saved in byte stream.

15. Can a class have multiple constructors?

Yes, a class can have multiple constructors with different parameters. Which constructor gets used for object creation depends on the arguments passed while creating the objects.

16. Can we override static methods of a class?

We cannot override static methods. Static methods belong to a class and not to individual objects and are resolved at the time of compilation (not at runtime).Even if we try to override static method,we will not get an complitaion error,nor the impact of overriding when running the code.

17. Is String a data type in java?

String is not a primitive data type in java. When a string is created in java, it’s actually an object of Java.Lang.String class that gets created. After creation of this string object, all built-in methods of String class can be used on the string object.

18. What’s the difference between an array and Vector

An array groups data of same primitive type and is static in nature while vectors are dynamic in nature and can hold data of different data types.

19. What is multi-threading?

Multi threading is a programming concept to run multiple tasks in a concurrent manner within a single program. Threads share same process stack and running in parallel. It helps in performance improvement of any program.

20. Why Runnable Interface is used in Java?

Runnable interface is used in java for implementing multi threaded applications. Java.Lang.Runnable interface is implemented by a class to support multi threading.

21. How garbage collection is done in Java?

In java, when an object is not referenced any more, garbage collection takes place and the object is destroyed automatically. For automatic garbage collection java calls either System.gc() method or Runtime.gc() method.

22. What is Difference Between Abstraction & Encapsulation?

Knowing the difference between abstraction and encapsulation is the key to understand both the concept in deep. You cannot learn either of both in isolation. They walk along in Java, so they must be understood collectively.

23. What is an Exception?

An exception is a problem that arises during the execution of a program. Exceptions are caught by handlers positioned along the thread’s method invocation stack.

24. When throws keyword is used in Java?

If a method does not handle a checked exception, the method must declare it using the throws keyword. The throws keyword appears at the end of a method’s signature.

25. What is Polymorphism?

Polymorphism is the ability of an object to take on many forms. The most common use of polymorphism in OOP occurs when a parent class reference is used to refer to a child class object.

If You Want To Get More Daily Such Interview Questions Updates Then Press Red Bell Icon At The Right Side of Page To Subscribe our Updates.

High Paying Jobs For Java Developer: Click here

Also Read:Interview Question In Python Interview: Click here

Join Whatsapp Group of Daily Jobs Updates for 2010-2020 Batch: Click Here

Subscribe Our Telegram Channel for Interview Questions: Click here

Also Read: Daily Morning Skin Care For Glowing Skin: Click here

Also Read:How To Get a Job Easily: Professional Advice For Job Seekers: Click here

LEAVE A REPLY

Please enter your comment!
Please enter your name here