0% found this document useful (0 votes)
3 views2 pages

Java Fundamentals Cheat Sheet Guide

This cheat sheet covers fundamental concepts in Java including variables, data types, operators, conditional statements, loops, user-defined functions, arrays, strings, wrapper classes, getters and setters, threads, and error handling. Key distinctions such as the difference between == and .equals(), while and do-while loops, and the immutability of strings are highlighted. It serves as a quick reference for essential Java programming knowledge.

Uploaded by

kala22858
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Java Fundamentals Cheat Sheet Guide

This cheat sheet covers fundamental concepts in Java including variables, data types, operators, conditional statements, loops, user-defined functions, arrays, strings, wrapper classes, getters and setters, threads, and error handling. Key distinctions such as the difference between == and .equals(), while and do-while loops, and the immutability of strings are highlighted. It serves as a quick reference for essential Java programming knowledge.

Uploaded by

kala22858
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Java Fundamentals - Viva Cheat Sheet

Variables
Q: What is a variable?
A: A variable is a named memory location that stores a value.
Q: Types of variables?
A: Local, Instance, Static.

Data Types
Q: How many primitive data types in Java?
A: 8 → byte, short, int, long, float, double, char, boolean.
Q: Size of int?
A: 4 bytes.

Operators
Q: Difference between == and .equals()?
A: == compares references, .equals() compares values.
Q: Pre-increment vs post-increment?
A: ++i increments before use, i++ increments after use.

Conditional Statements
Q: Difference between if-else and switch?
A: if-else handles ranges/conditions, switch works with fixed values.
Q: Can we use strings in switch?
A: Yes, from Java 7 onwards.

Loops
Q: Difference between while and do-while?
A: while checks before execution, do-while executes at least once.
Q: What is enhanced for loop?
A: A loop for iterating collections/arrays without index.

User Defined Functions


Q: What is method overloading?
A: Same method name, different parameter list.
Q: Can methods return objects?
A: Yes.
Arrays
Q: Default value of int array elements?
A: 0.
Q: Can array size be changed after creation?
A: No, arrays are fixed size.

Strings
Q: Why are strings immutable?
A: For security, caching, and thread-safety.
Q: Difference between String and StringBuilder?
A: String is immutable, StringBuilder is mutable.

Wrapper Classes
Q: What is autoboxing?
A: Automatic conversion of primitive → wrapper.
Q: Example of wrapper class?
A: Integer, Double, Boolean, etc.

Getter & Setter


Q: What is a getter?
A: Method to access private variable.
Q: Why use them?
A: To achieve encapsulation.

Threads
Q: Two ways to create a thread?
A: Extend Thread class, implement Runnable interface.
Q: Difference between start() and run()?
A: start() creates a new thread, run() runs in the same thread.

Errors
Q: Error vs Exception?
A: Error = serious, not recoverable; Exception = can be handled.
Q: Example of checked exception?
A: IOException.

You might also like