UNIT 1: Internet Fundamentals Internet Basics Definition: A global network of interconnected computer networks that uses standard communication protocols (TCP/IP). Key Concepts: Connecting: DSL, Cable, Fiber, Satellite, Mobile (3G/4G/5G). ISP (Internet Service Provider): Company providing internet access. Internet Services: WWW, Email, FTP, Chat, VoIP, Social Media. E-Mail Concepts E-Mail: Electronic Mail for sending digital messages. Components: Sender, Recipient, Subject, Body, Attachments. Secure E-Mail: Encryption (e.g., PGP, S/MIME) for confidentiality; Digital Signatures for authenticity. Protocols: SMTP (Simple Mail Transfer Protocol): For sending emails. POP3 (Post Office Protocol v3): For retrieving emails (downloads to client). IMAP (Internet Message Access Protocol): For accessing and managing emails on server (synchronizes). Voice and Video Conferencing Definition: Real-time communication over the internet using voice and/or video. Technologies: VoIP (Voice over Internet Protocol) for voice, various video codecs. Applications: Zoom, Skype, Google Meet, Microsoft Teams. UNIT 2: Core Java Programming Introduction to Java Platform Independent: "Write Once, Run Anywhere" (WORA) via JVM (Java Virtual Machine). Object-Oriented: Supports classes, objects, inheritance, polymorphism, abstraction, encapsulation. Features: Simple, Secure, Robust, Multithreaded, High Performance. Fundamentals Operators: Arithmetic ($+,-,*,/,%$), Relational ($==, !=, , =$), Logical ($&&, ||, !$), Bitwise, Assignment, Ternary. Data Types: Primitive: byte , short , int , long , float , double , char , boolean . Non-Primitive: Classes, Interfaces, Arrays. Variables: Named memory locations to store data. Arrays: Fixed-size collection of elements of the same data type. int[] numbers = new int[5]; // Declaration & instantiation int[] primes = {2, 3, 5, 7}; // Declaration & initialization Control Statements Conditional: if , if-else , if-else if-else , switch . Looping: for , while , do-while , for-each . Jump: break , continue , return . Methods and Classes Class: Blueprint for creating objects. Object: Instance of a class. Method: A block of code that performs a specific task. Constructors: Special methods for initializing objects, same name as class, no return type. OOP Concepts Inheritance: A class (subclass/child) inherits properties and methods from another class (superclass/parent) using extends . Polymorphism: Objects having multiple forms (Method Overloading/Overriding). Abstraction: Hiding implementation details and showing only functionality (Abstract classes/Interfaces). Encapsulation: Binding data (variables) and methods together into a single unit (class) and restricting direct access to some components. Package: A way to organize related classes and interfaces, providing access control and preventing naming conflicts. Interface: A blueprint of a class, containing abstract methods and static final variables ( implements keyword). Exception Handling Errors: Unrecoverable problems (e.g., OutOfMemoryError ). Exceptions: Events that disrupt normal program flow, can be handled. Checked Exceptions: Must be handled or declared (e.g., IOException ). Unchecked Exceptions (Runtime): Not required to be handled (e.g., NullPointerException , ArrayIndexOutOfBoundsException ). Keywords: try , catch , finally , throw , throws . Exception Handling Flowchart Start Code in try block Exception? No Exception Handle in catch Finally block End No Yes Multithreaded Programming Thread: A lightweight sub-process, smallest unit of execution. Creation: Extending Thread class. Implementing Runnable interface (preferred). Synchronization: To prevent race conditions and ensure data consistency in shared resources ( synchronized keyword). I/O (Input/Output) Streams: Used to perform I/O operations. Byte Streams: For raw binary data (e.g., FileInputStream , FileOutputStream ). Character Streams: For character data (e.g., FileReader , FileWriter , BufferedReader , PrintWriter ). Classes: BufferedReader , BufferedWriter , Scanner . Java Applet Small Java programs embedded in HTML pages, executed in a web browser. ( Largely deprecated due to security concerns and rise of web technologies). Lifecycle methods: init() , start() , paint() , stop() , destroy() . String Handling String class: Immutable sequence of characters. Once created, cannot be changed. StringBuffer / StringBuilder : Mutable sequences of characters. StringBuffer : Thread-safe, synchronized, slower. StringBuilder : Not thread-safe, non-synchronized, faster. Preferred in single-threaded environments. Networking Socket Programming: Foundation for network communication. ServerSocket : Used by servers to listen for and accept client connections. Socket : Used by clients to connect to a server and for client-server communication. URL Handling: URL and URLConnection classes for interacting with web resources. Event Handling Delegation Event Model: Event Source: Component that generates an event (e.g., button click). Event Object: Encapsulates information about the event (e.g., ActionEvent , MouseEvent ). Event Listener: Object that registers to receive and process events (e.g., ActionListener , MouseListener ). AWT (Abstract Window Toolkit) Introduction: Java's original platform-dependent GUI toolkit. Uses native peer components. AWT Controls: Button , TextField , Label , Checkbox , Choice , List . Layout Managers: FlowLayout : Components flow from left to right, then wrap. BorderLayout : Arranges components in 5 regions (North, South, East, West, Center). GridLayout : Arranges components in a grid of rows and columns. CardLayout : Manages components as a stack of cards, only one visible at a time. Graphics: Drawing shapes, text, images using Graphics class. Menus: MenuBar , Menu , MenuItem . UNIT 3: Java Swing Introduction to Swing Lightweight GUI Toolkit: Platform-independent, richer set of components than AWT. Components are drawn by Java code, not native OS. Pluggable Look and Feel (PLAF): Allows changing the appearance of GUI components (e.g., Metal, Nimbus, Windows, GTK+). Can be used for both Applets and Standalone Applications. Swing Components (JComponents) Top-level containers: JFrame , JDialog , JApplet . Intermediate containers: JPanel , JScrollPane , JSplitPane , JTabbedPane . Atomic components (controls): JLabel , JTextField , JTextArea , JPasswordField . JButton , JToggleButton , JCheckBox , JRadioButton (use with ButtonGroup ). JList , JComboBox , JTable , JTree . JProgressBar , JSlider , JSpinner . Containers and Panes JScrollPane : Provides scrollability to components like JTextArea , JList , JTable . JMenuBar , JMenu , JMenuItem : For creating application menus. JToolBar : Container for frequently used actions, often with buttons. JLayeredPane : Allows components to be placed in different "depths" or layers, useful for overlapping components. JTabbedPane : Manages a set of components by associating each component with a tab, allowing easy switching. JSplitPane : Divides two components, allowing the user to resize them horizontally or vertically. Layouts Swing uses the same Layout Managers as AWT ( FlowLayout , BorderLayout , GridLayout , CardLayout ) plus additional ones like BoxLayout and GridBagLayout . BoxLayout : Arranges components in a single row or column. GridBagLayout : The most flexible but complex layout manager, aligning components in a grid of cells with varying sizes. Windows and Dialog Boxes JFrame : The main application window, providing title bar, borders, and window controls. JDialog : Secondary pop-up window, often modal (blocks interaction with parent window until closed). JOptionPane : Provides standard pre-built dialogs for messages, input, confirmation, and options. JInternalFrame : A lightweight window that resides within a JFrame , behaving like a desktop within a desktop. UNIT 4: JDBC (Java Database Connectivity) JDBC Connectivity Model (Architecture) Java Application JDBC API JDBC Driver Manager JDBC Driver (Type 4: Thin Driver) Database (e.g., MySQL, PostgreSQL) Definition: An API for connecting to and executing queries against relational databases. Key Components: Application, JDBC API, Driver Manager, JDBC Driver, Database. JDBC/ODBC Bridge (Type 1 Driver) Translates JDBC calls into ODBC calls, then ODBC calls to native database API. Disadvantages: Performance overhead, requires ODBC driver on client, platform-dependent. Usage: Mostly for legacy systems or databases without direct JDBC drivers. Not recommended for new development. java.sql Package Key Interfaces/Classes: DriverManager : Manages JDBC drivers, establishes connections. Connection : Represents an active session with a database. Statement : Used to execute simple, static SQL queries. PreparedStatement : Used for pre-compiled SQL queries with parameters, improves performance, prevents SQL injection. CallableStatement : Used to execute stored procedures in the database. ResultSet : Represents the tabular data returned by a SQL query. Connectivity to Remote Database (Steps) Load the Driver: Class.forName("com.mysql.cj.jdbc.Driver"); Establish Connection: Connection con = DriverManager.getConnection(url, user, password); Create Statement: Statement stmt = con.createStatement(); (or PreparedStatement ). Execute Query: DML (INSERT, UPDATE, DELETE): int rowsAffected = stmt.executeUpdate(sql); DQL (SELECT): ResultSet rs = stmt.executeQuery(sql); Process Results: Iterate through ResultSet using rs.next() and retrieve data (e.g., rs.getString("columnName") ). Close Resources: Always close ResultSet , Statement , and Connection in a finally block to prevent resource leaks. // Example of processing ResultSet ResultSet rs = stmt.executeQuery("SELECT id, name FROM students"); while (rs.next()) { int id = rs.getInt("id"); String name = rs.getString("name"); System.out.println("ID: " + id + ", Name: " + name); } UNIT 5: Java Servlets and RMI Servlet Basics Definition: Java programs that extend the capabilities of a server (typically web servers) to generate dynamic web content. Server-side: Servlets execute on the web server, generating HTML/XML/JSON to be sent to the client browser. Uses javax.servlet and javax.servlet.http packages. Part of the Java EE (Enterprise Edition) platform. Servlet API Basic Servlet interface: Core interface for all servlets, defines lifecycle methods. GenericServlet class: Abstract class implementing Servlet , provides protocol-independent base. HttpServlet class: Abstract class extending GenericServlet , specifically for HTTP requests (overrides service() to call doGet() , doPost() etc.). ServletRequest / HttpServletRequest : Provides client request information (parameters, headers, session data). ServletResponse / HttpServletResponse : Allows sending responses to the client (status codes, headers, content). ServletConfig : Provides servlet initialization parameters defined in web.xml . ServletContext : Provides global information about the web application (context-wide attributes, init params). Life Cycle of a Servlet Loaded init() Initialized service() Ready destroy() Unloaded Client Request Process Request Server Shutdown / Reload Loading: Web container loads servlet class. Instantiation: Servlet object created. Initialization: init(ServletConfig config) called once . Request Handling: service(ServletRequest req, ServletResponse res) called for each request . Destruction: destroy() called once before servlet is removed. Running and Debugging Servlets Requires a web server/container (e.g., Apache Tomcat, Jetty, WildFly). Deployment: Place compiled .class files in WEB-INF/classes or package as a WAR file. Debugging: Attach a remote debugger to the running server process. Thread-safe Servlets Servlets are multithreaded; multiple requests can execute concurrently in the same servlet instance. Issue: Shared instance variables can lead to race conditions and data corruption. Solutions: Avoid instance variables; make variables local to methods. Use synchronized blocks for critical sections accessing shared resources. Use thread-safe objects or collections. ( SingleThreadModel interface is deprecated and not recommended). HTTP Redirects response.sendRedirect("URL"); : Instructs the client browser to make a new request to a different URL. Client sees the new URL in the browser's address bar. Used for navigation, after form submissions (Post/Redirect/Get pattern), or moving resources. Common HTTP status codes: 302 (Found - temporary), 301 (Moved Permanently). Cookies Small pieces of information sent by a web server to a browser, which the browser stores and sends back with subsequent requests to the same server. Used for session management, user tracking, personalization, remembering login state. Cookie class: Create: new Cookie("name", "value") . Set properties: setMaxAge() , setPath() , setDomain() . Add to response: response.addCookie(cookie) . Retrieve from request: request.getCookies() . Introduction to Java Server Pages (JSP) Definition: Technology that allows developers to create dynamic web pages by embedding Java code directly into HTML, XML, or other document types. Transpiled to Servlets: A JSP page is first translated into a Java Servlet, then compiled and executed. Syntax Elements: Directives: <%@ page ... %> , <%@ include ... %> . Scriptlets: <% Java code %> (discouraged in modern JSP). Expressions: <%= Java expression %> (output to page). Declarations: <%! Java variable/method declaration %> . Standard Actions: <jsp:include ... /> , <jsp:forward ... /> . Implicit Objects: Pre-defined objects available in JSPs without explicit declaration (e.g., request , response , session , application , out , pageContext ). Introduction to RMI (Remote Method Invocation) Definition: A mechanism that allows an object running in one JVM (client) to invoke a method on an object running in another JVM (server), potentially on a different machine. Purpose: Enables distributed computing in Java. Components: Remote Interface: Defines methods that can be called remotely (extends java.rmi.Remote ). Remote Object (Server Implementation): Implements the remote interface (extends java.rmi.server.UnicastRemoteObject ). RMI Registry: A naming service where remote objects are registered by name, allowing clients to look them up. Client: Looks up the remote object in the registry and invokes its methods. Stub (Client-side proxy): A proxy that acts as a local representative for the remote object. Handles marshaling arguments and unmarshaling return values. Skeleton (Server-side proxy - deprecated in modern RMI): A server-side object that unmarshals arguments, invokes the actual remote object's method, and marshals the return value. RMI Architecture Client JVM Client Application Stub (Proxy) RMI Runtime Transport Layer Server JVM Remote Object Skeleton (Deprecated) RMI Runtime Transport Layer RMI Registry Lookup Bind