0% found this document useful (0 votes)
55 views19 pages

Java Basics & Features Guide

Uploaded by

omsagaryadav945
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)
55 views19 pages

Java Basics & Features Guide

Uploaded by

omsagaryadav945
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/ 19

JAVA QB

UNIT 1

1. Explain the JAVA with their features and example.


https://www.javatpoint.com/features-of-java

2. Write a short note on JDK (Java Development Kit), Java API


(Application Programming Interface)
JDK - https://www.geeksforgeeks.org/jdk-in-java/
API - https://www.geeksforgeeks.org/what-is-an-api/

3. Write a short note on Java Virtual Machine, Java Program


Structure.
JVM -https://www.geeksforgeeks.org/jvm-works-jvm-architecture
JPS- https://www.w3schools.in/java/program-structure

4. Explain the Java Tokens with example and types.


https://www.geeksforgeeks.org/java-tokens/

5. Explain the class and object with example.


https://www.geeksforgeeks.org/classes-objects-
java/#:~:text=A%20class%20in%20Java%20is,named%20Ravi%20is%
20an%20object

6. Explain the constructors with their types and example.


https://www.geeksforgeeks.org/constructors-in-java/
7. Explain the inheritance with their types and example.
https://www.geeksforgeeks.org/inheritance-in-java/

8. Differentiate between polymorphism overloading and


polymorphism overriding with example.
https://www.geeksforgeeks.org/difference-between-method-
overloading-and-method-overriding-in-java/

9. Explain the packages with their types and example.


https://www.geeksforgeeks.org/packages-in-java/

10. Explain access specifiers with their example.


https://www.geeksforgeeks.org/access-modifiers-java/

11. Explain the exception handling with their types and


example.(IMP)
https://www.javatpoint.com/exception-handling-in-java

12. Differentiate between threads and process with their example.


https://www.geeksforgeeks.org/difference-between-process-and-
thread/

13. Explain the thread life cycle with their architecture(IMP)


https://www.geeksforgeeks.org/lifecycle-and-states-of-a-thread-in-
java/

14. Explain Different methods used in thread life cycle.


ANS : The thread life cycle in Java (and many other programming
languages) includes several states through which a thread can
transition during its execution. Here are the main states and the
methods used to manage a thread's life cycle:
New: A thread is in the new state when it is created but not yet
started.
Method: The thread is instantiated using new Thread() but start() has
not yet been called.
Runnable: When the thread's start() method is invoked, it moves to
the runnable state. The thread is ready to run and is waiting for the
CPU to schedule it.
Method: start()
The thread can transition back to this state from other states such as
waiting or timed waiting.

Running: The thread is in the running state when the CPU actually
executes its code.
Method: The thread's run() method is executed.

Blocked: A thread enters the blocked state when it is waiting for a


monitor lock to enter or re-enter a synchronized block/method.
Methods: Typically caused by entering synchronized blocks or
methods, or waiting for another thread to release a lock.
Waiting: A thread is in the waiting state when it waits indefinitely for
another thread to perform a particular action.
Methods:
Object.wait(): Called on an object, causing the current thread to wait
until another thread calls notify() or notifyAll() on that object.
Thread.join(): Called on a thread, causing the current thread to wait
for the thread on which join was called to terminate.
LockSupport.park(): Causes the current thread to wait until it is
unparked.

Timed Waiting:
A thread is in the timed waiting state when it waits for another
thread to perform a particular action for a specified amount of time.

Methods:
Thread.sleep(long millis): Causes the current thread to sleep for the
specified number of milliseconds.
Object.wait(long timeout): Causes the current thread to wait for the
specified number of milliseconds.
Thread.join(long millis): Causes the current thread to wait for the
thread on which join was called to terminate within the specified
time.
LockSupport.parkNanos(long nanos): Causes the current thread to
wait for the specified number of nanoseconds.
LockSupport.parkUntil(long deadline): Causes the current thread to
wait until the specified deadline.
Terminated: A thread is in the terminated state when it has
completed its execution or has been terminated abnormally.
Method: The thread finishes execution by reaching the end of its
run() method or by throwing an uncaught exception that terminates
the thread.

Unit 2 JAVA

1. Explain the java.util package with their interfaces


https://www.geeksforgeeks.org/java-util-package-java/
https://www.geeksforgeeks.org/interfaces-in-java/

2. Explain the list and set collection with their interfaces and classes
https://www.geeksforgeeks.org/set-in-java/
https://www.geeksforgeeks.org/list-interface-java-examples/
https://www.geeksforgeeks.org/collections-class-in-java/?ref=lbp

3. Explain the JFC (Java Foundation Classes) with their features


https://www.javatpoint.com/jfc-java

4. Explain the different swing API components with their


example(IMP)
ANS ;Swing is a part of Java's Standard Library that provides a set of
GUI components for building graphical user interfaces. It is built on
top of the Abstract Window Toolkit (AWT) and offers a richer set of
features and more flexible components. Here’s a brief overview of
some of the key Swing components and their typical usage:

# 1. *JFrame*
- *Description*: The top-level container for creating a window.
- *Usage*: JFrame frame = new JFrame("Title");
- *Common Methods*: setSize(), setDefaultCloseOperation(),
setVisible()

# 2. *JPanel*
- *Description*: A generic container that can hold other
components.
- *Usage*: JPanel panel = new JPanel();
- *Common Methods*: add(), setLayout()

# 3. *JButton*
- *Description*: A push button that can trigger an action.
- *Usage*: JButton button = new JButton("Click Me");
- *Common Methods*: addActionListener()

# 4. *JLabel*
- *Description*: A non-editable text or image label.
- *Usage*: JLabel label = new JLabel("Hello, World!");
- *Common Methods*: setText(), setIcon()

# 5. *JTextField*
- *Description*: A single-line text input field.
- *Usage*: JTextField textField = new JTextField("Default Text");
- *Common Methods*: getText(), setText()

# 6. *JTextArea*
- *Description*: A multi-line area to display/edit text.
- *Usage*: JTextArea textArea = new JTextArea("Default Text");
- *Common Methods*: getText(), setText(), setLineWrap()

# 7. *JCheckBox*
- *Description*: A checkbox that can be either checked or
unchecked.
- *Usage*: JCheckBox checkBox = new JCheckBox("Option");
- *Common Methods*: isSelected(), setSelected()

# 8. *JRadioButton*
- *Description*: A button that is part of a group where only one
button can be selected at a time.
- *Usage*: JRadioButton radioButton = new
JRadioButton("Option");
- *Common Methods*: isSelected(), setSelected()
# 9. *JComboBox*
- *Description*: A combo box that allows users to select from a
drop-down list.
- *Usage*: JComboBox<String> comboBox = new
JComboBox<>(new String[]{"Option1", "Option2"});
- *Common Methods*: getSelectedItem(), setSelectedItem()

# 10. *JList*
- *Description*: A list of items where users can select one or more
items.
- *Usage*: JList<String> list = new JList<>(new String[]{"Item1",
"Item2"});
- *Common Methods*: getSelectedValuesList(), setListData()

# 11. *JTable*
- *Description*: A table component to display and edit tabular
data.
- *Usage*: JTable table = new JTable(data, columnNames);
- *Common Methods*: getValueAt(), setValueAt()

# 12. *JScrollPane*
- *Description*: A scrollable view for another component.
- *Usage*: JScrollPane scrollPane = new JScrollPane(component);
- *Common Methods*: setViewportView()
# 13. *JToolBar*
- *Description*: A toolbar that can hold a set of buttons or other
components.
- *Usage*: JToolBar toolBar = new JToolBar();
- *Common Methods*: add()

# 14. *JMenuBar, JMenu, JMenuItem*


- *Description*: Components for creating a menu bar with menus
and menu items.
- *Usage*:
java
JMenuBar menuBar = new JMenuBar();
JMenu menu = new JMenu("File");
JMenuItem menuItem = new JMenuItem("Open");
menu.add(menuItem);
menuBar.add(menu);
frame.setJMenuBar(menuBar);

# 15. *JDialog*
- *Description*: A pop-up dialog window that can be modal or
modeless.
- *Usage*: JDialog dialog = new JDialog(frame, "Dialog Title", true);
- *Common Methods*: setVisible(), setSize()
# Common Layout Managers:
- *FlowLayout*: Arranges components in a left-to-right flow.
- *BorderLayout*: Divides the container into five regions: north,
south, east, west, and center.
- *GridLayout*: Arranges components in a grid.
- *BoxLayout*: Arranges components in a single row or column.

# Example of a Simple Swing Application:


java
import javax.swing.*;

public class SimpleSwingExample {


public static void main(String[] args) {
// Create the frame
JFrame frame = new JFrame("Simple Swing Example");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300, 200);

// Create a panel and add components


JPanel panel = new JPanel();
JLabel label = new JLabel("Enter text:");
JTextField textField = new JTextField(20);
JButton button = new JButton("Submit");
panel.add(label);
panel.add(textField);
panel.add(button);

// Add the panel to the frame


frame.add(panel);
frame.setVisible(true);
}
}

This code creates a simple Swing application with a window


containing a label, a text field, and a button. Each Swing component
comes with its own set of methods for configuring its appearance
and behavior, so you can customize your GUI according to your
needs.

5. Differentiate between checkbox and radio button


https://www.geeksforgeeks.org/radio-button-vs-checkbox-in-
html/#:~:text=Radio%20buttons%20allow%20users%20to,checkboxe
s%20for%20multiple%20independent%20choices

6. Differentiate between list and combo box with example(IMP)


ANS : In Swing, JList and JComboBox are both components used for
displaying and selecting from a list of items, but they have different
use cases and behaviors. Here’s a breakdown of the differences
between JList and JComboBox, along with examples to illustrate their
usage:

# *1. JList*

# *Description:*
- JList displays a list of items in a list format where users can select
one or more items from a visible list.
- It's often used when you want to present a list of options where the
user can see multiple options at once.
# *Features:*
- Displays all the items at once if space allows or provides scroll bars
if there are too many items.
- Supports single or multiple selections.
- Allows custom cell rendering and sorting.

# *Example:*

java
import javax.swing.*;
import java.awt.*;

public class JListExample {


public static void main(String[] args) {
// Create the frame
JFrame frame = new JFrame("JList Example");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300, 200);

// Create an array of items


String[] items = {"Apple", "Banana", "Cherry", "Date", "Fig",
"Grape"};

// Create a JList with the items


JList<String> list = new JList<>(items);

list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELE
CTION);

// Add the JList to a JScrollPane


JScrollPane scrollPane = new JScrollPane(list);

// Add the scroll pane to the frame


frame.add(scrollPane, BorderLayout.CENTER);
frame.setVisible(true);
}
}

# *Key Points:*
- All items in the list are visible if the space permits.
- Users can select multiple items (depending on the selection mode).
- Use JList when you want users to view and select from a list of
items in a dedicated space.

# *2. JComboBox*

# *Description:*
- JComboBox presents a drop-down list of items from which users
can select one item.
- It's used when you want to conserve screen space and only show
the list when the user clicks on the drop-down arrow.

# *Features:*
- Only shows the currently selected item and hides the rest of the list
until the user interacts with it.
- Supports single item selection.
- Useful for conserving space and presenting a compact selection UI.

# *Example:*

java
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class JComboBoxExample {


public static void main(String[] args) {
// Create the frame
JFrame frame = new JFrame("JComboBox Example");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300, 200);

// Create an array of items


String[] items = {"Apple", "Banana", "Cherry", "Date", "Fig",
"Grape"};

// Create a JComboBox with the items


JComboBox<String> comboBox = new JComboBox<>(items);

// Add an action listener to the combo box


comboBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String selectedItem = (String) comboBox.getSelectedItem();
JOptionPane.showMessageDialog(frame, "Selected Item: " +
selectedItem);
}
});

// Add the combo box to the frame


frame.add(comboBox);
frame.setVisible(true);
}
}

#### *Key Points:*


- Shows only one item at a time with a drop-down arrow to view
more options.
- Users can select only one item at a time.
- Use JComboBox when you want a compact control to let users pick
from a predefined list of options.

### *Summary*

- **JList**: Suitable for displaying a list of items where multiple


items might be visible simultaneously, and you want the user to have
a more expansive view of the options. It allows multiple selections.
- **JComboBox**: Ideal for situations where space is limited, and
you want to present a single selected item with a drop-down list of
options. It is more compact and allows only a single selection at a
time.
Choose between JList and JComboBox based on how much space you
have and how you want to present the list of options to the user.

7. Explain the Java Print Service API with example


https://docs.oracle.com/javase/8/docs/technotes/guides/jps/index.
html#:~:text=The%20Java%20Print%20Service%20API%20includes%2
0an%20extensible%20print%20attribute,capabilities%20specified%2
0by%20the%20attributes
8. Explain the delegation event model with diagram
https://www.javatpoint.com/delegation-event-model-in-java

9. Explain the event classes with example(IMP)


https://www.geeksforgeeks.org/event-handling-in-java/

10.. Explain the event interfaces with example


https://www.geeksforgeeks.org/event-handling-in-java/

11. Explain the JDBC with architecture


https://www.geeksforgeeks.org/introduction-to-jdbc/

12. Explain the JDBC with the types of drivers (IMP)


https://www.geeksforgeeks.org/jdbc-drivers/

13. Explain the following


a. java.sql packages,
https://www.javatpoint.com/java-sql-package
b. using statement,
https://www.geeksforgeeks.org/types-of-statements-in-jdbc/
c. prepared statement,
https://www.geeksforgeeks.org/types-of-statements-in-jdbc/
d. callable statement
https://www.geeksforgeeks.org/types-of-statements-in-jdbc/
14. Differentiate between BLOB and CLOB with example(V.V IMP)
https://www.tutorialspoint.com/what-is-the-difference-between-
blob-and-clob-datatypes

Unit 3 JAVA

1. Explain the servlets with their advantages and disadvantage(SKIP)

2. Explain the servlets with their life cycle


https://www.geeksforgeeks.org/life-cycle-of-a-servlet/

3. Explain the servlets with their types and example


https://www.geeksforgeeks.org/introduction-java-servlets/

4. Differentiate between servlets request and servlets response with


example(SKIP)

5. Explain the cookies with their types and example


https://www.geeksforgeeks.org/understanding-cookies-in-web-
browsers/

6. Explain the JSP with their advantages and disadvantages (SKIP)


7. Explain the JSP with their architecture
https://www.geeksforgeeks.org/jsp-architecture/

8. Explain the JSP with their Life cycle


https://www.geeksforgeeks.org/life-cycle-of-jsp/

9. Explain the JSP with their types of directives(SKIP)

10. Explain the JSP with their implicit objects


https://www.geeksforgeeks.org/jsp-implicit-objects-request-and-
response/

11. Explain the different CRUD operations with their examples


https://www.javatpoint.com/crud-operations-in-java

12. Explain the JSON with their advantages and disadvantages(SKIP)

13. Explain the different data types in JSON


https://www.geeksforgeeks.org/json-data-types/

14. Differentiate between JSON and XML with example


https://www.geeksforgeeks.org/difference-between-json-and-xml/
15. Explain the JSON with JAVA and their example(SKIP)

You might also like