UNIT-1
Overview and Characteristics of Java
- Java – A high-level, object-oriented, platform-independent programming language developed by Sun Microsystems.
- Platform Independent – Java programs can run on any system with a Java Virtual Machine without modification.
- Object-Oriented – Java is based on objects and classes, promoting modular and reusable code.
- Simple – Java removes complex features like pointers and multiple inheritance to make programming easier.
- Secure – Java provides a secure execution environment using bytecode verification and runtime checks.
- Robust – Java emphasizes strong memory management, exception handling, and type checking.
- Multithreaded – Java supports concurrent execution of multiple threads within a single program.
- Portable – Java bytecode can be transferred and executed across different platforms.
Java Program Compilation and Execution Process
- Source Code – The human-readable Java program written using
.javaextension. - Java Compiler (javac) – A tool that converts Java source code into bytecode.
- Bytecode – An intermediate, platform-independent code generated by the Java compiler.
- Class File – The
.classfile containing bytecode that is executed by the JVM. - Java Interpreter – A component of the JVM that reads and executes bytecode instructions.
- Just-In-Time (JIT) Compiler – A JVM component that improves performance by compiling bytecode into native machine code at runtime.
- Execution Phase – The stage where the JVM loads, verifies, and executes the bytecode.
Organization of the Java Virtual Machine
- Java Virtual Machine (JVM) – A virtual machine that enables Java programs to run on any platform.
- Class Loader Subsystem – Loads class files into memory and prepares them for execution.
- Method Area – Stores class-level data such as class structures, methods, and static variables.
- Heap Memory – Runtime memory area used to store objects and instance variables.
- Stack Memory – Stores method calls, local variables, and execution states for each thread.
- Program Counter Register – Keeps track of the current instruction being executed.
- Native Method Stack – Stores information for native methods written in languages like C or C++.
- Execution Engine – Executes bytecode using interpretation and JIT compilation.
- Garbage Collector – Automatically frees unused memory by removing unreachable objects.
JVM as an Interpreter and Emulator
- Interpreter – A JVM component that executes bytecode instructions one by one at runtime.
- Emulator – The JVM simulates a virtual processor to run Java bytecode on different hardware platforms.
Instruction Set
- JVM Instruction Set – A predefined set of bytecode instructions that the JVM understands and executes.
- Opcode – A numeric value that specifies the operation to be performed by the JVM.
- Operand – Data values on which JVM instructions operate.
Class File Format
- Class File – A binary file containing Java bytecode and metadata generated by the Java compiler.
- Magic Number – A fixed value at the beginning of a class file used to identify it as a valid Java class.
- Constant Pool – A table in the class file storing constants, method references, and field references.
- Access Flags – Indicators defining the visibility and properties of classes, methods, and fields.
- Method Table – A structure in the class file containing bytecode and information for each method.
Verification
- Bytecode Verifier – A JVM component that checks bytecode for illegal operations and security violations.
- Type Checking – Verification that ensures correct data types are used in operations.
- Stack Integrity Check – Verification process ensuring proper use of the operand stack.
Class Area
- Class Area – Memory region that stores class definitions, static variables, and method metadata.
Java Stack
- Java Stack – Memory area that stores stack frames for method execution in each thread.
- Stack Frame – A data structure containing local variables, operand stack, and method return information.
Heap
- Heap – Runtime memory area where all Java objects and instance variables are stored.
Garbage Collection
- Garbage Collection – Automatic process of reclaiming memory occupied by unreachable objects.
- Garbage Collector – JVM component responsible for identifying and freeing unused objects.
Security Promises of the JVM
- Security Promises – Guarantees provided by the JVM to ensure safe execution of Java programs.
- Memory Safety – Prevention of illegal memory access through controlled object references.
Security Architecture and Security Policy
- Security Architecture – Framework of mechanisms used by the JVM to enforce security rules.
- Security Policy – A set of rules defining permissions granted to Java code.
- Permission – An authorization that allows or denies access to system resources.
Class Loaders and Security Aspects
- Class Loader – A JVM component responsible for loading class files into memory.
- Bootstrap Class Loader – Loads core Java classes required by the JVM.
- Extension Class Loader – Loads classes from the Java extensions directory.
- Application Class Loader – Loads classes from the application classpath.
- Class Loader Hierarchy – Parent-child delegation model used for secure class loading.
Sandbox Model
- Sandbox Model – A security mechanism that restricts untrusted Java code to a controlled execution environment.
- Trusted Code – Code granted full access to system resources by the JVM.
- Untrusted Code – Code executed with restricted permissions to prevent security risks.
UNIT-2
- Java Fundamentals – Java is an object-oriented, platform-independent programming language that runs using the Java Virtual Machine (JVM).
- Data Types & Literals – Data types define the type of data a variable can store, such as int, float, char, or boolean. There are 8 primitive data types in java (boolean, byte, char, short, int, long, float, double).
- Variables – Variables are named memory locations used to store data values during program execution.
- Wrapper Classes – Wrapper classes convert primitive data types into objects to allow their use in collections and frameworks, ex.(Float, Double, Integer......etc.)
- Arrays – Arrays are fixed-size collections of elements of the same data type stored in contiguous memory locations.
- Arithmetic Operators – Arithmetic operators perform basic mathematical operations like addition, subtraction, multiplication, and division.
- Logical Operators – Logical operators combine multiple conditions and return boolean results.
- Control of Flow – Control flow statements determine the order in which program statements are executed.
- Loops – Loops repeatedly execute a block of code while a specified condition is true.
- Classes and Instances – A class is a blueprint for objects, and an instance is an object created from that class.
- Class Member Modifiers – Class member modifiers control access, visibility, and behavior of variables and methods.
- Anonymous Inner Class – An anonymous inner class is a nameless class used for one-time implementation of interfaces or abstract classes.
- Interfaces and Abstract Classes – Interfaces provide full abstraction while abstract classes provide partial abstraction.
- Inheritance – Inheritance allows one class to acquire properties and methods of another class.
- Exception Handling – Exception handling manages runtime errors to prevent abnormal program termination.
- throw and throws Clauses – The throw keyword explicitly throws an exception, while throws declares exceptions in a method signature.
- User Defined Exceptions – User defined exceptions are custom exceptions created by extending the Exception class.
- StringBuffer Class – StringBuffer is a mutable and thread-safe class used to modify strings.
- Tokenizer – StringTokenizer breaks a string into smaller parts called tokens using delimiters.
- Applets – Applets are Java programs that run inside a web browser.
- Life Cycle of Applet – The applet life cycle includes initialization, execution, display, stopping, and destruction stages.
- Security Concerns in Applets – Applet security restricts access to system resources using a sandbox environment.
UNIT-3
Thread: A thread is a lightweight unit of execution within a Java program that allows multiple tasks to run concurrently.
Creating Threads: Threads can be created in Java by:
-
Extending the
Threadclass -
Implementing the
Runnableinterface
- Extending Thread Class: A way to create a thread by inheriting from the
Thread class and overriding its run() method. - Runnable Interface: An interface with a single
run() method. A class implementing Runnable can be executed by a thread, allowing better design since the class can extend another class. - Starting Threads: A thread is started using the
start() method, which internally calls the run() method and begins concurrent execution. - Thread Priority: Thread priority determines the order in which threads are scheduled for execution. Priorities range from
MIN_PRIORITY (1) to MAX_PRIORITY (10). - Blocked States: A thread enters a blocked state when it is waiting to acquire a lock, waiting for I/O, or waiting for another thread to perform an action.
- Thread Synchronization: A mechanism used to control access to shared resources so that only one thread can access the resource at a time, preventing data inconsistency.
- Synchronize Threads: Synchronization is achieved using the
synchronized keyword to ensure mutual exclusion when accessing shared data. - Synchronized Code Block: A block of code declared with
synchronized that locks a specific object, allowing finer control than synchronizing entire methods. - Overriding Synchronized Methods: When a synchronized method is overridden, the synchronization behavior depends on whether the overridden method is also declared
synchronized. - Thread Communication: A technique that allows threads to communicate with each other to coordinate execution, typically using
wait(), notify(), and notifyAll(). - wait(): Causes the current thread to release the lock and enter a waiting state until another thread invokes
notify() or notifyAll(). - notify(): Wakes up a single thread that is waiting on the object's monitor.
- notifyAll(): Wakes up all threads that are waiting on the object's monitor.
- AWT Components: Graphical elements like buttons, labels, text fields, and checkboxes used to build Java GUI applications.
- Component Class: The superclass of all AWT components. It provides basic properties like size, position, and visibility.
- Container Class: A component that can hold other components, such as
Frame, Panel, and Dialog. - Layout Manager Interface: An interface that defines how components are arranged within a container.
- Default Layouts: Each container has a default layout manager:
Thread class and overriding its run() method.run() method. A class implementing Runnable can be executed by a thread, allowing better design since the class can extend another class.start() method, which internally calls the run() method and begins concurrent execution.MIN_PRIORITY (1) to MAX_PRIORITY (10).synchronized keyword to ensure mutual exclusion when accessing shared data.synchronized that locks a specific object, allowing finer control than synchronizing entire methods.synchronized.wait(), notify(), and notifyAll().notify() or notifyAll().Frame, Panel, and Dialog.-
Frame→ BorderLayout -
Panel→ FlowLayout -
Applet→ FlowLayout - Insets: Represents the space between the container’s border and its components.
- Dimensions: Represents the width and height of a component.
- BorderLayout: Divides the container into five regions: North, South, East, West, and Center.
- FlowLayout: Arranges components in a left-to-right flow, wrapping to the next line when needed.
- GridLayout: Arranges components in a grid of rows and columns where all cells are of equal size.
- CardLayout: Allows multiple components to share the same display space, showing one “card” at a time.
- GridBagLayout: A flexible and complex layout manager that allows components of varying sizes and positions in a grid.
- AWT Events: Events represent user actions such as clicking a button, pressing a key, or moving the mouse.
- Event Models: Java uses the Delegation Event Model, where events are delegated to registered listeners.
- Listeners: Interfaces that receive and handle events generated by components.
- Class Listener: A class that implements a listener interface to handle specific types of events.
- Adapters: Abstract classes that provide empty implementations of listener interfaces, allowing programmers to override only required methods.
- Action Event: Generated when an action occurs, such as clicking a button or selecting a menu item.
- Action Event Methods:
actionPerformed(ActionEvent e)— handles action events. - Focus Event: Occurs when a component gains or loses keyboard focus.
- Key Event: Generated when a key is pressed, released, or typed on the keyboard.
- Mouse Events: Occur when mouse actions such as clicking, pressing, releasing, or moving are performed.
- Window Event : Generated when window-related actions occur, such as opening, closing, minimizing, or activating a window.
UNIT-4
No comments:
Post a Comment