1/122
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.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Who developed Java and in which year?
James Gosling at Sun Microsystems in 1995.
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.
Which file extension stores Java byte-code?
.class
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.
Which compiler translates .java files into byte-code?
JAVAC, included with the JDK.
Name the three main components supplied by the JDK.
Compiler, Java Runtime Environment (JRE), and development tools such as debugger/docs.
Why is Java considered platform independent?
Because the same byte-code runs on different OS-specific JVMs producing identical results.
What is the function of the Garbage Collector?
Automatically reclaims memory occupied by objects that are no longer referenced.
What is the purpose of the classpath?
It tells the JVM and compiler where to look for .class files and external libraries.
List the four pillars of Object-Oriented Programming in Java.
Abstraction, Encapsulation, Inheritance, Polymorphism.
Which Java feature allows concurrent execution of program parts?
Multithreading.
What keyword is used to inherit from a superclass?
extends
Give two examples of Java access modifiers.
public, private (others: protected, default).
What is the syntax for the main method in Java?
public static void main(String[] args)
Define a Java token.
The smallest element meaningful to the compiler (keywords, identifiers, constants, operators, special symbols).
What is a Java identifier?
A user-defined name for variables, methods, classes; must start with a letter, underscore, or $.
Provide an example of a special symbol and its role.
{} braces – mark the start and end of a code block.
Which operator group checks numerical equality/ordering?
Relational operators (==, !=, >,
Differentiate declaration vs. expression statement.
Declaration introduces variables/constants; expression statements evaluate/assign values or call methods.
Name Java’s two broad data-type categories.
Primitive and Non-Primitive (reference/object) data types.
Give the widening casting hierarchy from byte up to double.
byte → short → char → int → long → float → double.
What is narrowing type casting?
Explicitly converting a larger data type to a smaller one, risking data loss.
How do you declare a one-dimensional int array called nums?
int[] nums; or int nums[];
What property returns an array’s length?
length (e.g., nums.length).
What is a jagged array?
A multidimensional array in which each sub-array can have different lengths.
Define a class in Java.
A blueprint containing fields and methods from which objects are created.
What three parts define an object’s essence?
State (attributes), Behavior (methods), Identity (unique reference).
When is the static keyword most commonly used?
For members shared across all instances; e.g., constants or utility methods.
Why can’t static methods access non-static fields directly?
They don’t belong to any specific object instance.
Explain the purpose of a static block.
Runs once when the class is loaded to initialize static variables requiring complex logic.
When is a constructor invoked?
Every time an object is created with new().
Give two differences between constructors and regular methods.
Constructors have same name as class and no return type; called once during object creation.
What are the two constructor types in Java?
Default (no-arg) and Parameterized constructors.
State one rule for constructor declaration.
Cannot be abstract, static, final, or synchronized.
What does the this keyword reference?
The current object instance.
How do you call another constructor in the same class?
Using this() as the first statement.
Give one advantage of using this keyword.
Distinguishes between instance variables and parameters with same names.
Define inheritance in one sentence.
Mechanism where one class inherits fields and methods of another, enabling code reuse.
List three Java inheritance types supported with classes.
Single, Multilevel, Hierarchical.
How is multiple inheritance achieved in Java?
Through interfaces, not classes.
What does the super keyword do when used inside a subclass constructor?
Calls the superclass constructor; must be first statement.
How can you access an overridden superclass method inside the subclass?
Using super.methodName().
Define compile-time polymorphism.
Polymorphism achieved via method overloading; resolved during compilation.
Give two rules for method overloading.
Methods share a name but differ in parameter number or types; return type alone is insufficient.
Define runtime polymorphism.
Polymorphism via method overriding; call resolved at runtime based on object type.
What must differ when overriding a method?
Method body; signature must be identical, but access cannot be more restrictive.
State one advantage of polymorphism.
Allows the same interface to be used for different underlying forms, enhancing code flexibility.
What is an interface in Java?
An abstract type containing abstract methods and constants; used to specify behavior and achieve multiple inheritance.
Which keyword lets a class promise to use an interface?
implements
Can an interface have constructors?
No.
What modifiers are implicitly applied to interface fields?
public static final
Describe abstraction in Java.
The concept of exposing only essential features while hiding implementation details, achieved via abstract classes/interfaces.
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.
True/False: Abstract classes can have concrete methods.
True.
What keyword prohibits object creation directly from a class?
abstract
Give one advantage of abstraction.
Reduces complexity and improves maintainability by focusing on relevant behavior.
Define encapsulation.
Bundling data (fields) and methods in one unit while restricting external access to implementation details.
Which access modifier is typically used with instance variables to enforce encapsulation?
private
What are getters and setters?
Public methods that read (get) and modify (set) private fields, controlling external access.
Name one benefit of encapsulation related to testing.
Encapsulated code is easier to unit-test due to clear interfaces.
How is a String different from StringBuffer?
String is immutable; StringBuffer is mutable and thread-safe.
Which String method returns its length?
length()
What does equalsIgnoreCase() do?
Compares two strings for equality, ignoring case differences.
Which String method splits a string based on regex?
split()
State one advantage of StringBuffer over String when repeatedly modifying text.
Avoids creating many intermediate objects, thus more memory- and time-efficient.
Constructor signature to build empty StringBuffer with capacity 16.
new StringBuffer()
How do you reverse the contents of a StringBuffer?
Using reverse() method.
What class tokenizes strings based on delimiters?
java.util.StringTokenizer
Which StringTokenizer method checks if tokens remain?
hasMoreTokens()
Name two predefined Java packages automatically available.
java.lang (auto-imported), java.util (must import).
Give one reason to create packages.
Avoid naming conflicts and organize related classes.
What access level allows package-private visibility?
Default (no modifier).
Write the syntax to declare a user-defined package called utils.
package utils;
How do you import all classes from java.io?
import java.io.*;
What is the effect of protected access on inheritance across packages?
Accessible to subclasses even in different packages.
Which keyword lets you define a constant variable inside a class?
final
Explain JIT in Java.
Just-In-Time compiler converts byte-code to machine code at runtime for performance.
What execution sandbox element checks byte-code for security violations?
Bytecode verifier.
Name two Java features that contribute to security.
No pointers (prevents buffer overflow) and sandbox execution environment.
Which primitive data type represents 16-bit Unicode characters?
char
What does the ‘instanceof’ operator test?
Whether an object is an instance of a specific class or interface.
What is method signature in Java?
The combination of method name and parameter list (types/order).
Can static methods be overridden?
No, they can be hidden but not overridden.
What’s the difference between == and equals() for objects?
== compares references; equals() compares logical content (if overridden).
Describe the purpose of final methods.
Prevent subclasses from overriding them.
Which exception is thrown when accessing an array with invalid index?
ArrayIndexOutOfBoundsException
What is autoboxing?
Automatic conversion between primitive types and their wrapper classes.
List two wrapper classes in Java.
Integer, Double (others: Boolean, Character, etc.).
Give an example of a control statement category.
Decision (if/else/switch), Loop (for/while), Branch (break/continue).
How do you create a constant PI in Java?
static final double PI = 3.14159;
Which keyword immediately exits a loop?
break
What does continue do inside a loop?
Skips current iteration and proceeds with the next loop cycle.
Define classpath variable on command line (Windows example).
set CLASSPATH=.;C:\libs\external.jar
Explain purpose of native methods.
Allow Java code to call functions written in other languages (e.g., C/C++).
Name two built-in functional interfaces from java.util.function.
Predicate
Which package contains collection classes like ArrayList?
java.util
What access modifier makes a class visible to all other classes?
public
Is Java pass-by-value or pass-by-reference?
Pass-by-value (object references are passed by value).
Which class is the root of every Java class?
java.lang.Object
What does the hashCode() method represent?
An integer hash value used in hashing-based collections (should align with equals()).