NEW
Font size
WorksheetsJava Fundamentals Assessment
Total questions: 10
Worksheet time: 50secs
What are the primitive data types in Java?
byte, short, int, long, float, double, char, boolean
text, number, flag
integer, decimal, character
string, list, map
Explain the difference between 'if' and 'switch' statements.
'if' statements can only handle two conditions, while 'switch' can handle more than two.
The 'if' statement is for conditional branching, while 'switch' is for selecting among multiple cases based on a variable's value.
'if' statements evaluate expressions, while 'switch' evaluates boolean values.
'if' statements are used for loops, whereas 'switch' is used for functions.
What is encapsulation in Object-Oriented Programming?
Encapsulation is the bundling of data and methods that operate on that data within a single unit, restricting access to some components.
Encapsulation is the method of exposing all data and methods to the public.
Encapsulation refers to the inheritance of properties from a parent class.
Encapsulation is the process of creating multiple instances of a class.
How do you handle exceptions in Java?
Ignore exceptions and continue execution.
Use try-catch blocks to handle exceptions in Java.
Throw exceptions without handling them.
Use if-else statements to handle exceptions in Java.
What is the purpose of the ArrayList class in Java?
The purpose of the ArrayList class in Java is to provide a dynamic array that can grow and shrink in size, allowing for flexible storage and manipulation of elements.
To create a multi-dimensional array in Java.
To implement a stack data structure in Java.
To provide a fixed-size array for storing elements.
Describe the try-catch block in exception handling.
The try-catch block is a way to declare variables in programming.
The try-catch block is a mechanism for handling exceptions in programming, allowing for graceful error management.
The try-catch block is used to define functions in programming.
The try-catch block is a method for optimizing code performance.
What is the difference between a HashMap and a TreeMap?
HashMap is unordered and faster (O(1)), while TreeMap is ordered and slower (O(log n)).
Both HashMap and TreeMap are unordered and have the same performance (O(n)).
HashMap is ordered and faster (O(1)), while TreeMap is unordered and slower (O(log n)).
TreeMap is faster (O(1)) and HashMap is slower (O(log n)).
How do you read a file using File I/O in Java?
Use BufferedReader with FileReader to read a file line by line.
Use Scanner to read a file character by character.
Read the entire file into a byte array at once.
Utilize PrintWriter to write to a file instead of reading.
What is polymorphism in Java?
Polymorphism is a feature that allows Java to run on any operating system.
Polymorphism refers to the process of compiling Java code into bytecode.
Polymorphism is the ability of a single function or method to operate in different ways based on the object it is acting upon.
Polymorphism is the ability to create multiple classes in Java.
Explain the concept of inheritance in Java.
Inheritance in Java allows a subclass to inherit properties and methods from a superclass, promoting code reusability and establishing a class hierarchy.
Inheritance in Java restricts access to methods and properties of a class.
Inheritance in Java allows a class to create multiple instances of itself.
Inheritance in Java is a way to define interfaces without implementation.
