FRESHERS INTERVIEW Q&A – Java Part 2

 In Q&A

1. What are the differences between C++ and Java?
C++ is not platform-independent; the principle behind C++ programming is “write once, compile anywhere.”
In contrast, because the byte code generated by the Java compiler is platform-independent, it can run on any machine, Java programs are written once and run everywhere.
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 and 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?
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. Define package in Java.
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.

4. What is a ClassLoader?
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.

5. What are the Memory Allocations available in JavaJava?
Java has five significant types of memory allocations.
Class Memory
Heap Memory
Stack Memory
Program Counter-Memory
Native Method Stack Memory

6. What are the differences between Heap and Stack Memory in Java?
Stack memory in data structures is the amount of memory allocated to each individual programme. It is a fixed memory space. Heap memory, in contrast, is the portion that was not assigned to the Java code but will be available for use by the Java code when it is required, which is generally during the program’s runtime.

7. Will the program run if we write static public void main?
Yes, the program will successfully execute if written so. Because, in Java, there is no specific rule for the order of specifiers.

8. What is the default value stored in Local Variables?
Neither the Local Variables nor any primitives and Object references have any default value stored in them.

9. Explain the expected output of the following code segment?
public class Simplilearn
{
public static void main (String args[])
{
System.out.println(100 + 100 +“Simplilearn”);
System.out.println(“E-Learning Company” + 100 + 100);
}
}
The answers for the two print statements are as follows.
200Simplilearn
E-Learning Company100100

10. What is an Association?
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.

11. What do you mean by aggregation?
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.

12. Define Copy Constructor in Java
A Copy Constructor in Java is a constructor that initializes an object through another object of the same class.

13. What is a Marker Interface?
An empty interface in Java is referred to as a Marker interface. Serializable and Cloneable are some famous examples of Marker Interface.

14. What is Object Cloning?
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.

15. What is an object-oriented paradigm?
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.

Recent Posts
Learn Devops

Become a Devops Engineer in 3 months