/
Java Fundamentals
Save to my account
Sign up
Java Fundamentals
Java Fundamentals
Study
1
Question
What is Java primarily described as in terms of its typing, orientation, and platform independence?
Page 2
Answer
Java is a strongly typed, object-oriented, platform-independent language compiled to bytecode.
2
Question
Describe the complete compilation and execution process of a Java program from source code.
Page 2
Answer
Source (.java) → javac compiler → Bytecode (.class) → JVM interprets/JIT compiles → Machine code.
3
Question
What components are included in the Java Development Kit (JDK)?
Page 2
Answer
JDK includes compiler (javac), debugger, javadoc, and JRE for developers.
4
Question
What does the Java Runtime Environment (JRE) provide for running Java programs?
Page 2
Answer
JRE provides JVM plus standard libraries for running programs.
5
Question
How does the Java Virtual Machine (JVM) execute bytecode and ensure platform neutrality?
Page 2
Answer
JVM executes bytecode and is platform-specific, but bytecode remains platform-neutral.
6
Question
What role does the Just-In-Time (JIT) Compiler play in JVM performance?
Page 2
Answer
JIT compiles hot bytecode to native machine code at runtime for speed.
7
Question
What are the hierarchical classloaders in Java and their order?
Page 2
Answer
Bootstrap → Extension → Application classloaders load .class files into JVM.
8
Question
What is bytecode in the context of Java compilation?
Page 2
Answer
Bytecode is intermediate, platform-independent code, neither machine code nor source code.
9
Question
Why does 'Write Once Run Anywhere' refer specifically to bytecode in Java?
Page 2
Answer
Bytecode is platform-independent; JVM is platform-dependent for different OS like Windows/Linux.
10
Question
What is the size and range of the byte primitive data type in Java?
Page 2
Answer
Byte is 1 byte, range -128 to 127.
11
Question
What are the size and range limits for the short primitive type in Java?
Page 2
Answer
Short is 2 bytes, range -32,768 to 32,767.
12
Question
Specify the size and range of the int primitive data type in Java.
Page 2
Answer
Int is 4 bytes, range -2³¹ to 2³¹-1.
13
Question
How do you denote a long literal in Java, and what is its size?
Page 2
Answer
Long is 8 bytes; use suffix L like 100L.
14
Question
What suffix is required for float literals in Java, and what is its precision?
Page 2
Answer
Float is 4 bytes, single precision; use suffix F.
15
Question
What is the default floating-point type in Java and its size?
Page 2
Answer
Double is 8 bytes, double precision; default for decimals.
16
Question
How does the char primitive differ from C in terms of size and encoding in Java?
Page 2
Answer
Char is 2 bytes, Unicode (0 to 65535); unlike C's 1 byte.
17
Question
What values can the boolean primitive hold, and what is its conceptual size?
Page 2
Answer
Boolean is true/false; size JVM-dependent, conceptually 1 bit.
18
Question
Name all the wrapper classes for Java primitive types.
Page 2
Answer
Integer, Long, Double, Float, Character, Boolean, Byte, Short.
19
Question
What is autoboxing in Java, and provide an example of its behavior?
Page 3
Answer
Autoboxing converts int to Integer automatically; unboxing reverses it.
20
Question
Explain Integer caching in Java with specific range and example outcomes.
Page 3
Answer
Java caches Integers from -128 to 127; a=127; b=127; a==b true, but 128 false.
21
Question
What are widening and narrowing type casts in Java, including safety implications?
Page 3
Answer
Widening: implicit, safe (int→long); Narrowing: explicit, may lose data (double→int).
22
Question
What is the result of adding two char primitives in Java, and how to concatenate instead?
Page 3
Answer
'A' + 'B' = 131 (int); use String.valueOf() or empty string for concatenation.
23
Question
Where are String literals stored in Java, and what happens on reassignment?
Page 3
Answer
Strings immutable, stored in String Constant Pool (SCP) in heap; String s="hello" checks/reuses SCP.
24
Question
How does new String("hello") differ from String s = "hello" in terms of object creation?
Page 3
Answer
new String("hello") always creates new heap object, bypassing SCP; literal reuses SCP if exists.
25
Question
What does the intern() method do for String objects in Java?
Page 3
Answer
intern() forces a String object to use the SCP version.
26
Question
Compare the properties of String, StringBuffer, and StringBuilder classes.
Page 3
Answer
String: immutable, thread-safe, SCP, new object per mod. StringBuffer: mutable, synchronized/thread-safe, slower. StringBuilder: mutable, not thread-safe, faster.
27
Question
List key String methods for manipulation, case conversion, searching, and splitting.
Page 3
Answer
length(), charAt(i), substring(start,end), indexOf(), lastIndexOf(), replace(), toUpperCase(), toLowerCase(), trim(), split(), equals(), equalsIgnoreCase(), compareTo(), contains(), startsWith(), endsWith(), isEmpty(), toCharArray().
28
Question
What is String.format used for, and provide its syntax example?
Page 3
Answer
String.format("%d %s", num, str) creates formatted strings.
29
Question
Why should you prefer StringBuilder over + for string concatenation in loops?
Page 3
Answer
+ creates new String objects each time; StringBuilder mutable avoids this.
30
Question
Why is "hello".equals(s) safer than s.equals("hello") for null safety?
Page 3
Answer
Avoids NullPointerException if s is null; always put known value first.