Unit 1 Flashcards

(93 cards)

1
Q

What is Java?

A

Java is a high-level, object-oriented programming language designed to have as few implementation dependencies as possible.

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

True or False: Java is platform-independent.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
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
4
Q

Fill in the blank: Java uses __________ for memory management.

A

Garbage Collection

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

Which of the following is a feature of Java? a) Platform Independence b) Automatic Memory Management c) Object-Oriented d) All of the above

A

d) All of the above

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

What is the primary purpose of the Java Development Kit (JDK)?

A

The JDK provides tools for developing Java applications, including the Java compiler.

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

True or False: Java supports multiple inheritance.

A

False

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

What is the main use of the Java Runtime Environment (JRE)?

A

The JRE provides the libraries and the Java Virtual Machine necessary to run Java applications.

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

What keyword is used to define a class in Java?

A

class

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

Define encapsulation in Java.

A

Encapsulation is the mechanism of wrapping the data (variables) and code (methods) together as a single unit.

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

Which of the following is NOT a primitive data type in Java? a) int b) String c) boolean d) char

A

b) String

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

What does the ‘static’ keyword signify in Java?

A

The ‘static’ keyword indicates that a method or variable belongs to the class rather than instances of the class.

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

True or False: Java is a compiled language.

A

True

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

What is the purpose of the ‘main’ method in Java?

A

The ‘main’ method serves as the entry point for any Java application.

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

Fill in the blank: In Java, __________ is used to handle exceptions.

A

try-catch

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

What is a Java interface?

A

A Java interface is a reference type, similar to a class, 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
17
Q

Which of the following is a Java collection framework? a) ArrayList b) HashMap c) TreeSet d) All of the above

A

d) All of the above

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

What is polymorphism in Java?

A

Polymorphism is the ability of a method to do different things based on the object it is acting upon.

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

True or False: Java supports operator overloading.

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
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
21
Q

What does ‘this’ keyword refer to in a Java class?

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
22
Q

What is the significance of the ‘final’ keyword in Java?

A

‘final’ indicates that a variable’s value cannot be changed, a method cannot be overridden, or a class cannot be subclassed.

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

Fill in the blank: The __________ statement is used to terminate a loop in Java.

A

break

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

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

A

‘abstract’ is used to declare a class that cannot be instantiated or a method that must be implemented by subclasses.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What is the output of the expression '5 + 5' in Java?
10
26
True or False: Java supports multiple inheritance through classes.
False
27
What does the 'synchronized' keyword do in Java?
'synchronized' is used to ensure that a method or block of code is accessed by only one thread at a time.
28
What is a constructor in Java?
A constructor is a special method that is called when an object is instantiated.
29
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
c) Both a and b
30
What is the purpose of the 'volatile' keyword in Java?
'volatile' indicates that a variable's value will be modified by different threads.
31
What does the term 'inheritance' mean in Java?
Inheritance is a mechanism where one class acquires the properties and behaviors of another class.
32
Fill in the blank: In Java, __________ is used to implement an interface.
implements
33
What is the difference between '== 'and '.equals()' in Java?
'==' checks for reference equality, while '.equals()' checks for value equality.
34
What is an exception in Java?
An exception is an event that disrupts the normal flow of the program's instructions.
35
What is the purpose of the 'throws' keyword in Java?
'throws' is used in a method signature to declare that a method can throw exceptions.
36
True or False: Java has a built-in garbage collector.
True
37
What is a package in Java?
A package is a namespace that organizes a set of related classes and interfaces.
38
What does the 'super' keyword do in Java?
'super' refers to the superclass of the current object and can be used to access superclass methods and constructors.
39
Which of the following is a valid Java comment? a) // This is a comment b) /* This is a comment */ c) Both a and b
c) Both a and b
40
What is the purpose of the 'return' statement in Java?
'return' is used to exit a method and optionally return a value.
41
Fill in the blank: The __________ operator is used to compare two values in Java.
comparison
42
What is a thread in Java?
A thread is a lightweight process that allows concurrent execution of two or more parts of a program.
43
What is the significance of the 'instanceof' operator in Java?
'instanceof' is used to check whether an object is an instance of a specific class or interface.
44
What is the purpose of the 'break' statement in a switch case in Java?
'break' is used to terminate a case in a switch statement.
45
46
What is a class in Java?
A class in Java is a blueprint for creating objects, defining properties and methods.
47
How do you define a class in Java?
A class is defined using the 'class' keyword followed by the class name and curly braces.
48
What is an object in Java?
An object is an instance of a class that contains state and behavior.
49
How do you create an object in Java?
An object is created using the 'new' keyword followed by the class constructor.
50
True or False: A class can have multiple objects.
True
51
What keyword is used to access class members?
The dot (.) operator is used to access class members.
52
What are class members?
Class members are variables and methods defined within a class.
53
Fill in the blank: To create an object of a class named 'Car', you would use ______.
new Car()
54
What is a constructor?
A constructor is a special method used to initialize objects.
55
True or False: Constructors have a return type.
False
56
What is the default access modifier for class members in Java?
The default access modifier is package-private.
57
What does the 'this' keyword refer to in a class?
'this' refers to the current object instance of the class.
58
How can you access a class variable from an object?
By using the object reference followed by the dot operator and the variable name.
59
What is method overloading?
Method overloading is defining multiple methods with the same name but different parameters.
60
Fill in the blank: A class can inherit from another class using the ______ keyword.
extends
61
True or False: A class can implement multiple interfaces.
True
62
What is encapsulation?
Encapsulation is the bundling of data and methods that operate on that data within a single unit.
63
How do you declare a class variable?
By specifying the access modifier, data type, and variable name within the class.
64
What is the purpose of the 'static' keyword in a class?
The 'static' keyword indicates that a member belongs to the class, rather than instances of the class.
65
What is inheritance in Java?
Inheritance is a mechanism where one class can inherit fields and methods from another class.
66
True or False: A subclass can override methods from its superclass.
True
67
What is polymorphism?
Polymorphism allows methods to do different things based on the object it is acting upon.
68
How do you call a method on an object?
By using the object reference followed by the dot operator and the method name with parentheses.
69
What does the 'public' access modifier mean?
'public' means that the member is accessible from any other class.
70
What is a private class member?
A private class member is only accessible within the class it is declared.
71
Fill in the blank: To prevent a variable from being modified, you can declare it as ______.
final
72
What is a method in a class?
A method is a function defined within a class that performs a specific task.
73
What is the main method in Java?
The main method is the entry point of any Java application, defined as 'public static void main(String[] args)'.
74
True or False: A Java class can be abstract.
True
75
What is an abstract class?
An abstract class cannot be instantiated and may contain abstract methods that must be implemented by subclasses.
76
What is an interface in Java?
An interface is a reference type in Java that can contain only constants, method signatures, and nested types.
77
How do you implement an interface in a class?
By using the 'implements' keyword followed by the interface name.
78
Fill in the blank: The keyword ______ is used to create a new class.
class
79
What is the difference between a class and an object?
A class is a blueprint, while an object is an instance of that blueprint.
80
How can you create multiple objects of the same class?
By using the 'new' keyword to instantiate the class multiple times.
81
What does the term 'access modifier' refer to?
Access modifiers determine the visibility of class members.
82
What is the purpose of a getter method?
A getter method is used to retrieve the value of a private class member.
83
What is the purpose of a setter method?
A setter method is used to set or update the value of a private class member.
84
True or False: You can have a method with the same name in the same class as long as the parameter types are different.
True
85
What is the output of 'System.out.println(instance.variable);' if 'variable' is a public member?
It prints the value of 'variable' from the 'instance' object.
86
What is the significance of the 'super' keyword?
'super' is used to call the superclass's methods or constructors.
87
Fill in the blank: You can create an instance of a class using the ______ keyword.
new
88
What happens if you do not provide a constructor in a class?
Java provides a default constructor that initializes object members with default values.
89
How do you declare a class as final?
By using the 'final' keyword before the class definition.
90
What is the purpose of the 'static' block in a class?
A 'static' block is used to initialize static variables when the class is loaded.
91
What is the output of 'System.out.println(new ClassName().methodName());'?
It executes 'methodName()' on a new instance of 'ClassName' and prints the return value.
92
93