In Q&A

1. Define Wrapper Classes in Java.
In Java, when you declare primitive datatypes, then Wrapper classes are responsible for converting them into objects(Reference types).

2. What is a singleton class in Java? And How to implement a singleton class?
A class that can possess only one object at a time is called a singleton class. To implement a singleton class given steps are to be followed:
• Make sure that the class has only one object
• Give global access to that object

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. Can you implement pointers in a Java Program?
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.

5. Differentiate between instance and local variables.
For instance, variables are declared inside a class, and the scope of variables in javascript 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.

6. Explain Java String Pool.
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.

7. What is an Exception?
An Exception handling 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.

8. What is the final keyword in Java?
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.

9. What happens when the main() isn’t declared as static?
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.”

10. Why is Java a platform independent language?
One of the most well-known and widely used programming languages is Java. It is a programming language that is independent of platforms. Java doesn’t demand that the complete programme be rewritten for every possible platform. The Java Virtual Machine and Java Bytecode are used to support platform independence. Any JVM operating system can run this platform-neutral byte code. The application is run after JVM translates the byte code into machine code. Because Java programmes can operate on numerous systems without having to be individually rewritten for each platform, the language is referred to as “Write Once, Run Anywhere” (WORA).

11. Why is the main method static in Java?
Java’s main() function is static by default, allowing the compiler to call it either before or after creating a class object. The main () function is where the compiler begins programme execution in every Java programme. Thus, the main () method needs to be called by the compiler. If the main () method is permitted to be non-static, the JVM must instantiate its class when calling the function.

12. What part of memory – Stack or Heap – is cleaned in the garbage collection process?
On Heap memory, garbage collection is employed to release the memory used by objects with no references. Every object created in the Heap space has access to the entire application and may be referred to from anywhere.
13. What is the difference between the program and the process?
A programme is a non-active entity that includes the collection of codes necessary to carry out a specific operation. When a programme is run, an active instance of the programme called a process is launched. A process is begun by a programme once it has been run. The process carries out the program’s specified instructions.

14. What are the differences between constructor and method of a class in Java?
Initializing the state of the object is done by constructors. A function Object () { [native code] }, like methods, contains a group of statements (or instructions) that are carried out when an object is created. A method is a group of statements that work together to complete a certain task and return the outcome to the caller. A method has the option of working without returning anything.

15. Which among String or String Buffer should be preferred when there are a lot of updates required to be done in the data?
Because StringBuilder is quicker than StringBuffer, it is advised to utilize it wherever possible. However, StringBuffer objects are the best choice if thread safety is required.

Recent Posts
Learn Devops

Become a Devops Engineer in 3 months