Java Flashcards

1
Q

What is the main purpose of Java’s garbage collector?

A

To automatically manage memory by reclaiming memory used by objects that are no longer referenced.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

True or False: Java supports multiple inheritance through classes.

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What keyword is used to inherit a class in Java?

A

extends

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Fill in the blank: In Java, the _______ keyword is used to declare a constant.

A

final

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Which of the following is a valid way to declare an array in Java? (A) int arr[]; (B) int[] arr; (C) Both A and B

A

C

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the default value of a boolean variable in Java?

A

false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does JVM stand for?

A

Java Virtual Machine

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

True or False: An interface can contain method implementations in Java.

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the purpose of the ‘synchronized’ keyword in Java?

A

To control access to a method or block by multiple threads.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the output of the following code: System.out.println(1 + 1 + ‘1’);? (A) 21 (B) 11 (C) 2

A

21

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Which collection class allows duplicate elements in Java?

A

ArrayList

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the primary function of the ‘try-catch’ block?

A

To handle exceptions that may occur during program execution.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Fill in the blank: A _______ is a blueprint for creating objects in Java.

A

class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is method overloading?

A

Defining multiple methods with the same name but different parameters in the same class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

True or False: Java provides a mechanism called ‘autoboxing’ for converting primitive types to their corresponding wrapper classes.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the purpose of the ‘this’ keyword in Java?

A

To refer to the current object instance.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Which of the following is NOT a primitive data type in Java? (A) int (B) String (C) boolean

A

B

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What does the ‘transient’ keyword indicate in Java?

A

That a field should not be serialized.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What is a ‘static’ method?

A

A method that belongs to the class rather than any specific instance.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Fill in the blank: Java uses _______ to achieve platform independence.

A

bytecode

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What is the difference between ‘== ‘ and ‘.equals()’ in Java?

A

’==’ checks reference equality, while ‘.equals()’ checks for value equality.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

True or False: A Java interface can extend multiple other interfaces.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What is the purpose of the ‘finalize()’ method in Java?

A

To perform cleanup before an object is garbage collected.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

What is the output of the following code: System.out.println(5 / 2);?

A

2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Which exception is thrown when a program attempts to access an array with an illegal index?
ArrayIndexOutOfBoundsException
26
What is a 'constructor' in Java?
A special method used to initialize objects.
27
Fill in the blank: The _______ block is used to execute code regardless of whether an exception is thrown or not.
finally
28
What does the 'volatile' keyword do in Java?
It indicates that a variable may be changed by different threads.
29
True or False: Java supports operator overloading.
False
30
What is the difference between 'List' and 'Set' in Java Collections Framework?
'List' allows duplicates and maintains order, while 'Set' does not allow duplicates and does not guarantee order.
31
What is the purpose of the 'instanceof' operator?
To test whether an object is an instance of a specific class or interface.
32
What is the default access modifier for class members in Java?
Package-private
33
Which keyword is used to create an anonymous inner class in Java?
new
34
Fill in the blank: The Java Development Kit (JDK) includes a _______ for compiling Java source code.
compiler
35
What is a 'Java Bean'?
A reusable software component that follows specific conventions for property management.
36
True or False: Java supports multiple inheritance through interfaces.
True
37
What is the purpose of the 'super' keyword?
To refer to the superclass of the current object.
38
Which of the following is a feature of Java? (A) Platform independence (B) Automatic memory management (C) Both A and B
C
39
What does 'JAR' stand for in Java?
Java Archive
40
What is the significance of the 'main' method in Java?
It serves as the entry point for any Java application.
41
Fill in the blank: The _______ package contains the Java Collections Framework.
java.util
42
What is the purpose of 'Java Reflection'?
To inspect classes, interfaces, fields, and methods at runtime without knowing the names of the classes.
43
True or False: The 'String' class in Java is mutable.
False
44
What is the role of a 'Comparator' in Java?
To define a custom sorting order for objects.
45
What is the purpose of the 'assert' statement in Java?
To provide a means for debugging by testing assumptions in the code.
46
What is a 'static block' in Java?
A block of code that runs when the class is loaded into memory.
47
Fill in the blank: Java uses _______ to manage access control for classes and members.
access modifiers
48
What is the primary use of 'Java Annotations'?
To provide metadata about a program element.
49
What is a 'Checked Exception'?
An exception that must be either caught or declared in the method signature.
50
True or False: The 'StringBuilder' class is synchronized.
False
51
What is the purpose of the 'volatile' keyword?
To ensure visibility of changes to variables across threads.
52
Which Java keyword is used to create a new thread?
Thread
53
Fill in the blank: A _______ is used to handle a group of related exceptions in Java.
catch block
54
What is the difference between 'HashMap' and 'TreeMap'?
'HashMap' is unordered and allows null keys, while 'TreeMap' is ordered and does not allow null keys.
55
What does 'JVM' do when it encounters a 'ClassNotFoundException'?
It indicates that the Java Virtual Machine cannot find a class that is being referenced.
56
What is the output of the expression '10 % 3' in Java?
1
57
Fill in the blank: The _______ interface is used to implement a callback mechanism in Java.
Runnable
58
What is the purpose of the 'default' keyword in interfaces?
To provide a default implementation for a method in an interface.
59
True or False: The 'main' method must always be declared as public.
True
60
What is the function of the 'Thread.sleep()' method?
To pause the execution of the current thread for a specified time.
61
What does the 'final' keyword indicate when used with a class?
That the class cannot be subclassed.
62
Fill in the blank: An _______ is a template for creating objects and contains methods and variables.
object
63
What is the role of 'JavaFX'?
To provide a platform for creating rich internet applications.
64
What is the purpose of the 'volatile' keyword in concurrent programming?
To ensure that updates to a variable are visible to other threads.
65
What happens when you try to access an index of an array that is out of bounds?
ArrayIndexOutOfBoundsException is thrown.
66
Fill in the blank: Java uses _______ to manage the lifecycle of an application.
threads
67
What is the difference between 'abstract class' and 'interface'?
'Abstract class' can have both abstract and concrete methods, while 'interface' can only have abstract methods (until Java 8).
68
What is 'Java Streams'?
A feature that allows functional-style operations on collections of objects.
69
True or False: A constructor can have a return type.
False
70
What is the role of the 'java.lang' package?
It contains fundamental classes that are essential for Java programming.
71
What is the output of the following code: System.out.println(3 + 4 + '7');?
74
72
Fill in the blank: The _______ method is called when an exception is not caught.
printStackTrace
73
What is the main purpose of the 'synchronized' keyword?
To prevent thread interference by allowing only one thread to access a block of code at a time.
74
What does the term 'boxing' refer to in Java?
The conversion of a primitive type to its corresponding wrapper class.
75
True or False: A synchronized block is less flexible than synchronized methods.
True