java2m
java2m
1.Functions of JVM:
• The JVM (Java Virtual Machine) loads, verifies, and executes Java bytecode.
• It provides platform independence and manages memory using the garbage
collector.
2.Object and Class in Java:
• A class is a blueprint for creating objects.
• An object is an instance of a class with state and behavior.
3.Anonymous Object:
• An anonymous object is created without a reference and used immediately (e.g.,
new ClassName().method();).
4.Equals() vs == in Java:
• equals() compares object content, while == checks if two references point to
the same object.
5.Java Program to Check Perfect Square:
int num = 16; int sqrt = (int) Math.sqrt(num); if (sqrt * sqrt == num)
System.out.println("Perfect Square"); else System.out.println("Not a Perfect
Square");
6.Features of Java Programming:
• Java is platform-independent, secure, object-oriented, robust, and supports
multithreading.
7.Instance Variable in Java:
• Instance variables belong to an object and are declared inside a class but
outside methods.
8.Ways to Initialize an Object in Java:
• Using a constructor, by assigning values directly, or through setter methods.
9.Constructors vs Java Methods:
• Constructors initialize objects and have no return type, while methods perform
tasks and can return values.
10.Program for Static Method:
class Demo { static void display() { System.out.println("Static Method
Example"); } public static void main(String[] args) { Demo.display(); } }
2nd unit
1.Types of Inheritance in Java:
• Single, multilevel, hierarchical, and hybrid inheritance (through interfaces).
• Java doesn’t support multiple inheritance with classes to avoid ambiguity.
2.Usage of Inheritance:
• Inheritance allows a class to reuse properties and methods of another class.
• It promotes code reusability and hierarchical relationships.
3.Function and Method Overloading:
• Function overloading occurs when multiple methods have the same name but
different parameters.
• It improves code readability and allows flexibility in method calls.
4.Protected Class in Java:
• Protected access allows members to be accessed within the same package or by
subclasses.
• It provides controlled visibility for inheritance.
5.Java Access Modifiers:
• Public: Accessible everywhere.
• Private: Accessible only within the class.
• Protected: Accessible in the package and subclasses.
• Default: Accessible within the package.
6.Interface in Java:
• An interface is a blueprint of a class containing abstract methods and
constants.
• It is used to achieve abstraction and multiple inheritance.
7.Final Variable:
• A final variable is a constant and cannot be modified once initialized.
• It is used to define immutable values like PI.
8.Final Methods and Classes:
• A final method cannot be overridden in subclasses.
• A final class cannot be inherited by any other class.
9.Accessing a Package from Another Package:
• Use the import keyword to include the package (e.g., import
packageName.ClassName;).
• This makes the package accessible in your program.
10.Difference Between Interface and Class:
• An interface contains only abstract methods and constants, while a class has
fields, constructors, and concrete methods.
• Interfaces are used for abstraction and implementing multiple inheritance.
3rd unit
1.Java Built-in Exceptions:
• NullPointerException: Occurs when trying to use a null reference.
• ArrayIndexOutOfBoundsException: Happens when accessing an invalid array index.
2.Difference Between Multi-threading and Multi-tasking:
• Multi-threading runs multiple threads in one process.
• Multi-tasking runs multiple processes at the same time.
3.Use of Exception in Java:
• Exceptions handle errors without crashing the program.
• They allow you to handle problems in a controlled way.
4.Reason for an Exception:
• Exceptions occur due to unexpected events like invalid input or resource
issues.
• They happen when something goes wrong during program execution.
5.Exception Handling in Java:
• Exception handling in Java uses try, catch, and finally blocks.
• It helps manage errors and allows the program to continue running smoothly.
6.Advantages of Using Exception Handling in Java:
• Makes code easier to read and manage.
• Allows the program to recover from errors instead of crashing.
7. Advantages of Multithreading:
• Multithreading makes programs run faster by doing multiple tasks at once.
• It improves performance, especially on multi-core systems.
8.Use of Multithreading:
• Used for tasks like downloading files or handling user input simultaneously.
• It is helpful for making programs responsive and efficient.
9.Difference Between Process and Thread:
• A process is a program with its own memory.
• A thread is a part of a process that shares memory with other threads.
10.Purpose of the wait() Method in Java:
• The wait() method pauses the current thread until another thread signals it to
continue.
• It helps manage synchronization between threads.
4th unit
1. **Classify the Purpose of Event Object**
The Event Object encapsulates information about an event, providing details
such as the event type and the source component that generated it.
2. **Discover an Action Event**
An Action Event occurs when a user triggers an action, like pressing a button
or selecting a menu item, which is then handled by ActionListeners.
3. **Distinguish the relationship between an EventListener interface and Event
Adapter class**
The EventListener interface defines methods to handle events, while an Event
Adapter class provides default implementations of these methods, simplifying
event handling by allowing only required methods to be overridden.
4. **Discover the three main components of Event handling**
The main components of event handling are the Event Source, Event Object, and
Event Listener, which work together to detect and respond to user actions.
5. **List the difference between Event handler and Event Listener**
An Event Handler processes the event once it’s received, while an Event
Listener monitors and detects events, waiting to trigger an action when an event
occurs.
6. **Analyze Event in delegation model used in Java**
In Java's delegation model, an event source delegates event handling to
listeners registered to it, promoting loose coupling by separating event
detection from event handling.
7. **Examine about MouseMotionListener**
MouseMotionListener detects mouse movements and drag actions, triggering
specific methods like `mouseMoved` and `mouseDragged` when these events occur.
8. **Discover the methods which are used to register KeyListener**
Methods such as `addKeyListener` are used to register KeyListeners to
components, allowing them to respond to keyboard events like key presses and
releases.
9. **Examine the event which will be notified if Scrollbar is manipulated**
The AdjustmentEvent is notified when the Scrollbar is manipulated, indicating
changes in the scrollbar’s position.
10. **Inspect the events which will be generated if we close an applet’s
window**
When an applet’s window is closed, a WindowEvent is generated, specifically
the `windowClosing` event in the WindowListener interface.
5th unit
1. **Assess the term Java Networking**
Java Networking refers to the concept of connecting multiple devices or
applications over a network, enabling them to share data using classes and
protocols provided by Java.
2. **Justify the difference between local Applet and Remote Applet**
A local applet is stored on the local system and executed from there, while a
remote applet is loaded over a network, typically from a web server.
3. **Assess the types of Applets**
Applets are primarily categorized into two types: Standalone Applets, which
can run independently, and Web Applets, which are embedded in a web page and
require a browser.
4. **Assess the term socket**
A socket is an endpoint for communication between two devices over a network,
allowing data exchange through a connection.
5. **Justify that we need Socket Programming**
Socket programming is essential for enabling real-time, bidirectional
communication between networked applications, useful in chat applications, file
sharing, and more.
6. **Prioritize the use of Applet**
Applets are primarily used for creating dynamic and interactive web content,
like animations and forms, embedded in web pages and run by browsers.
7. **Conclude the advantages of Applet**
Applets are platform-independent, secure, and can run directly in web
browsers, making them suitable for lightweight web applications.
8. **Determine the applet methods**
Key applet methods include `init`, `start`, `stop`, and `destroy`, which
control the applet's lifecycle and behavior within a browser.
9. **Evaluate the term Protocol**
A protocol is a set of rules that governs data communication over a network,
ensuring proper formatting, transmission, and error handling.
10. **Assess about TCP/IP**
TCP/IP (Transmission Control Protocol/Internet Protocol) is a suite of
communication protocols that form the foundation of the internet, enabling
reliable data transmission across networks.