What are the Interview Questions for java ?
1. What are the differences between C++ and Java?
Answer:
- Languages Compatibility.
C++ is a programming language that is based on the C programming language. Most other high-level languages are compatible with C++.
Most of the languages of Java are incompatible. Java is comparable to those of C and C++.
- Interaction with the library.
It can access the native system libraries directly in C++. As a result, it’s better for programming at the system level.
Java’s native libraries do not provide direct call support. You can use Java Native Interface or access the libraries.
- Characteristics.
C++ distinguishes itself by having features that are similar to procedural and object-oriented languages. The characteristic that sets Java apart is automatic garbage collection. Java doesn’t support destructors at the moment.
- The semantics of the type.
Primitive and object types in C++ have the same kind of semantics. The primitive and object classes of Java, on the other hand, are not consistent.
- In the context of Compiler and Interpreter.
Java refers to a compiled and interpreted language. In contrast, C++ is only a compiled language.
In Java, the source code is the compiled output is a platform-independent byte code.
In C++, the source program is compiled into an object code that is further executed to produce an output.
2. List the features of the Java Programming language?
Answer:
A few of the significant features of Java Programming Language are:
Easy: Java is a language that is considered easy to learn. One fundamental concept of OOP Java has a catch to understand.
Secured Feature: Java has a secured feature that helps develop a virus-free and tamper-free system for the users.
OOP: OOP stands for Object-Oriented Programming language. OOP signifies that, in Java, everything is considered an object.
Independent Platform: Java is not compiled into a platform-specific machine; instead, it is compiled into platform-independent bytecode. This code is interpreted by the Virtual Machine on which the platform runs.
3. What is a ClassLoader?
Answer:
A classloader in Java is a subsystem of Java Virtual Machine, dedicated to loading class files when a program is executed; ClassLoader is the first to load the executable file.
Java has Bootstrap , Extension, and Application classloaders.
4. What are the Memory Allocations available in Java?
Answer:
Java has five significant types of memory allocations.
- Class Memory
- Heap Memory
- Stack Memory
- Program Counter-Memory
- Native Method Stack Memory
5. What are the differences between Heap and Stack Memory in Java?
Answer:
Stack is generally used to store the order of method execution and local variables. In contrast, Heap memory is used to store the objects. After storing, they use dynamic memory allocation and deallocation.
6. Will the program run if we write static public void main?
Answer:
Yes, the program will successfully execute if written so. Because, in Java, there is no specific rule for the order of specifiers
7. What is the default value stored in Local Variables?
Answer:
Neither the Local Variables nor any primitives and Object references have any default value stored in them.
Read Also- Network Troubleshooting Commands
8. What is an Association?
Answer:
An Association can be defined as a relationship that has no ownership over another. For example, a person can be associated with multiple banks, and a bank can be related to various people, but no one can own the other.
9. What do you mean by aggregation?
Answer:
The term aggregation refers to the relationship between two classes best described as a “whole/part” and “has-a” relationship. This kind is the most specialized version of an association relationship. It contains the reference to another class and is said to have ownership of that class.
10. Define Copy Constructor in Java
Answer:
A Copy Constructor in Java is a constructor that initializes an object through another object of the same class.
11. What is a Marker Interface?
Answer:
An empty interface in java is referred to as a Marker interface. Serializable and Cloneable are some famous examples of Marker Interface.
12. What is Object Cloning?
Answer:
An ability to recreate an object entirely similar to an existing object is known as Object Cloning in Java. Java provides a clone() method to clone a current object offering the same functionality as the original object.
13. Why is Java not completely object-oriented?
Answer:
Java is not considered as a 100% object-oriented Programming language because it still makes use of eight or more primitive data types like int, float double, etc.
14. What is an object-oriented paradigm?
Answer:
A Paradigm that is based on the concepts of “Objects.” It contains data and code. Data that is in the form of fields, and regulation, that is in the form of procedures. The exciting feature of this paradigm is that the object’s procedures can access and often modify the data fields themselves.
15. Define Wrapper Classes in Java.
IAnswer:
n Java, when you declare primitive datatypes, then Wrapper classes are responsible for converting them into objects(Reference types).
16. Define Singleton Classes in Java.
Answer:
In Java, when you make the constructor of a class private, that particular class can generate only one object. This type of class is popularly known as a Singleton Class.
17. Define package in Java.
Answer:
The package is a collective bundle of classes and interfaces and the necessary libraries and JAR files. The use of packages helps in code reusability.
18. Can you implement pointers in a Java Program?
Answer:
Java Virtual Machine takes care of memory management implicitly. Java’s primary motto was to keep programming simple. So, accessing memory directly through pointers is not a recommended action. Hence, pointers are eliminated in Java.
19. Differentiate between instance and local variables.
Answer:
for instance, variablesare declared inside a class, and the scope is limited to only a specific object.
A local variable can be anywhere inside a method or a specific block of code. Also, the scope is limited to the code segment where the variable is declared.
20. Explain Java String Pool.
Answer:
A collection of strings in Java’s Heap memory is referred to as Java String Pool. In case you try to create a new string object, JVM first checks for the presence of the object in the pool. If available, the same object reference is shared with the variable, else a new object is created.
21. What is an Exception?
Answer:
An Exception in Java is considered an unexpected event that can disrupt the program’s normal flow. These events can be fixed through the process of Exception Handling.
22. What is the final keyword in Java?
Answer:
The term final is a predefined word in Java that is used while declaring values to variables. When a value is declared using the final keyword, then the variable’s value remains constant throughout the program’s execution.
23. What happens when the main() isn’t declared as static?
Answer:
When the main method is not declared as static, then the program may be compiled correctly but ends up with a severe ambiguity and throws a run time error that reads “NoSuchMethodError.”
Hope you like this blog….
- AnchorSetup using Docker-Compose - October 18, 2024
- Devops assignment - October 17, 2024
- Deployment of vault HA using MySQL - September 18, 2024