Three real slices of Module 1: the revision notes, the explained Q&A, and the rapid-fire mock. Tap an option on any question — every lesson works like this.
Every question is asked the way an interviewer asks it. Say your answer aloud first, then open the model answer — it also tells you the follow-up and what NOT to say. Try the two below — this is exactly how every lesson in the pack behaves.
Q1 What does this print, and why? 📣 Reported in: TCS, Infosys, Wipro, Capgemini Java rounds
String a = "java";
String b = "java";
String c = new String("java");
System.out.println((a == b) + " " + (a == c) + " " + a.equals(c));
== asks “are these the same object?”. equals() asks “is the text the same?”. a and b are the one shared pooled object, so == is true. new String("java") deliberately makes a second object, so a == c is false — but the text still matches, so equals is true.
Output: true false true
Why: a and b point to the same literal in the string pool, so == is true. new String() creates a separate heap object, so a == c is false. equals is overridden in String to compare contents, so it is true. The lesson: == compares references, equals() compares values — the most asked Java fresher question.
Follow-up: "How do you make a == c true?" → call c = c.intern(), which returns the pooled copy of the same content.
Don’t say: "== compares the text" — that assumes two strings with the same characters are always one object, and it fails the moment a String comes from new, user input or a DB.
Q2 Which OOP principle do private fields with public getters and setters implement? Explain with an example.
Encapsulation is locking the data inside the class and letting people touch it only through your methods. The balance is private, so the only way to change it is withdraw() — and withdraw() can refuse. That is the point: one place to put the rule.
Say this: That is encapsulation. The data and the methods that control it are bundled in one class, and direct access is hidden so validation can live in one place. For example, a BankAccount keeps balance private and exposes withdraw(amount), which checks for insufficient funds before changing it; no other class can set the balance to a negative number.
Follow-up: "How is that different from abstraction?" → abstraction hides implementation (interfaces, abstract classes show what, not how); encapsulation hides data. Be ready with one real example for all four pillars: inheritance reuses via extends; polymorphism is one interface, many forms (overloading at compile time, overriding at runtime).
Don’t say: "It's abstraction" or just "data hiding" with no example — interviewers are checking whether you can connect the word to code you would actually write.
The full pack has revision notes + 125 explained interview questions like these across Core Java & OOP, Collections & Java 8, Multithreading & JVM, Spring Boot & JPA, and SQL & JDBC, 52 mock-interview questions, 30 coding-round programs with clean solutions, and a company-wise module covering what TCS, Infosys, Wipro, Accenture, Capgemini, Cognizant, HCL, Zoho, Amazon and Oracle actually ask — with every answer written out.
Every module gives you two study lessons: a 📖 full-notes lesson that teaches the topic in depth, and a ⚡ cheat sheet like this one for quick revision before the Q&A. Here are the first 3 sections of the Core Java & OOP cheat sheet from Module 1 (Core Java & OOP).
⚡ Cheat sheet · quick revision before the Q&ACore Java rounds are built from a few mechanics: how objects live in memory, how the compiler picks a method, how strings are stored, and how exceptions travel. Learn those and the 25 Q&A will read like revision, not a test.
static, finalthis/superHello.java --javac--> Hello.class (bytecode) --java--> JVM (interprets + JIT-compiles) on any OS
JDK = JRE + compiler/tools JRE = JVM + libraries JVM = runs bytecode
"Write once, run anywhere" = bytecode is platform-independent; the JVM is platform-specific. main is public static void main(String[] args): public so the JVM can call it, static so no object is needed, void because nothing returns to the JVM.
| Primitive | Size | Wrapper | Default (field) |
|---|---|---|---|
| byte / short / int / long | 1 / 2 / 4 / 8 bytes | Byte, Short, Integer, Long | 0 |
| float / double | 4 / 8 | Float, Double | 0.0 |
| char | 2 (Unicode) | Character | '\u0000' |
| boolean | JVM-dependent | Boolean | false |
Integer a = 127, b = 127; a == b // true — Integer cache −128..127
Integer c = 128, d = 128; c == d // false — new objects; use equals()
int x = 5 / 2; // 2 (integer division); 5 / 2.0 = 2.5
long big = 1_000_000 * 1_000_000; // overflow! ints multiplied first -> use 1_000_000L
char ch = 'A' + 1; // 'B' (compile-time constant)
Local variables have no default — using one uninitialised is a compile error. Widening (int → long) is automatic; narrowing (double → int) needs a cast and truncates.
class Account {
private static int count = 0; // shared by all objects (class-level)
private final String id; // must be set once (here or in constructor)
private double balance;
Account(String id) { this.id = id; count++; } // constructor: no return type, same name
Account() { this("TEMP"); } // constructor chaining with this()
static int getCount() { return count; } // static method: no 'this', only static members
}
new allocates on the heap; references live on the stack. Objects with no references become garbage.🔒 7 more sections in the full notes:
+ 2 quick-check interview questions at the end of every study lesson, a ⚡ cheat sheet like this in every module — and a 📖 full-notes lesson that teaches the whole topic in depth before you revise.
After the notes and cheat sheet comes the Q&A lesson — 25 questions asked the way an interviewer asks them, each with a model answer, the follow-up probe and what not to say. Answer aloud first, then open the answer. Here are the first 5 from Module 1.
Q1 Can you explain the difference between JDK, JRE and JVM? 🏢 TCS, Infosys, Wipro
Three boxes, one inside the other. The JVM is the small engine that actually runs your program. The JRE is that engine plus Java’s ready-made libraries — enough to run an app. The JDK is the JRE plus tools like javac — enough to write an app. A developer installs the JDK. Someone who only wants to run the finished app needs the JRE.
Say this: The JVM is the engine that actually runs the bytecode. The JRE is the JVM plus the standard libraries — that is everything you need to run a Java program. The JDK is the JRE plus development tools like javac and the debugger — that is what you need to write Java. So on my laptop I install the JDK; a client machine that only runs the app needs just the JRE. The "write once, run anywhere" promise comes from bytecode being platform-independent, while each OS has its own JVM.
Follow-up: "Who compiles the code — the JVM?" → No, javac in the JDK compiles .java to .class bytecode; the JVM interprets and JIT-compiles that bytecode at runtime.
Follow-up: "Is Java platform-independent or is the JVM?" → The bytecode is platform-independent; the JVM itself is platform-specific.
Don’t say: "They are basically the same thing" or "the JDK runs programs and the JVM compiles" — reversing the roles is the most common fresher mistake.
Q2 Why is main declared as public static void main(String[] args)? What does each word do? 🏢 TCS, Capgemini
Java starts your program by calling main. Each word is there so the JVM is able to call it: public — you are allowed to call me; static — call me without creating an object first; void — I give nothing back; String[] args — a box holding anything typed after the command.
Say this: public so the JVM, which is outside our class, is allowed to call it. static so the JVM can call it without first creating an object of the class — there is no object yet when the program starts. void because it returns nothing to the JVM. And String[] args receives the command-line arguments.
Follow-up: "Can main be written differently in newer Java?" → Java 21+ has preview features for simpler mains (unnamed classes, instance main), but the classic signature is still the standard one (verify exact version status).
Don’t say: "It's just the convention" — the interviewer wants the reason behind each keyword. Also don't claim static is for speed.
Q3 What does this print, and why? 🏢 Wipro, Cognizant
int a = 7, b = 2;
System.out.println(a / b + " " + a % b + " " + (double) a / b);
In Java a whole number divided by a whole number gives a whole number. So 7 / 2 is 3 and the .5 is simply thrown away. Make one side a decimal and you get 3.5.
Output: 3 1 3.5
Why: a / b with two ints is integer division, so 3.5 is truncated to 3. % gives the remainder, 1. In (double) a / b the cast applies to a first, making it 7.0, so the division becomes floating-point and gives 3.5.
Follow-up: "What if I write (double)(a / b)?" → 3.0 — the integer division happens first, then the cast. Cast order matters.
Q4 What does this print, and why? 🏢 Infosys, Capgemini
Integer x = 127, y = 127, p = 128, q = 128;
System.out.println((x == y) + " " + (p == q) + " " + p.equals(q));
Java keeps ready-made Integer objects for the small numbers −128 to 127 and hands out the same one every time. So the two 127s are literally one object; the two 128s are two different objects. == asks “same object?”, equals() asks “same value?”
Output: true false true
Why: Integer caches values from −128 to 127, so x and y point to the same cached object and == is true. 128 is outside the cache, so autoboxing creates two separate objects and == compares references — false. equals compares the value, so it is true.
Follow-up: "So how should wrappers be compared?" → Always with equals(), never ==.
Q5 What is encapsulation, and how is it different from abstraction? 🏢 TCS, Infosys, Wipro
Encapsulation is locking the data inside the class and letting people touch it only through your methods. Abstraction is hiding the messy inside and showing a simple button. Short version: encapsulation hides the data, abstraction hides the working.
Say this: Encapsulation means bundling data together with the methods that operate on it, and restricting direct access to that data — in practice, private fields with public getters and setters. For example a BankAccount keeps balance private and exposes deposit() and withdraw(), so nobody can set a negative balance directly. Abstraction is different: it hides implementation complexity behind a simple interface — you call list.sort() without knowing the algorithm. One line to remember: encapsulation hides data, abstraction hides implementation.
Follow-up: "How do you achieve abstraction in Java?" → Abstract classes and interfaces.
Don’t say: "Encapsulation is hiding implementation behind an interface" — that is the definition of abstraction. The two are confused most often, and interviewers deliberately check for it.
🔒 20 more explained questions in this lesson — and a 25-question Q&A lesson like this in every tech module, plus the company-wise module with every answer written out.
Every module ends with a mock interview — answer each aloud in 30–60 seconds, then check the key points. First 3 of the 12-question Module 1 mock:
Q1 What is the default value of a local int variable that you declare but never initialise?
Good answer hits: Local variables have no default · using one uninitialised is a compile error · instance and static fields do get defaults (0 / false / null) · the difference is a favourite trick question.
One-liner: There is no default — the compiler refuses to compile if you read it before assigning; only fields get 0/false/null.
Q2 What does this print, and why?
System.out.println(1 + 2 + "3" + 4 + 5);
Output: 3345
Why: + is evaluated left to right. 1 + 2 is integer addition = 3. Then 3 + "3" becomes string concatenation "33", and from there every + appends: "334", "3345".
Q3 Which methods cannot be overridden in Java?
Good answer hits: private methods — not visible to the subclass · final methods — explicitly locked · static methods are hidden, not overridden · a same-named private method in a subclass is a brand-new unrelated method.
One-liner: Private and final methods can't be overridden; static methods can only be hidden.
🔒 9 more mock questions in this lesson, and a mock at the end of every module.
Full course
7 modules · 31 lessons · lifetime access
Every module: notes → 25 explained Q&A → mock. Plus the practical round and the company-wise module (TCS, Infosys, Wipro, Accenture…). 7-day money-back guarantee.