[go: up one dir, main page]

0% found this document useful (0 votes)
2 views5 pages

Java PartA All Units 1Mark QA

The document covers fundamental concepts of Java programming, including Object-Oriented Programming principles, control structures, classes, objects, inheritance, polymorphism, packages, exception handling, strings, and multithreading. It provides definitions and explanations for key terms and functionalities, such as constructors, method overloading, exception types, and thread states. Additionally, it highlights the importance of programming style, exception handling, and the Spring Boot framework in Java development.

Uploaded by

mvignesh5756
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)
2 views5 pages

Java PartA All Units 1Mark QA

The document covers fundamental concepts of Java programming, including Object-Oriented Programming principles, control structures, classes, objects, inheritance, polymorphism, packages, exception handling, strings, and multithreading. It provides definitions and explanations for key terms and functionalities, such as constructors, method overloading, exception types, and thread states. Additionally, it highlights the importance of programming style, exception handling, and the Spring Boot framework in Java development.

Uploaded by

mvignesh5756
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/ 5

UNIT I - Basics of Java & Control Structures

1. What are the four main principles of Object-Oriented Programming (OOP)?

Answer: Encapsulation, Inheritance, Polymorphism, Abstraction.

2. Define type casting in Java.

Answer: Converting one data type into another (e.g., int to float).

3. List any three tokens in Java.

Answer: Keywords, Identifiers, Literals.

4. What is the purpose of the break statement in loops?

Answer: Exits the current loop or switch block immediately.

5. How is user input handled in Java?

Answer: Using Scanner class (e.g., Scanner sc = new Scanner(System.in);).

6. What is the significance of command-line arguments in Java?

Answer: Pass input values to the main method using String[] args.

7. Differentiate between while and do-while loops.

Answer: while checks condition first; do-while runs once before checking.

8. Explain the use of escape sequences in Java with an example.

Answer: Special characters in strings. Example: \n for newline ("Hello\nWorld").

9. What are the types of comments in Java?

Answer: Single-line (//), Multi-line (/* */), Documentation (/** */).

10. Why is programming style important in Java development?

Answer: Improves readability, maintainability, and debugging.

UNIT II - Classes, Objects, and Constructors


1. What is the purpose of a constructor in Java?

Answer: Initializes objects when they are created.

2. Define access control in Java classes.

Answer: Determines visibility using modifiers like private, public, protected.

3. What is the difference between a class and an object?


Answer: Class is a blueprint; object is an instance of the class.

4. What does the static keyword do in a Java class?

Answer: Makes variables or methods belong to the class, not instances.

5. How do you declare a nested class in Java?

Answer: class Outer { class Inner { } }

6. What is the role of the this keyword in Java?

Answer: Refers to the current object of a class.

7. Differentiate between method overloading and constructor overloading.

Answer: Both have same name but different parameters; constructors initialize objects.

8. What is the significance of the final keyword in Java classes and methods?

Answer: Prevents method overriding, inheritance, or value reassignment.

9. How are arguments passed in Java: by value or by reference?

Answer: Java passes all arguments by value (object references are passed by value).

10. What are recursive methods? Give an example.

Answer: A method that calls itself.

int factorial(int n) {

if(n == 1) return 1;

return n * factorial(n - 1);

UNIT III - Inheritance and Polymorphism


1. What is an array in Java?

Answer: A data structure to store multiple values of same type in a single variable.

2. How do you declare and initialize a one-dimensional array in Java?

Answer: int[] arr = {1, 2, 3};

3. What is method overriding in Java?

Answer: Redefining a superclass method in a subclass.

4. Define inheritance and its importance in Java.


Answer: Inheritance allows one class to acquire properties of another, promoting reusability.

5. What is the difference between abstract classes and interfaces?

Answer: Abstract classes can have method bodies; interfaces only have abstract methods (before

Java 8).

6. What is the super keyword used for in inheritance?

Answer: Refers to superclass constructor or method.

7. List the types of inheritance supported in Java.

Answer: Single, Multilevel, Hierarchical (Java doesn't support multiple inheritance with classes).

8. How does polymorphism work in Java?

Answer: Same method behaves differently based on the object (via overloading and overriding).

9. What is an interface, and how is it different from a class?

Answer: Interface has only abstract methods; class has fields and methods with implementation.

10. Can an interface extend another interface? If yes, how?

Answer: Yes. interface B extends A {}

UNIT IV - Packages and Exception Handling


1. What is a package in Java?

Answer: A namespace that organizes classes and interfaces.

2. How do you import a package in Java?

Answer: import java.util.Scanner;

3. What are access modifiers, and how do they affect member access in a package?

Answer: They control visibility of class members: public, private, protected, default.

4. What is the difference between throws and throw in Java?

Answer: throw is used to throw exception, throws declares it in method signature.

5. Define exception handling and its importance in Java.

Answer: Manages runtime errors, improves program stability.

6. What are the different types of exceptions in Java?

Answer: Checked and Unchecked exceptions.


7. What is the purpose of the finally block in exception handling?

Answer: Executes code regardless of exception occurrence.

8. How does multiple catch block handling work in Java?

Answer: Allows handling multiple exception types individually.

9. What is the difference between byte stream classes and character stream classes?

Answer: Byte stream handles binary data, character stream handles text data.

10. How do you create a user-defined exception in Java?

Answer: class MyException extends Exception {}

UNIT V - Strings and Multithreading


1. What is the difference between String and StringBuffer in Java?

Answer: String is immutable, StringBuffer is mutable and thread-safe.

2. How can you compare two strings in Java?

Answer: Using equals() method.

3. What is the purpose of the CharSequence interface?

Answer: Represents a sequence of characters used by String, StringBuilder, etc.

4. How do you extract a substring from a given string in Java?

Answer: Using substring(start, end) method.

5. What is multithreading, and why is it important?

Answer: Concurrent execution of two or more threads to improve performance.

6. What are the different states of a thread in Java?

Answer: New, Runnable, Running, Blocked, Waiting, Timed Waiting, Terminated.

7. How do you create a new thread in Java using the Thread class?

Answer: Extend Thread class and override run() method.

8. What is inter-thread communication, and why is it needed?

Answer: Allows threads to communicate using wait(), notify() etc.

9. What is synchronization in multithreading?

Answer: Ensures only one thread accesses a critical section at a time.


10. What is Spring Boot, and why is it used in Java development?

Answer: Framework for creating standalone, production-grade Spring applications easily.

You might also like