Model Exam 2 Mark Question Bank
1. Define exceptions in Java
An exception in Java is an unwanted event that disrupts the normal flow of a program during execution and can occur at compile time or runtime.
An exception in Java is an unwanted event that disrupts the normal flow of a program during execution and can occur at compile time or runtime.
2. Syntax for declaring a variable (with example)
A variable is declared using a data type followed by its name and optional value, for example:
A variable is declared using a data type followed by its name and optional value, for example:
int a = 10;
where int is the data type and a is the variable.
3. Define JRE
JRE (Java Runtime Environment) provides the environment required to run Java programs and includes JVM along with standard libraries needed for execution.
JRE (Java Runtime Environment) provides the environment required to run Java programs and includes JVM along with standard libraries needed for execution.
4. Character Stream in Java
Character streams are used to read and write text data using characters instead of bytes, such as FileReader and FileWriter classes from the java.io package.
Character streams are used to read and write text data using characters instead of bytes, such as FileReader and FileWriter classes from the java.io package.
5. Uses of Garbage Collection
Garbage collection is used to automatically remove unused objects, free memory, prevent memory leaks, and improve application performance.
Garbage collection is used to automatically remove unused objects, free memory, prevent memory leaks, and improve application performance.
6. Define events in Java
An event in Java is an action or occurrence (like mouse click or key press) that is detected by the program and handled using event-handling mechanisms.
An event in Java is an action or occurrence (like mouse click or key press) that is detected by the program and handled using event-handling mechanisms.
7. FileInputStream class
FileInputStream is used to read data from a file in byte format and belongs to the java.io package, commonly used for reading binary data.
FileInputStream is used to read data from a file in byte format and belongs to the java.io package, commonly used for reading binary data.
8. Checked vs Unchecked Exceptions
Checked exceptions occur at compile time and must be handled, whereas unchecked exceptions occur at runtime and handling is optional.
Checked exceptions occur at compile time and must be handled, whereas unchecked exceptions occur at runtime and handling is optional.
9. Constructor with example
A constructor is a special method used to initialize objects; for example:
A constructor is a special method used to initialize objects; for example:
Student(){ name="John"; }
is a constructor that initializes object data.
10. Steps to add components in Java
Create a frame (JFrame), create components (buttons, labels), set layout, add components using add(), and set visibility using setVisible(true).
Create a frame (JFrame), create components (buttons, labels), set layout, add components using add(), and set visibility using setVisible(true).
11. Define class and object with example
A class is a blueprint for objects, while an object is an instance of a class; for example:
A class is a blueprint for objects, while an object is an instance of a class; for example:
class Student{}
Student s = new Student();
12. Data types & variable declaration
Java has primitive (int, float, char) and non-primitive (String, array) data types; example:
Java has primitive (int, float, char) and non-primitive (String, array) data types; example:
int num = 5;
declares and initializes a variable.
13. Constructor & its types
A constructor initializes objects in Java; types include default constructor and parameterized constructor.
A constructor initializes objects in Java; types include default constructor and parameterized constructor.
14. While vs Do-While loop (with example)
While loop checks condition before execution, e.g.,
While loop checks condition before execution, e.g.,
while(i<5)
whereas do-while executes at least once, e.g.,
do{ }while(i<5);
15. Types of exceptions with example
Java has checked (e.g., IOException) and unchecked exceptions (e.g., ArithmeticException) based on when they occur.
Java has checked (e.g., IOException) and unchecked exceptions (e.g., ArithmeticException) based on when they occur.
16. Built-in and user-defined packages
Built-in packages are predefined (e.g., java.lang), while user-defined packages are created by users to organize classes.
Built-in packages are predefined (e.g., java.lang), while user-defined packages are created by users to organize classes.
17. Two methods to create thread
Threads can be created by extending the Thread class or by implementing the Runnable interface.
Threads can be created by extending the Thread class or by implementing the Runnable interface.
18. Input vs Output stream
Input stream is used to read data (e.g., FileInputStream), while output stream is used to write data (e.g., FileOutputStream).
Input stream is used to read data (e.g., FileInputStream), while output stream is used to write data (e.g., FileOutputStream).
19. Java Swing package
Java Swing is a GUI package used to create desktop applications with components like buttons, frames, and text fields.
Java Swing is a GUI package used to create desktop applications with components like buttons, frames, and text fields.
20. MVC architecture & applications
MVC (Model-View-Controller) separates application into data, UI, and logic, used in web apps, desktop apps, and frameworks for better organization.
MVC (Model-View-Controller) separates application into data, UI, and logic, used in web apps, desktop apps, and frameworks for better organization.
0 Comments