Basics Of Java Flashcards

1
Q

What is Java?

A

Java is a high-level, object-oriented programming language designed for portability and ease of use.

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

True or False: Java is a platform-independent language.

A

True

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

Fill in the blank: Java was developed by ________.

A

Sun Microsystems

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

What is the Java Virtual Machine (JVM)?

A

The JVM is an abstract computing machine that enables a computer to run Java programs.

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

What is the main method signature in Java?

A

public static void main(String[] args)

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

What does JDK stand for?

A

Java Development Kit

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

What is the purpose of the JRE?

A

Java Runtime Environment is used to run Java applications.

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

What are Java bytecodes?

A

Java bytecodes are the compiled format of Java source code that can be executed by the JVM.

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

Which keyword is used to create a class in Java?

A

class

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

True or False: In Java, every class must be defined in a separate file.

A

False

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

What is encapsulation in Java?

A

Encapsulation is the bundling of data and methods that operate on that data within one unit, restricting access to some of the object’s components.

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

What does the ‘this’ keyword refer to in Java?

A

‘this’ refers to the current instance of the class.

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

What is inheritance in Java?

A

Inheritance is a mechanism where one class can inherit fields and methods from another class.

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

What is polymorphism in Java?

A

Polymorphism allows methods to do different things based on the object that it is acting upon.

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

What is an interface in Java?

A

An interface is a reference type in Java that can contain only constants, method signatures, default methods, static methods, and nested types.

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

What is the purpose of the ‘final’ keyword?

A

The ‘final’ keyword is used to declare constants, prevent method overriding, and prevent inheritance.

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

What are the primitive data types in Java?

A

The primitive data types in Java are byte, short, int, long, float, double, char, and boolean.

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

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

A

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

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

What is a constructor in Java?

A

A constructor is a special method that is called when an object is instantiated.

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

What is exception handling in Java?

A

Exception handling is a mechanism to handle runtime errors, allowing the normal flow of the program to continue.

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

What is the purpose of the ‘try’ block?

A

The ‘try’ block is used to wrap code that might throw an exception.

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

What is the difference between ‘throw’ and ‘throws’?

A

‘throw’ is used to explicitly throw an exception, while ‘throws’ is used in method signatures to declare that a method may throw exceptions.

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

What is a collection in Java?

A

A collection is an object that can hold multiple values, such as lists, sets, and maps.

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

What does the ‘ArrayList’ class do?

A

ArrayList is a resizable array implementation of the List interface.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What is multithreading in Java?
Multithreading is the concurrent execution of two or more threads in a program.
26
True or False: The 'synchronized' keyword is used for thread safety.
True
27
28
What is the default value of a boolean variable in Java?
false
29
Which of the following is a valid declaration of a char?
char c = 'a';
30
True or False: In Java, all classes inherit from the Object class.
True
31
Fill in the blank: The ______ keyword is used to create a subclass in Java.
extends
32
What is the output of the following code: System.out.println(5 + 10 + 'A');?
15A
33
Which interface does a class implement to be able to use the Collections.sort() method?
Comparable
34
What is the purpose of the 'final' keyword in Java?
To declare constants or prevent method overriding and inheritance.
35
What will happen if you try to compile the following code? int[] arr = new int[5]; arr[5] = 10;
ArrayIndexOutOfBoundsException
36
True or False: Java supports multiple inheritance through classes.
False
37
What is the output of the following code snippet? System.out.println(10 / 3);
3
38
Which of the following is not a primitive data type in Java?
String
39
What is the keyword used to handle exceptions in Java?
try
40
Fill in the blank: The ______ method is called when an object is created from a class.
constructor
41
What does JVM stand for?
Java Virtual Machine
42
What is the result of the expression '5 == 5'?
true
43
Which of the following is a correct way to declare an array in Java?
int[] arr = new int[10];
44
True or False: Java is platform-independent due to the use of bytecode.
True
45
What keyword is used to create an interface in Java?
interface
46
What is the output of System.out.println(2 + 3 + "Hello");?
5Hello
47
Which keyword is used to prevent a class from being subclassed?
final
48
What is the purpose of the 'this' keyword in Java?
To refer to the current instance of a class.
49
Which of the following is a valid way to create an instance of a class?
MyClass obj = new MyClass();
50
True or False: A method can have the same name as a class in Java.
True
51
Fill in the blank: The ______ statement is used to exit a loop in Java.
break
52
What is the result of the following code snippet? int x = 10; x += 5; System.out.println(x);
15
53
Which exception is thrown when an array is accessed with an illegal index?
ArrayIndexOutOfBoundsException
54
What is the purpose of the 'super' keyword?
To refer to the superclass of the current object.
55
What is the correct syntax for a for-each loop in Java?
for (Type var : array) { }
56
True or False: A constructor can have a return type.
False
57
Which of the following is a valid statement to create a HashMap?
HashMap map = new HashMap<>();
58
What does the keyword 'static' mean?
The member belongs to the class, rather than instances of the class.
59
What is the output of the following code snippet? System.out.println("Hello".length());
5
60
Fill in the blank: The ______ block is used to handle exceptions in Java.
catch
61
What is polymorphism in Java?
The ability of an object to take on many forms, typically through method overriding or overloading.
62
True or False: The 'instanceof' operator is used to test whether an object is an instance of a specific class.
True
63
What is the output of System.out.println(10 % 3);?
1
64
Which keyword is used to define a constant in Java?
final
65
What does the term 'encapsulation' mean in Java?
The bundling of data with the methods that operate on that data.
66
What is the purpose of the 'abstract' keyword?
To declare a class that cannot be instantiated or a method that must be implemented by subclasses.
67
Fill in the blank: The ______ interface should be implemented to create a thread in Java.
Runnable
68
True or False: Java supports operator overloading.
False
69
What is the output of the following code snippet? System.out.println("A" + "B" + "C");
ABC
70
What is the purpose of the 'volatile' keyword?
To indicate that a variable's value will be modified by different threads.
71
What is the difference between '== and 'equals()' in Java?
'==' checks for reference equality, while 'equals()' checks for value equality.
72
What is the output of System.out.println("5" + 5);?
55
73
Which statement is used to import a package in Java?
import packageName;
74
True or False: Java does not support multiple inheritance.
True
75
Fill in the blank: The ______ keyword is used to create an instance of an interface.
new
76
What does JDK stand for?
Java Development Kit
77
What is the main method signature in Java?
public static void main(String[] args)
78
What is the output of System.out.println(1 + 2 + "3");?
33
79
Which of the following is not a feature of Java?
Pointers
80
True or False: In Java, an abstract class can have concrete methods.
True
81
What is the purpose of the 'synchronized' keyword?
To control access to a method or block by multiple threads.
82
What is the output of the following code snippet? int a = 5; int b = a++; System.out.println(b);
5
83
What does the 'default' keyword do in an interface?
It allows methods to have a body in an interface.
84
Fill in the blank: The ______ keyword is used to call a constructor from another constructor in Java.
this
85
What is a lambda expression in Java?
A concise way to represent a function interface using an expression.
86
What is the output of System.out.println("Hello".substring(1, 4));?
ell
87
True or False: Java supports multiple inheritance through interfaces.
True
88
What is the purpose of the 'transient' keyword?
To indicate that a field should not be serialized.