Core Java interview questions

Core Java Interview Questions

Here are some Core Java interview questions, which help us to clear college interviews. Here you can find best and to the point core java interview questions.

Ques 1: Is Java a platform-dependent or platform-independent language. Explain?

Answer: Java is a platform-independent language which means we can write java programs on one platform and we can run it on another. This is an amazing feature of java which makes the coder flexible with java.

Ques 2: What is the difference between java and C++ language?

Answer :

  • Java is a platform-independent language whereas C++ is platform dependent language. Once written on a C++ platform, the code cannot be run and compiled on any other platform in C++.
  • Java doesn’t supper β€˜goto’ statement whereas C++ supports goto statements.
  • Java doesn’t support multiple inheritances whereas C++ supports multiple inheritances.
  • C++ has a virtual keyboard which comes into play when the methods of parent class are overridden by the child class.
  • Java supports multi-threading whereas it is not supported in case of C++.

Ques 3: What is javac and how do we use it?

Answer: javac is a java compiler that compiles the java code program and helps to generate byte-code through it. Further, JVM runs that byte when we want to perform the execution of the program.

Ques 4: What is wrapper class in Java?

Answer: The class in java used to convert primitive data types into objects is called the wrapper class in Java. We have 8 primitive data types in java which are byte, short, int, Boolean, long, double, float etc. Which are already defined in Java? These data types are not objects.  This process is also called as auto-boxing and its vice versa is called unboxing. Wrapper classes are also the sub-classes of abstract classes. More memory can be held in the case of wrapper class than primitive data types.

Ques 5: What do you understand by type casting in Java?

Answer: This is one of the best Core java interview questions when one data type is assigned a value of another data type, it makes the two data types non-compatible with each other which calls for conversion. Hence we perform type casting for the conversion of these data types.

Ques 6: What is break statement in Java?

Answer: when we have a flow sequence in Java, the keyword is needed to break that flow sequence. When we want to come out of a statement after executing the case, the break comes into play. A break statement is also used to come out of the loop.

Ques 7: What are the 4 principles of OOPs in Java?

Answer 7: The four principles of Oops in java are:

  • Inheritance: It is the key feature of OOP programming. This process allows one class to inherit another class including its objects and methods.
  • Polymorphism: Polymorphism is a process in java by which we can use a method in multiple ways. Or we make the method take different forms. The parent class is used as a reference for the child class. This process is performed either by overloading in java or overriding in java.
  • Abstraction: It is the property by which only useful details are shown to the user. The non-useful parts are made hidden from the user. This process identifies the things that are required.
  • Encapsulation: It wraps all the data under a single unit by binding the whole code together. It is said to be protective for the data from any outer threat by declaring all the variables as private but methods remain public in the class.

For Better understanding read Oops Concepts in Java

Ques 8: what is method overloading and method overriding in Java?

Answer: when a method of child class overrides the method of the parent class, we call this processing method overriding in java. For overriding to happen, the signature method of both parent and child class should match with each other.

However, method overloading is a feature in Java that allows a class to have more than one method which has the same name, even if their arguments vary. It is also done within the same class with different parameters. Overloading is sometimes also referred to as compile-time polymorphism.

Ques 9: Can we overload main() in Java?

Answer: yes, it is possible to overload main() in Java.

Ques 10: what do you understand by abstract class in Java?

Answer: A class whose object cannot be created but we can extend that class, such type of classes are termed as abstract classes. It has generalized forms which are shared by all the child class.

Top Java Interview Questions

Ques 11: What are transient variables?

Answer: Transient variables are those which are not included in the process of serialization in java, not they are a part of the serialized state of the object.

Ques 12: What are constructors? Also explain the type of constructors?

Answer: we use constructors to create the instance of a class. They are also invoked when a class is invoked. We should never keep the class and constructor names the same. We cannot inherit the constructors. 2 types of constructors which are:

  • Default constructor: The constructors which do not have any argument statements are called default constructors.
  • Parameterized constructor: The constructors which take argument statements are called the Parameterised constructor.

Ques 13: Explain β€˜this’ keyword in Java?

Answer: When we initialize an object in the class, this keyword helps to refer to that particular object of the class whose method is being called by the coder.
For Detail This keyword in java

The properties are:

  • we use this keyword is used to get the current object in the program P.
  • This keyword is used to invoke the current method of the object.
  • This keyword is used to return the current object from the method.
  • This() can be invoked in current class constructor C.
  • This keyword can also be passed as a parameter to the constructor C.

Ques 14: Explain β€˜super’ keyword in Java?

Answer: Super keyword in java is a type of reference variable. we use it to refer to the parent class in java. we also call it as superclass and it can also be used to call the methods or constructors of the parent class.

We have various ways of using super keyword:

  • Using it with variables: This situation occurs when the parent and child class have the same data members. We use the super keyword to remove the JVM ambiguity.
  • Using it with data members: we use super when we want to call the method of the parent class. As parent and child class will have the same data members, super will remove the ambiguity in that case.
  • Using it with constructors: super keyword can access both the parametric as well as non- parametric constructors of the parent class.

Ques 15: What is an object class in Java?

Answer: It is a special class in java, and all the other classes are subclasses of this object class. It has 3 main methods: objectClone(), finalize() and toString().
Read Post Java Object Class

Ques 16: What is garbage collection in Java?

Answer: The process by which Java performs automatic memory management is called garbage collection in Java. As long as the object is present on java virtual machine, it is considered to be alive. Once it is no longer found in the application code, it is removed by the JVM and the memory space is made free. As a result, it is claimed to be an unused memory. The whole process is done during the run time of the code. JVM does this by converting the byte code into machine language.

Ques 17: What is exception handling in Java? what are the various types of exceptions? Explain

Answer: Exception handling is a process that aims at handling the worse state in a program to avoid a system crash. An exception is a state while running the program that happens when an unexpected point occurs which requires special processing. It gracefully handles the situation by showing an error message saving the crash and program breakage.

There are 2 types of exceptions:

  • Checked exception: these exceptions throw a compile-time error if not properly handled by the programmer. These exceptions occur at compile time
  • Unchecked exceptions: These exceptions occur at run time and the programmer needs to handle them at the time of compilation.

Ques 18: what is the minor difference between an error and an exception?

Answer: An error is mostly a hardware or system issue that generally occurs at run time. We can solve it in order to proceed. Whereas an exception in some issues with the input data or if the program logic is not correct.

Ques 19: Elaborate the concept of β€˜throw’, β€˜throws’ and β€˜finally’ block?

Answer: Throw in java works similar to try-catch block and it is basically used to declare an exception. Throws are assumed to be an instance of the Exception class.

Finally is a block in java which always executes, whether there is an exception or not. Finally block comes after the try-catch block. We cannot have a block without finally block.

Ques 20: Define Java-bean?

Answer: Java bean is a reusable software class in Java which follows some conventions such as name conventions.

Ques 21: What do you understand by collections in Java?

Answer: Collection is a pack of objects in java that comes under java.util package. Along with this, the package has all the date and time facility, legacy classes etc. Or it is also termed as a framework used to store objects. The functions that we can be performed in the collection are Manipulation, insertion, deletion, searching, sorting etc

Leave a comment

Your email address will not be published.