Core Java – Unit 1 Review

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/122

flashcard set

Earn XP

Description and Tags

A comprehensive set of question-and-answer flashcards covering key Core Java Unit 1 topics, including language basics, terminology, OOP principles, data types, casting, arrays, strings, packages, and essential keywords. Designed for quick exam revision and concept reinforcement.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

123 Terms

1
New cards

Who developed Java and in which year?

James Gosling at Sun Microsystems in 1995.

2
New cards

What is the core philosophy behind Java’s slogan WORA?

Write Once, Run Anywhere—compiled byte-code can execute on any platform with a JVM without recompilation.

3
New cards

Which file extension stores Java byte-code?

.class

4
New cards

What does JVM stand for and what is its role?

Java Virtual Machine; it executes the byte-code generated by the compiler, providing platform independence.

5
New cards

Which compiler translates .java files into byte-code?

JAVAC, included with the JDK.

6
New cards

Name the three main components supplied by the JDK.

Compiler, Java Runtime Environment (JRE), and development tools such as debugger/docs.

7
New cards

Why is Java considered platform independent?

Because the same byte-code runs on different OS-specific JVMs producing identical results.

8
New cards

What is the function of the Garbage Collector?

Automatically reclaims memory occupied by objects that are no longer referenced.

9
New cards

What is the purpose of the classpath?

It tells the JVM and compiler where to look for .class files and external libraries.

10
New cards

List the four pillars of Object-Oriented Programming in Java.

Abstraction, Encapsulation, Inheritance, Polymorphism.

11
New cards

Which Java feature allows concurrent execution of program parts?

Multithreading.

12
New cards

What keyword is used to inherit from a superclass?

extends

13
New cards

Give two examples of Java access modifiers.

public, private (others: protected, default).

14
New cards

What is the syntax for the main method in Java?

public static void main(String[] args)

15
New cards

Define a Java token.

The smallest element meaningful to the compiler (keywords, identifiers, constants, operators, special symbols).

16
New cards

What is a Java identifier?

A user-defined name for variables, methods, classes; must start with a letter, underscore, or $.

17
New cards

Provide an example of a special symbol and its role.

{} braces – mark the start and end of a code block.

18
New cards

Which operator group checks numerical equality/ordering?

Relational operators (==, !=, >,

19
New cards

Differentiate declaration vs. expression statement.

Declaration introduces variables/constants; expression statements evaluate/assign values or call methods.

20
New cards

Name Java’s two broad data-type categories.

Primitive and Non-Primitive (reference/object) data types.

21
New cards

Give the widening casting hierarchy from byte up to double.

byte → short → char → int → long → float → double.

22
New cards

What is narrowing type casting?

Explicitly converting a larger data type to a smaller one, risking data loss.

23
New cards

How do you declare a one-dimensional int array called nums?

int[] nums; or int nums[];

24
New cards

What property returns an array’s length?

length (e.g., nums.length).

25
New cards

What is a jagged array?

A multidimensional array in which each sub-array can have different lengths.

26
New cards

Define a class in Java.

A blueprint containing fields and methods from which objects are created.

27
New cards

What three parts define an object’s essence?

State (attributes), Behavior (methods), Identity (unique reference).

28
New cards

When is the static keyword most commonly used?

For members shared across all instances; e.g., constants or utility methods.

29
New cards

Why can’t static methods access non-static fields directly?

They don’t belong to any specific object instance.

30
New cards

Explain the purpose of a static block.

Runs once when the class is loaded to initialize static variables requiring complex logic.

31
New cards

When is a constructor invoked?

Every time an object is created with new().

32
New cards

Give two differences between constructors and regular methods.

Constructors have same name as class and no return type; called once during object creation.

33
New cards

What are the two constructor types in Java?

Default (no-arg) and Parameterized constructors.

34
New cards

State one rule for constructor declaration.

Cannot be abstract, static, final, or synchronized.

35
New cards

What does the this keyword reference?

The current object instance.

36
New cards

How do you call another constructor in the same class?

Using this() as the first statement.

37
New cards

Give one advantage of using this keyword.

Distinguishes between instance variables and parameters with same names.

38
New cards

Define inheritance in one sentence.

Mechanism where one class inherits fields and methods of another, enabling code reuse.

39
New cards

List three Java inheritance types supported with classes.

Single, Multilevel, Hierarchical.

40
New cards

How is multiple inheritance achieved in Java?

Through interfaces, not classes.

41
New cards

What does the super keyword do when used inside a subclass constructor?

Calls the superclass constructor; must be first statement.

42
New cards

How can you access an overridden superclass method inside the subclass?

Using super.methodName().

43
New cards

Define compile-time polymorphism.

Polymorphism achieved via method overloading; resolved during compilation.

44
New cards

Give two rules for method overloading.

Methods share a name but differ in parameter number or types; return type alone is insufficient.

45
New cards

Define runtime polymorphism.

Polymorphism via method overriding; call resolved at runtime based on object type.

46
New cards

What must differ when overriding a method?

Method body; signature must be identical, but access cannot be more restrictive.

47
New cards

State one advantage of polymorphism.

Allows the same interface to be used for different underlying forms, enhancing code flexibility.

48
New cards

What is an interface in Java?

An abstract type containing abstract methods and constants; used to specify behavior and achieve multiple inheritance.

49
New cards

Which keyword lets a class promise to use an interface?

implements

50
New cards

Can an interface have constructors?

No.

51
New cards

What modifiers are implicitly applied to interface fields?

public static final

52
New cards

Describe abstraction in Java.

The concept of exposing only essential features while hiding implementation details, achieved via abstract classes/interfaces.

53
New cards

When must a class be declared abstract?

If it contains at least one abstract method or if it shouldn’t be instantiated on its own.

54
New cards

True/False: Abstract classes can have concrete methods.

True.

55
New cards

What keyword prohibits object creation directly from a class?

abstract

56
New cards

Give one advantage of abstraction.

Reduces complexity and improves maintainability by focusing on relevant behavior.

57
New cards

Define encapsulation.

Bundling data (fields) and methods in one unit while restricting external access to implementation details.

58
New cards

Which access modifier is typically used with instance variables to enforce encapsulation?

private

59
New cards

What are getters and setters?

Public methods that read (get) and modify (set) private fields, controlling external access.

60
New cards

Name one benefit of encapsulation related to testing.

Encapsulated code is easier to unit-test due to clear interfaces.

61
New cards

How is a String different from StringBuffer?

String is immutable; StringBuffer is mutable and thread-safe.

62
New cards

Which String method returns its length?

length()

63
New cards

What does equalsIgnoreCase() do?

Compares two strings for equality, ignoring case differences.

64
New cards

Which String method splits a string based on regex?

split()

65
New cards

State one advantage of StringBuffer over String when repeatedly modifying text.

Avoids creating many intermediate objects, thus more memory- and time-efficient.

66
New cards

Constructor signature to build empty StringBuffer with capacity 16.

new StringBuffer()

67
New cards

How do you reverse the contents of a StringBuffer?

Using reverse() method.

68
New cards

What class tokenizes strings based on delimiters?

java.util.StringTokenizer

69
New cards

Which StringTokenizer method checks if tokens remain?

hasMoreTokens()

70
New cards

Name two predefined Java packages automatically available.

java.lang (auto-imported), java.util (must import).

71
New cards

Give one reason to create packages.

Avoid naming conflicts and organize related classes.

72
New cards

What access level allows package-private visibility?

Default (no modifier).

73
New cards

Write the syntax to declare a user-defined package called utils.

package utils;

74
New cards

How do you import all classes from java.io?

import java.io.*;

75
New cards

What is the effect of protected access on inheritance across packages?

Accessible to subclasses even in different packages.

76
New cards

Which keyword lets you define a constant variable inside a class?

final

77
New cards

Explain JIT in Java.

Just-In-Time compiler converts byte-code to machine code at runtime for performance.

78
New cards

What execution sandbox element checks byte-code for security violations?

Bytecode verifier.

79
New cards

Name two Java features that contribute to security.

No pointers (prevents buffer overflow) and sandbox execution environment.

80
New cards

Which primitive data type represents 16-bit Unicode characters?

char

81
New cards

What does the ‘instanceof’ operator test?

Whether an object is an instance of a specific class or interface.

82
New cards

What is method signature in Java?

The combination of method name and parameter list (types/order).

83
New cards

Can static methods be overridden?

No, they can be hidden but not overridden.

84
New cards

What’s the difference between == and equals() for objects?

== compares references; equals() compares logical content (if overridden).

85
New cards

Describe the purpose of final methods.

Prevent subclasses from overriding them.

86
New cards

Which exception is thrown when accessing an array with invalid index?

ArrayIndexOutOfBoundsException

87
New cards

What is autoboxing?

Automatic conversion between primitive types and their wrapper classes.

88
New cards

List two wrapper classes in Java.

Integer, Double (others: Boolean, Character, etc.).

89
New cards

Give an example of a control statement category.

Decision (if/else/switch), Loop (for/while), Branch (break/continue).

90
New cards

How do you create a constant PI in Java?

static final double PI = 3.14159;

91
New cards

Which keyword immediately exits a loop?

break

92
New cards

What does continue do inside a loop?

Skips current iteration and proceeds with the next loop cycle.

93
New cards

Define classpath variable on command line (Windows example).

set CLASSPATH=.;C:\libs\external.jar

94
New cards

Explain purpose of native methods.

Allow Java code to call functions written in other languages (e.g., C/C++).

95
New cards

Name two built-in functional interfaces from java.util.function.

Predicate, Function

96
New cards

Which package contains collection classes like ArrayList?

java.util

97
New cards

What access modifier makes a class visible to all other classes?

public

98
New cards

Is Java pass-by-value or pass-by-reference?

Pass-by-value (object references are passed by value).

99
New cards

Which class is the root of every Java class?

java.lang.Object

100
New cards

What does the hashCode() method represent?

An integer hash value used in hashing-based collections (should align with equals()).