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

Java QB

The document contains a comprehensive set of questions and tasks related to Java programming, covering fundamental concepts such as keywords, data types, object-oriented principles, exception handling, and collections. It also includes practical coding exercises and design challenges that require the application of Java concepts in various scenarios. The content is structured to facilitate understanding and application of Java programming techniques.

Uploaded by

vmwtl8gsp6
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 views12 pages

Java QB

The document contains a comprehensive set of questions and tasks related to Java programming, covering fundamental concepts such as keywords, data types, object-oriented principles, exception handling, and collections. It also includes practical coding exercises and design challenges that require the application of Java concepts in various scenarios. The content is structured to facilitate understanding and application of Java programming techniques.

Uploaded by

vmwtl8gsp6
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/ 12

1. What is a keyword in Java?

(Remember)

2. Define a constant in Java programming. (Remember)

3. What is the primary purpose of JVM in Java? (Understand)

4. List two primitive data types in Java. (Remember)

5. What is the role of a constructor in a Java class? (Understand)

6. What does the 'static' keyword signify in Java? (Understand)

7. Explain the concept of method overloading. (Understand)

8. What is the purpose of the 'this' keyword in Java? (Understand)

9. Define an abstract class in Java. (Remember)

10. What is the difference between shallow and deep cloning? (Understand)

11. How does garbage collection work in Java? (Understand)

12. What is the function of the 'final' keyword in Java? (Remember)

13. Explain the concept of an interface in Java. (Understand)

14. What is a nested class in Java? (Remember)

15. How does Java achieve platform independence? (Understand)


16. What is the purpose of the 'super' keyword in Java? (Remember)

17. Define method recursion in Java. (Remember)

18. What is the role of the 'public' access modifier in Java? (Understand)

19. Explain the concept of generic class types in Java. (Understand)

20. What is the purpose of the 'finalize()' method in Java? (Remember)

1. What is inheritance in Object-Oriented Programming (OOP)? (Remember)

2. List the types of inheritance supported in Java. (Remember)

3. What keyword is used to inherit a class in Java? (Remember)

4. Explain the use of the 'super' keyword in Java. (Understand)

5. What is method overriding in Java? (Understand)

6. Define polymorphism in the context of inheritance. (Remember)

7. How does a constructor behave in an inherited class? (Understand)

8. What is the primary benefit of using inheritance in OOP? (Understand)

9. Can a Java class inherit multiple classes directly? (Remember)


10. How do you implement an interface in Java? (Remember)

11. What is type compatibility in the context of inheritance? (Understand)

12. What is the difference between method overloading and method overriding?
(Understand)

13. Explain how data members are inherited in Java. (Understand)

14. What is the purpose of the 'extends' keyword in Java? (Remember)

15. How does Java achieve polymorphism through inheritance? (Understand)

16. What is type conversion in the context of inheritance? (Understand)

17. Can constructors be inherited in Java? (Remember)

18. What is the use of the 'instanceof' operator in Java? (Remember)

19. How does implementing an interface differ from extending a class? (Understand)

20. Explain the concept of an abstract class in Java. (Understand)

1. Exception Handling:

1. What is an exception in Java? (Remember)

2. Differentiate between an error and an exception in Java. (Understand)

3. What is the purpose of the 'try' block in exception handling? (Understand)


4. How does the 'catch' block function in exception handling? (Understand)

5. What is the role of the 'finally' block in Java exception handling? (Understand)

6. What keyword is used to manually throw an exception in Java? (Remember)

7. Explain the purpose of the 'throws' keyword in method declaration.


(Understand)

8. What is the difference between checked and unchecked exceptions?


(Understand)

9. Name two built-in exceptions in Java. (Remember)

10. How can you create a user-defined exception in Java? (Remember)

2. Packages:

11. What is a package in Java? (Remember)

12. How does a package provide access protection in Java? (Understand)

13. What keyword is used to define a package in Java? (Remember)

14. Explain the purpose of the CLASSPATH environment variable. (Understand)

15. What is a JAR file in Java? (Remember)

16. How do you import a class from a package in Java? (Remember)


17. What is a static import in Java? (Understand)

18. Explain the naming convention for packages in Java. (Remember)

19. How does package organization help in large Java projects? (Understand)

20. What is the default package in Java? (Remember)

3. Arrays and Strings:

1. How do you declare a one-dimensional array in Java? (Remember)

2. What is the index of the first element in a Java array? (Remember)

3. How do you initialize a multi-dimensional array in Java? (Remember)

4. What is the difference between mutable and immutable strings in Java?


(Understand)

5. Which class represents mutable strings in Java? (Remember)

6. How do you use a for-each loop to iterate over a string in Java? (Apply)

7. What method is used to split a string into tokens in Java? (Remember)

8. How do you create a string using StringBuffer in Java? (Apply)

4. Useful Classes:

9. Which class provides utility methods for arrays in Java? (Remember)


10. What is the purpose of the Observable class in Java? (Understand)

11. Which class is used to represent date and time in Java 8 and later? (Remember)

12. What is the primary use of the Scanner class in Java? (Understand)

13. What package contains classes for input/output operations in Java? (Remember)

14. What is a stream in Java I/O? (Understand)

15. Name two classes used for reading from files in Java. (Remember)

16. What are the three standard streams in Java? (Remember)

17. How do you create a File object in Java? (Apply)

18. What is the purpose of buffering in I/O operations? (Understand)

19. What is a FileChannel in Java NIO? (Remember)

20. What interface must a class implement to enable object serialization?


(Remember)

1. Write a Java code snippet to reverse a string using StringBuilder. (Apply)

2. Implement a method to find the second largest element in an integer array.


(Apply)

3. Use a regular expression to validate an email address in Java. (Apply)


4. Create a program that reads a text file and counts the occurrence of each word.
(Apply)

5. Analyze:

6. Analyze the performance difference between ArrayList and LinkedList when


inserting elements at the beginning of the list. (Analyze)

7. Compare and contrast the use of BufferedReader and Scanner for reading input
in Java. (Analyze)

8. Examine the differences in memory usage between String, StringBuilder, and


StringBuffer for concatenation operations. (Analyze)

9. Investigate the impact of using different buffer sizes on file I/O performance in
Java. (Analyze)

10. Evaluate:

11. 9. Evaluate the pros and cons of using checked vs. unchecked exceptions in a
large-scale Java application. (Evaluate)

12. 10. Assess the suitability of Java's built-in serialization mechanism for long-term
data storage. (Evaluate)

13. 11. Judge the effectiveness of using the Observer pattern (Observable and
Observer classes) in a real-time system. (Evaluate)

14. 12. Critique the use of regular expressions for complex string parsing tasks in
terms of readability and maintainability. (Evaluate)

15. Create:
16. 13. Design a custom exception hierarchy for a banking application, considering
different types of potential errors. (Create)

17. 14. Develop a utility class that provides advanced array manipulation methods
not available in the standard Java Arrays class. (Create)

18. 15. Construct a file encryption/decryption system using Java I/O and security
APIs. (Create)

19. 16. Create a custom annotation and processor to generate boilerplate code for
data classes in Java. (Create)

1. (Apply) Write a Java method that checks if a given string is a valid palindrome,
considering only alphanumeric characters and ignoring case.

2. (Analyze) Explain the difference between `==` and `.equals()` when comparing
objects in Java. Provide an example to illustrate your answer.

3. (Apply) Implement a method to find the intersection of two integer arrays (i.e.,
common elements) using Java Collections.

4. (Understand) Describe the purpose of the `final` keyword in Java and provide
examples of its use with variables, methods, and classes.

5. (Apply) Write a Java program that demonstrates the use of a try-catch-finally


block to handle file I/O operations.

6. (Analyze) Compare the memory usage and performance of `String` vs


`StringBuilder` for repeated string concatenation operations.

7. (Apply) Implement a simple producer-consumer pattern using `wait()` and


`notify()` methods in Java.
8. (Understand) Explain the concept of method overloading and method overriding
in Java. Provide a code example for each.

9. (Apply) Write a Java method that uses a lambda expression to filter even
numbers from a list of integers.

10. (Analyze) Discuss the differences between `ArrayList` and `LinkedList` in terms
of their internal structure and performance characteristics.

11. (Apply) Implement a generic method in Java that swaps two elements in an
array of any type.

12. (Understand) Describe the purpose and usage of the `static` keyword in Java,
providing examples for variables and methods.

13. (Apply) Write a Java program that demonstrates the use of a `TreeMap` to store
and retrieve key-value pairs in sorted order.

14. (Analyze) Explain the concept of autoboxing and unboxing in Java. Provide
examples where these features are implicitly used.

15. (Apply) Implement a simple thread-safe singleton class in Java using double-
checked locking.

1. (Apply) Write a Java method that reverses a given string without using any
built-in reverse functions.

2. (Understand) Explain the difference between an abstract class and an interface


in Java. Provide a scenario where you would use one over the other.

3. (Apply) Implement a method that finds the second largest element in an integer
array.

4. (Analyze) Compare and contrast checked and unchecked exceptions in Java.


Provide an example of each.
5. (Apply) Write a Java program that demonstrates the use of a HashMap to count
the frequency of words in a given string.

6. (Understand) Describe the purpose of the `super` keyword in Java and provide
an example of its usage in method overriding.

7. (Apply) Implement a simple generic class in Java that can store and retrieve
elements of any type.

8. (Analyze) Explain the concept of method overloading in Java and how it differs
from method overriding. Provide code examples for both.

9. (Apply) Write a Java method that uses a try-with-resources statement to read


the contents of a text file.

10. (Understand) Describe the purpose and usage of the `static` keyword in Java,
providing examples for both methods and variables.

11. (Apply) Implement a Java method that uses a lambda expression to sort a list of
strings based on their length.

12. (Analyze) Compare the use of `StringBuilder` and `StringBuffer` in Java. When
would you choose one over the other?

13. (Apply) Write a Java program that demonstrates the use of the `Comparable`
interface to sort custom objects.

14. (Understand) Explain the concept of polymorphism in Java and provide a simple
code example to illustrate it.

15. (Apply) Implement a method in Java that uses a regular expression to validate
an email address.
1. Write a Java method that reverses a given string without using any built-in
reverse functions.

2. Explain the difference between an abstract class and an interface in Java.

3. Implement a method that finds the second largest element in an integer array.

4. Compare and contrast checked and unchecked exceptions in Java. Provide an


example of each.

5. Write a Java program that demonstrates the use of a HashMap to count the
frequency of words in a given string.

6. Implement a generic class called `Pair<T, U>` that can store two elements of
different types. Include methods to get and set these elements. Demonstrate its
usage with different data types.

7. Write a Java program that reads data from a text file, processes it to count the
occurrences of each word, and writes the results to another file. Use appropriate
exception handling and try-with-resources.

8. Explain the concept of multithreading in Java. Write a program that creates two
threads: one that prints even numbers and another that prints odd numbers up
to a given limit, ensuring they print in sequence.

9. Describe the Collections framework in Java. Implement a program that


demonstrates the use of ArrayList, LinkedList, and HashSet, highlighting the
differences in their performance for adding, removing, and searching elements.

10. Design a simple banking system using object-oriented principles in Java. Include
classes for Bank, Account (abstract), SavingsAccount, and CurrentAccount.
Implement methods for deposit, withdraw, and calculate interest. Use
inheritance, polymorphism, and exception handling where appropriate.
Demonstrate the usage of your classes in a main method.
11. Create a student management system that allows adding students, courses, and
managing student enrollments. Use appropriate data structures (e.g., ArrayList,
HashMap) to store student and course information. Implement methods to:
a) Add a new student
b) Add a new course
c) Enroll a student in a course
d) Display all courses a student is enrolled in
e) Display all students enrolled in a specific course
20. Include proper exception handling and demonstrate the functionality in a main
method.

12. Implement a multi-threaded chat server and client application in Java. The
server should be able to handle multiple client connections concurrently. Clients
should be able to send messages to all connected clients or to a specific client. Use
socket programming and proper synchronization techniques. Demonstrate the
application's functionality with at least three concurrent client connections.

13. Design and implement a generic graph data structure in Java. Include methods
for adding vertices and edges, performing depth-first search (DFS) and breadth-
first search (BFS), and finding the shortest path between two vertices (e.g., using
Dijkstra's algorithm). Demonstrate the usage of your graph implementation with
both directed and undirected graphs, using different data types for vertices.

You might also like