0% found this document useful (0 votes)
12 views3 pages

Short Questions

Uploaded by

nilgohil2005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views3 pages

Short Questions

Uploaded by

nilgohil2005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Short Questions

1. Explain final, finally, and finalize in detail:


 final: In Java, final is a keyword that can be applied to classes, methods, and
variables. When applied to a class, it indicates that the class cannot be
subclassed. When applied to a method, it indicates that the method cannot be
overridden by subclasses. When applied to a variable, it indicates that the
variable's value cannot be changed once initialized.
 finally: finally is a block associated with a try-catch block in Java. It is
guaranteed to be executed whether an exception is thrown or not. It is often used
for cleanup operations, such as closing resources like files or database
connections.
 finalize(): finalize() is a method provided by the Object class in Java. It is
called by the garbage collector before reclaiming an object's memory. However,
its use is discouraged because it is not guaranteed to be called promptly or at all,
and it can interfere with the garbage collector's performance.
2. What is bytecode:
 Bytecode is a compiled code generated by the Java compiler after compiling Java
source code (.java files). It is a platform-independent intermediate code that is
executed by the Java Virtual Machine (JVM). Java source code is compiled into
bytecode, which can then be executed on any system with a compatible JVM,
making Java a platform-independent language.
3. What is finalize() in Java:
 finalize() is a method provided by the Object class in Java. It is called by the
garbage collector before reclaiming an object's memory. Its purpose is to
perform cleanup operations or release resources held by the object before it is
garbage collected. However, its use is discouraged because it is not guaranteed
to be called promptly or at all, and it can interfere with the garbage collector's
performance.
4. Describe the use of finally:
 The finally block is used in Java to execute important code such as releasing
resources (e.g., closing files, database connections) regardless of whether an
exception is thrown or not. It is associated with a try-catch block, and it is
guaranteed to be executed even if an exception occurs in the try block. This
ensures that critical cleanup operations are performed regardless of the
program's flow.
5. Write the difference between == and equals():
 == is an operator used for reference comparison in Java. It checks if two object
references point to the same memory location.
 equals() is a method defined in the Object class in Java. It is used for content
comparison and checks if two objects are equal based on their content.
6. How do we compare two objects in Java:
 In Java, you can compare objects using the equals() method, which compares
the content of objects for equality. Alternatively, you can use the == operator to
compare object references for reference equality.
7. What is the difference between public and default (package) modifier:
 public: Classes, methods, and variables with the public modifier are accessible
from any other class.
 Default (package-private): Classes, methods, and variables without any access
modifier (i.e., not declared as public, private, or protected) are accessible only
within the same package.
8. Define the term Link List:
 A linked list is a linear data structure consisting of a sequence of elements, called
nodes, where each node contains a data value and a reference (link) to the next
node in the sequence. Unlike arrays, linked lists do not store elements in
contiguous memory locations.
9. Define abstract in Java:
 abstract is a keyword in Java used to define abstract classes and methods. An
abstract class cannot be instantiated on its own and may contain abstract
methods, which are declared without any implementation. Subclasses of an
abstract class must provide implementations for all abstract methods or be
declared abstract themselves.
10. Define Interface in Java:
 An interface in Java is a reference type that defines a contract for classes to
implement. It contains only method signatures (without implementation) and
constants. Classes implement interfaces using the implements keyword, and a
class can implement multiple interfaces.
11. What do you mean by checked and unchecked exception:
 Checked exceptions are exceptions that are checked at compile time by the
compiler. They must be either caught using a try-catch block or declared using
the throws keyword in the method signature.
 Unchecked exceptions, also known as runtime exceptions, are exceptions that are
not checked at compile time. They usually occur due to programming errors or
logical errors and do not need to be caught or declared.
12. What is mutex:
 Mutex (short for mutual exclusion) is a synchronization mechanism used to
control access to shared resources by multiple threads. It ensures that only one
thread can access the shared resource at a time, preventing concurrent access
and potential data corruption or race conditions.
13. Define Monitor:
 In concurrent programming, a monitor is a synchronization construct used to
control access to shared resources by multiple threads. It consists of a lock and
condition variables that allow threads to wait for certain conditions to be met
before proceeding.
14. Write the difference between init() and start():
 init() is a method provided by the Servlet interface in Java servlets. It is called
by the servlet container to initialize the servlet instance before servicing any client
requests.
 start() is a method provided by the Thread class in Java for starting a new
thread of execution. It invokes the run() method of the thread, causing it to
begin execution.
15. What do you mean by garbage collector:
 The garbage collector is a component of the Java Virtual Machine (JVM)
responsible for automatically reclaiming memory occupied by objects that are no
longer in use (i.e., unreachable). It identifies and frees up memory occupied by
unreachable objects, allowing it to be reused by the program. Garbage collection
helps manage memory efficiently and eliminates memory leaks in Java programs.

You might also like