💡 Why Was Java Created?
Java was created to solve real-world software problems that existing
languages (like C and C++) couldn’t address well at the time.
🧑💻 Origin Story:
• In 1991, James Gosling, Mike Sheridan, and Patrick
Naughton from Sun Microsystems started a project called “Green
Project.”
• The goal: to build software for intelligent home appliances
(like TVs, microwaves, remote controllers) that could run on di erent
devices without rewriting code.
Quick Recap for Your Viva:
• What is Java? A platform-independent, object-oriented
programming language used for developing various applications.
• Who Invented Java? James Gosling, Mike Sheridan, and
Patrick Naughton at Sun Microsystems in 1991.
• Founder of Java? James Gosling (known as the father of
Java).
• What Does the Java Logo Mean? The steaming co ee cup
symbolizes energy, modernity, and adaptability, drawing inspiration
from Java co ee beans.
Java Features:
• Simple, Object-Oriented, Platform-Independent, Secure,
Robust, Multithreaded, Distributed, High Performance, Dynamic,
Portable, Interpreted & Compiled, and Scalable.
Recap for Viva:
• Portable: Java programs can run on any platform with a
JVM, without modi cation.
• Platform-Independent: Java code runs on any platform
without needing to be rewritten, thanks to the JVM.
ff
fi
ff
ff
• Object-Oriented: Java follows the OOP paradigm, focusing
on objects, classes, and key concepts like inheritance, polymorphism,
encapsulation, and abstraction.
program related questions :
1. MouseMotionListener Applet
Q1. What is an Applet?
An applet is a small Java program that runs in a web browser or applet viewer. It uses Applet
class from java.applet and is used to create dynamic UI in the browser.
Q2. What is MouseMotionListener?
It is an interface in Java that listens for mouse movement events, like mouseMoved() and
mouseDragged().
Q3. What are the two methods of MouseMotionListener?
• mouseMoved(MouseEvent e)
• mouseDragged(MouseEvent e)
Q4. Why call repaint() in mouseMoved()?
repaint() is used to refresh the applet screen and call the paint() method, updating the graphics
with new mouse coordinates.
Q5. Use of getX() and getY()?
These return the current x and y coordinates of the mouse pointer.
Q6. Can we override init() and paint()?
Yes. init() is used to initialize the applet; paint() is used to draw graphics.
Q7. Purpose of drawString(s,x,y)?
It prints the coordinate string at the current position of the mouse.
🛢 2. JDBC Database Connectivity
Q1. What is JDBC?
JDBC (Java Database Connectivity) is an API to connect and execute queries on a database
using Java.
Q2. Purpose of DriverManager.getConnection()?
It establishes a connection to the database using the provided URL, username, and password.
Q3. Syntax of CREATE TABLE IF NOT EXISTS?
It creates a new table only if it does not already exist, preventing duplicate tables.
Q4. What is a Statement object?
It allows you to send SQL queries to the database.
Q5. How to execute SQL queries in Java?
Using executeUpdate() for insert/update/create and executeQuery() for select.
Q6. Why close the statement and connection?
To free up resources and prevent memory leaks or connection over ow.
Q7. What is the JDBC driver for MySQL?
com.mysql.cj.jdbc.Driver is the latest MySQL driver.
Q8. How are exceptions handled?
With try-catch blocks. Any database errors are caught in the catch(Exception e) block.
🧵 3. Multithreading Program
Q1. What is multithreading?
Multithreading allows multiple tasks (threads) to run concurrently, improving performance.
Q2. Di erence: run() vs start()?
• start() starts a new thread, calling run() internally.
• run() just executes in the current thread, not concurrently.
Q3. How many threads are running here?
Three threads (a, b, c), but because run() is used instead of start(), they run sequentially.
Q4. Why extend Thread class?
To create custom threads by overriding the run() method.
Q5. What is thread lifecycle?
States: New, Runnable, Running, Blocked, Terminated.
Q6. Why no concurrent output?
Because .run() is used directly. To run concurrently, use .start() instead.
⸻
ff
fl
✅ 4. AWT Checkbox Applet
Q1. What is AWT?
AWT (Abstract Window Toolkit) is Java’s GUI library for creating windows, buttons, checkboxes,
etc.
Q2. Why use CheckboxGroup?
To make checkboxes behave like radio buttons (only one selection at a time).
Q3. What is the di erence between grouped and ungrouped checkboxes?
• Grouped (CheckboxGroup): Only one can be selected.
• Ungrouped: Multiple selections allowed.
Q4. Purpose of Labels?
Used to display static text on the applet window.
Q5. Can AWT applets have layouts?
Yes, default is FlowLayout, but you can set others like BorderLayout, GridLayout.
🔁 General Viva Questions (BONUS)
Q1. Applet Lifecycle?
• init(): Initialization
• start(): Called after init or when applet is restarted
• paint(Graphics g): To draw content
• stop(): Called when applet is stopped
• destroy(): Cleanup before applet is destroyed
Q2. Di erence between Application & Applet?
• Application runs with main() method.
• Applet runs in a browser/applet viewer using lifecycle methods.
Q3. What are Layout Managers?
Classes that control the layout of components in a container. Example: FlowLayout, GridLayout.
Q4. What is Exception Handling?
Mechanism to handle runtime errors using try, catch, nally.
ff
ff
fi
Public Static void main(String ar[]);
public
• It’s an access modi er.
• It means this method is accessible from anywhere, including outside the class.
• Since the JVM (Java Virtual Machine) needs to access this method from outside the
class, it must be public.
🔹 static
• It means the method belongs to the class, not to any speci c object.
• This allows the JVM to run the method without creating an object of the class.
• Without static, the JVM would need to create an object, which is not possible
because the program hasn’t started yet.
🔹 void
• This means the method does not return any value.
• The main() method is used to run the program, not to return a result to the JVM.
🔹 main
• This is the name of the method.
• It is prede ned in Java — the JVM looks for this method when starting the
program.
• It must be exactly spelled as main, otherwise your program won’t run.
fi
fi
fi