Unit 1 home
CLASS 2 · PART A FIRST JAVA FILE TODAY UNIT I · UI24PC320CS
CLASS 2 · P 1/15PGDN NEXT POINT · PGUP BACK

Part A · Class 2 of 2 · The sealed-box blueprint — and your first Java file

One sealed box.
Facts + operations, together.

Class 1 ended with a promise: keep related facts and the steps that use them in one place, behind one door. Today that idea gets its real names — class and object — and by the end of the hour a main method you typed yourself prints its first line on your own machine.

THIS CLASSC2 · class = blueprint · object = instance · HelloWorld
NEXT CLASSC3 · Scanner, variables & data types — Java learns to listen
STORY SPINEThe flatmates' expense register becomes a sealed box
TOOLINGJDK 21 LTS · Notepad++ · Command Prompt
AFTER THIS CLASS YOU CAN
  • designDraw any real system — the flat register, a library book, a canteen bill — as a sealed box: facts on one side, operations on the other, one door.
  • classifyTell class, object and instance apart without hesitation — the blueprint, the stamped thing, and the word for "stamped from".
  • writeType, compile and run HelloWorld.java on your own laptop — javac then java, no IDE.
  • explainName all five pieces of the main method and say in one line what each is doing there.
WHERE THIS SITS
TODAY, IN ORDER
  • The sealed box — facts + operations kept together
  • class = the blueprintPYQ
  • object = one thing stamped from itPYQ
  • class vs object vs instance — settling the third word
  • Why Java — the two-minute version (full story waits for C7)
  • Install JDK 21 from oracle.com/java
  • Verify: java -version · javac -version
  • Notepad++ menu path: Language, then J, then Java
  • HelloWorld.java — type it, compile it, run itPYQ
  • Anatomy of the main method — five piecesP36-A
  • IS-A vs HAS-A · the generalisation ladder · one type familyPYQ

11 TOPICS · 4 BUILD-UPS · 1 CODE FILE · 1 ACTIVITY · 3 HOMEWORK

PART 2 · THE PICTURE THAT FIXES CLASS 1

Seal the register into one box.

Class 1's register failed because facts lived in four notebooks and the rules lived in four heads. The fix is a single box that holds both — and lets nobody reach inside.

BUILD-UP · THE SEALED BOX, ONE PIECE PER PRESS

ExpenseRegister — one box, one name

FACTS (DATA)

  • owner of the flat fund
  • month = "August"
  • total = ₹18,340

OPERATIONS (METHODS)

  • addExpense(...)
  • getTotal()
  • printSummary()
ONE DOOR — YOU ONLY TALK THROUGH THE OPERATIONS

You don't reach into the box. You knock on the door. ✦

Rohit can no longer scribble in Diya's notebook. If he wants ₹120 of chai added, he must call addExpense(120) — and the box updates its own total, correctly, every single time. That discipline — data and the methods that guard it, sealed together — is the whole of object-oriented thinking. Everything else in this course is detail.

PART 3 · NAMING THE PICTURE

The drawing is the class. The stamped thing is the object.

One box design can serve every flat in Hyderabad. The design is drawn once; real boxes are stamped from it as many times as needed.

BUILD-UP · ONE BLUEPRINT, THREE STAMPS

THE BLUEPRINT · DRAWN ONCE class ExpenseRegister

Says what facts every register holds and what operations every register offers. Holds no rupees itself — a drawing of a box is not a box.

▼  STAMPED FROM THE SAME BLUEPRINT  ▼

kondapurFlat

month: "August"

total: ₹18,340

gachibowliPG

month: "August"

total: ₹9,760

madhapurHostel

month: "July"

total: ₹26,105

Class

THE BLUEPRINT · EXISTS ONCE

A description: which facts, which operations. Written by the programmer, stored in a .java file. It spends no money and holds no month — it only says what registers look like.

Object

THE STAMPED THING · EXISTS MANY TIMES

A real box in memory with its own copies of the facts. kondapurFlat and gachibowliPG came from one blueprint but hold different totals — change one, the other doesn't blink.

And "instance"? Same thing as object — just pointing at its parent. We say kondapurFlat is an instance of ExpenseRegister, the way you'd say "this samosa is an instance of the canteen's samosa recipe". Object emphasises the thing; instance emphasises which class stamped it. One idea, two spotlights.

PUT A NUMBER ON "DRAWN ONCE" — THE BLUEPRINT ECONOMY

Say the register blueprint takes 200 lines of careful code to write, and every flat that adopts it fills in just 2 lines of its own facts (name + month). Compare the two worlds as Hyderabad scales up:

no blueprint: cost = flats × 200  ·  with blueprint: cost = 200 + flats × 2
SCALEFLATSEVERYONE WRITES THEIR OWNONE BLUEPRINT, MANY STAMPS
Our building1010 × 200 = 2,000 lines200 + 20 = 220 lines — 9× less
Kondapur1,0001,000 × 200 = 2,00,000200 + 2,000 = 2,200 — 90× less
All of Hyderabad10,00,00020 crore lines200 + 20 lakh ≈ 20 lakh — 100× less

And the kicker isn't even the typing — it's the FIXING. A bug in the blueprint world is repaired once, in 1 place. In the everyone-writes-their-own world the same bug hides in 10,00,000 places. That single column is why the word "class" exists.

PART 4 · WHY THIS LANGUAGE

Why Java? The two-minute version.

Many languages can draw sealed boxes. We pick Java for three reasons — the full James Gosling story, oak trees and all, waits until Class 7 when you've earned it.

Object-oriented from birth

In Java you cannot write code outside a class. The sealed-box discipline isn't an optional style — the language enforces it on line one of every file.

Sharp edges filed off

No stray pointers, no manual memory freeing, and mistakes are caught at compile time — before your program ever runs, not after it crashes.

Write once, run anywhere

One .class file runs on Windows, Mac and Linux unchanged. We use JDK 21 — the current Long-Term-Support release the industry ships on.

Who made it, and why the coffee cup? That's a genuinely good story — a frustrated team, set-top boxes, and a tree outside a window. It deserves more than a footnote, so it's parked at Class 7, right after your first lab. Hold the question.

PART 5 · TOOL-UP

Five steps and your laptop speaks Java.

Do these at home if the class Wi-Fi sulks. No IDE this semester's start — Notepad++ and the command prompt keep every moving part visible. Step 5 is the fun one: you'll make Java answer you before writing a single file.

1
Download JDK 21

Go to oracle.com/java, open Downloads, pick JDK 21 LTS, then the Windows x64 Installer. Run it, keep clicking Next, accept the default folder.

2
Verify from Command Prompt

Open a new Command Prompt window and ask both tools to introduce themselves:

C:\Users\diya> java -version
java 21.0.4 2024-07-16 LTS
C:\Users\diya> javac -version
javac 21.0.4
3
Install Notepad++ — your editor for Labs 0 and 1

Go to notepad-plus-plus.org/downloads, click the topmost release, and download the Installer, 64-bit x64 for Windows. Run it: keep English, click Next on every wizard screen, accept the default folder C:\Program Files\Notepad++, click Install, then Finish. A green chameleon icon lands in your Start menu — that is the whole install.

4
Point Notepad++ at Java

Open Notepad++, then menu Language, submenu J, click Java. Keywords turn blue, strings turn red — the editor now reads Java with you.

5
Say hello in JShell — your scratchpad

The JDK ships a scratchpad called JShell (the one from Class 0's toolchain): type any Java expression, get the answer instantly — no file, no class, no compile. Try these at home:

C:\Users\diya> jshell
| Welcome to JShell -- Version 21.0.4
jshell> "Hello " + "Diya"
$1 ==> "Hello Diya"
jshell> 7 / 2
$2 ==> 3
jshell> /exit
| Goodbye

Yes — 7 / 2 gave 3, not 3.5. Park that surprise; Class 3 explains it, and Lab 0 examines it.

Both commands must answer.

If java -version works but javac -version says "not recognized", you installed the JRE (runner) without the JDK (builder) — re-run the JDK 21 installer. We need both: javac builds, java runs.

PART 6 · FIRST FILE

HelloWorld.java — eight lines, typed by hand.

Watch it grow one line per press on the left; the command prompt on the right shows exactly what the class will see. Note the brace discipline — every { and every } stands on its own line (Allman style). Type along — do not copy-paste.

MINI PROBLEM · HELLOWORLD.JAVA
PROBLEM
Write and run your very first Java program — one that prints a single greeting line to the command prompt.
REQUIRE­MENTS
  • Class named exactly HelloWorld, saved as HelloWorld.java in class-02 — name and file must match, capital H and W.
  • One main method — the exact eight-line skeleton shown below, Allman braces.
  • One statement inside: print exactly Hello CSE-B!
EXPECTED OUTPUT
Hello CSE-B! — one line, no errors, after javac HelloWorld.java then java HelloWorld.
SAVE AS · EXACT NAME, EXACT FOLDER C:\Users\<you>\Desktop\java-practice\class-02\HelloWorld.java
HelloWorld.java — Notepad++
1// HelloWorld.java — our very first Java file
2public class HelloWorld
3{
4 public static void main(String[] args)
5 {
6 System.out.println("Hello CSE-B!");
7 }
8}
COMMAND PROMPT — WHAT YOU'LL SEE

C:\Users\diya\Desktop\java-practice\class-02> javac HelloWorld.java

C:\Users\diya\Desktop\java-practice\class-02> java HelloWorld

Hello CSE-B!

No errors. One line of output. Your machine just ran a program you wrote. ✦

THE FULL ROUND TRIP — SAVE, COMPILE, RUN

Desktop\java-practice\class-02\ save HelloWorld.java javac HelloWorld.java HelloWorld.class appears java HelloWorld
Java is case-sensitive, everywhere.

helloworld.java is not HelloWorld.java. The public class name must match the file name exactly — one wrong capital and javac refuses politely but firmly. This is the #1 first-week error; earn the habit today.

PART 7 · THE LINE EVERY PROGRAM NEEDS

Anatomy of the main method — five pieces.

Line 4 of HelloWorld is where every Java program begins. Today you name each of its five pieces — each numbered piece maps to the numbered card below it — and hold one honest line about each; three of the five get their full chapters later.

BUILD-UP · ONE PIECE PER PRESS — THE NUMBER ON EACH PIECE POINTS TO ITS MATCHING CARD BELOW

1public 2static 3void 4main 5(String[] args) { ... }
1
public

Visible from outside the box. The JVM lives outside your class — it must be allowed to knock on this door.

FWD C13 · ACCESS MODIFIERS
2
static

Belongs to the blueprint itself, not to any stamped object — so it can run before a single object exists.

FWD C9 · STATIC MEMBERS
3
void

Hands nothing back when it finishes. main does its work and ends — there is nobody above it waiting for a return value.

4
main

The agreed name. The JVM looks for exactly this word — call it Main or start and your program compiles but never begins.

5
String[] args

A tray for words handed in from the command line. Empty today — it starts catching real input very soon.

FWD C3 · INPUT & DATA TYPES

Memorise the music, not just the words: public static void main — String args in a tray. Say it twice. In the exam hall, the five pieces written in order with one line each is a full-mark answer waiting to happen.

PART 8 · YOUR TURN

Activity — finish AboutMe.java.

Diya has typed everything except one statement. Line 8 is yours: print her roll number so the output matches the target card exactly — spacing included. Braces stay Allman — every { and } on its own line.

MINI PROBLEM · ABOUTME.JAVA
PROBLEM
Print a three-line ID card for Diya — name, class, roll number. Lines 1–7 and 9–10 are already typed; line 8 is yours.
REQUIRE­MENTS
  • Class AboutMe, saved as AboutMe.java in class-02.
  • Add exactly ONE statement at line 8: print Roll : 24CS045 — capital R, one space either side of the colon.
  • Match the target card character for character — spacing inside the quotes counts.
EXPECTED OUTPUT
Three lines: Name : Diya · Class: CSE-B · Roll : 24CS045.
SAVE AS · EXACT NAME, EXACT FOLDER C:\Users\<you>\Desktop\java-practice\class-02\AboutMe.java
AboutMe.java — Notepad++
1// AboutMe.java — three facts, three lines
2public class AboutMe
3{
4 public static void main(String[] args)
5 {
6 System.out.println("Name : Diya");
7 System.out.println("Class: CSE-B");
8 // YOUR LINE HERE — print the roll number
9 }
10}

TARGET OUTPUT — MATCH IT EXACTLY

Name : Diya
Class: CSE-B
Roll : 24CS045

RULED NOTEBOOK FIRST — WRITE LINE 8 BY HAND

Write the full statement in your notebook — capitals, dots, quotes, semicolon. Look at line 6 and line 7 for the shape. Then, and only then, unlock the sheet below.

Notebook first — the hand remembers what the eye forgets.

SOLUTION SHEET · LINE 8 ONLY
AboutMe.java — line 8 solved
8 System.out.println("Roll : 24CS045");
// "Roll : " — R capital, one space before and after the colon
FULL RUN

C:\Users\diya\Desktop\java-practice\class-02> java AboutMe

Name : Diya
Class: CSE-B
Roll : 24CS045

Marking yourself? Be strict.

Missing semicolon: the compiler stops you. Wrong spacing inside the quotes: it compiles fine but the output is wrong. Two different kinds of mistake — Java only catches the first kind for you.

PART 9 · HOW BOXES RELATE

IS-A or HAS-A? Ask the sentence.

Boxes don't live alone. Two — and only two — relationships connect them, and plain English already tells you which is which.

IS-A · kind of

A DELIVERY PARTNER IS-A PERSON

Everything true of a person — name, phone number — is automatically true of a delivery partner. The special box inherits everything the general box has, then adds its own.

HAS-A · owns a

A DELIVERY PARTNER HAS-A BIKE

The bike is a separate box kept inside — its own facts (fuel, number plate), its own operations. The partner uses the bike; the partner is not a kind of bike.

The classic exam trap.

"A car IS-A engine" — tempting, wrong. A car HAS-A engine. Say the sentence aloud: if "X is a kind of Y" sounds silly, it's HAS-A. The sentence test scores marks; guessing loses them.

LIGHTNING DRILL — SHOUT THE ANSWER BEFORE THE STAMP LANDS · 6 ROUNDS

Biryani and Dish.

"Biryani is a kind of dish" — sounds right, IS right.

IS-A ✓
Laptop and Battery.

"A laptop is a kind of battery" — silly. The battery is a separate box kept inside.

HAS-A ✓
UPI app and QR scanner.

The app owns and uses a scanner. It is not a kind of scanner.

HAS-A ✓
ElectricScooter and Vehicle.

Every electric scooter is a vehicle — everything true of vehicles comes free.

IS-A ✓
Hostel and Warden.

Trap round — a hostel HAS a warden, and the warden is not "part of the building's kind". Ownership, not kinship.

HAS-A ✓
FoldablePhone and Hinge — careful, we just climbed this ladder…

The ladder said FoldablePhone IS-A Smartphone. But the hinge? "A phone is a kind of hinge" — no. The hinge is a component. Same object, both relationships, different partners.

HAS-A ✓

Score yourself: 6/6 and the sentence test is now a reflex — which is exactly what the 2-mark question wants. Anything less: re-run the drill, it costs 60 seconds.

PART 10 · CLIMBING UP

The generalisation ladder.

Chain IS-A links and a ladder appears. Krish's new folding phone climbs it in two steps — each rung up drops detail and keeps what's shared.

BUILD-UP · CLIMB ONE RUNG PER PRESS (BOTTOM TO TOP)

Gadget

The most general rung in our story — anything with power and a purpose. Above this, one root rules them all (next part).

▲ IS-A · every smartphone is a gadget

Smartphone

Drops the hinge detail; keeps calls, camera, apps — everything all smartphones share.

▲ IS-A · every foldable is a smartphone

FoldablePhone

Krish's actual phone — most specific: it folds, it creases, it cost too much.

▲ UP = GENERALISE · drop detail, keep the shared ▼ DOWN = SPECIALISE · add detail, narrow the kind

SECOND LADDER · DIFFERENT DOMAIN, SAME MOVE — PROVE IT'S A WAY OF SEEING

Dish

Anything the mess can serve — a name, a price, "is it veg?". The drill's round 1 lives here.

▲ IS-A · every biryani is a dish

Biryani

Drops "which meat/veg" detail; keeps what all biryanis share — rice, dum, the fight over raita.

▲ IS-A · every chicken biryani is a biryani

ChickenBiryani

Sunday's actual order — most specific: chicken, extra leg piece, ₹280 at the mess canteen.

▲ GENERALISE: ChickenBiryani, then Biryani, then Dish ▼ SPECIALISE: Dish, then Biryani, then ChickenBiryani

Phones climbed one ladder, food climbs another — the move is identical. Generalisation/specialisation is not a phone trick or a food trick; it is how OOP sees ANY domain. Exam asks "give an example"? You now own two.

PART 11 · THE TOP OF EVERY LADDER

Every class joins one family tree.

Keep climbing any ladder in Java and you always arrive at the same rung. This is a preview — plant the picture, details come with inheritance.

One tree, not many

ExpenseRegister, FoldablePhone, HelloWorld — every class you will ever write hangs somewhere on one shared type hierarchy. No class floats alone.

Object sits at the root

The topmost rung is a built-in class literally named Object — the most general box possible. Say nothing else about your class, and Java still says: it IS-An Object.

Why one root helps

Because every object shares a common ancestor, Java can promise a few abilities to all of them — comparing, describing, storing together. That promise powers half of what's ahead.

PART 12 · HAS-A, SHARPENED

Two kinds of "owns a" — and how boxes actually talk.

The drill stamped six HAS-A verdicts as if they were all the same. They are not. OOP splits "owns a" into two flavours — and there is one destruction test that separates them every time.

AGGREGATION · loose HAS-A Hostel HAS-A Warden

"owns, but does not own the LIFE of"

The warden works at the hostel — but has a family, a house, a life outside it. The hostel merely holds a reference to an independent person.

DESTRUCTION TEST — DEMOLISH THE HOSTEL: The warden SURVIVES ✓ — walks out, joins another hostel. Part can outlive the whole: aggregation.
COMPOSITION · strict HAS-A Hostel HAS-A Room 204

"owns, AND owns the life of"

Room 204 exists only as part of that building. It cannot pack up and join another hostel; the whole creates it and the whole takes it down.

DESTRUCTION TEST — DEMOLISH THE HOSTEL: Room 204 DIES WITH IT ✗ — no building, no room. Part dies with the whole: composition.
The one-line exam answer.

Both are HAS-A. Aggregation: the part can exist without the whole (Hostel–Warden, Laptop–Pendrive, Team–Player). Composition: the part cannot (Hostel–Room, Laptop–Motherboard, Human–Heart). Ask "if I destroy the whole, does the part survive?" — that single question scores the mark.

DESTRUCTION-TEST DRILL · 4 ROUNDS — SHOUT BEFORE THE STAMP

Car and Engine.

Scrap the car — that engine block dies with it (in our design, it was built into the chassis). Whole owns the part's life.

COMPOSITION ✓
Car and Driver.

Scrap the car — the driver walks away and drives another one. Independent life means loose ownership.

AGGREGATION ✓
ExpenseRegister and its pages of entries.

Delete the register — the entries are gone with it. They never existed anywhere else. Our Part-2 box is a composition.

COMPOSITION ✓
ExpenseRegister and the four flatmates.

Delete the register — Diya, Rohit, Krish and Trish are all still very much alive (and still owe money). The register only refers to them.

AGGREGATION ✓

MESSAGE PASSING · HOW SEALED BOXES TALK

If nobody may reach into a box, how does anything happen? Objects send each other messages — a request through the door, never a hand through the wall. Watch one rupee travel through three objects:

ONE PRESS = ONE MESSAGE · ROHIT PAYS THE WIFI BILL

ROHIT (object) register.addExpense("wifi", 799)Rohit doesn't touch the total. He sends a MESSAGE to the register object: method name + the data it needs.
REGISTER (object) total = total + 799 · entries: 5 becomes 6The register updates its OWN facts, its own way — sender never sees the machinery. That's encapsulation and message passing shaking hands.
REGISTER (object) notifier.sendAlert("Rohit added ₹799 — wifi")Objects message objects: the register now asks a THIRD box to inform everyone. A chain of requests, door to door.
NOTIFIER (object) replies: "sent to 4 phones" · register hears "done" · Rohit hears "done"Replies ripple back. Three objects cooperated; not one reached inside another.
ANATOMY OF A MESSAGE: receiver = register method = addExpense arguments = "wifi", 799

Exam line, memorise: message passing = objects communicating by invoking each other's methods — request by name, hand over the data, get a reply. A program is objects passing messages, not lines poking at shared facts.

PART 13 · JUDGING A DESIGN

Cohesion and coupling — the two dials of good design.

You can now build boxes and connect them. But which designs are GOOD? Engineers judge every design with two dials — one measured inside a box, one measured between boxes.

COHESION · inside one box

"DOES EVERYTHING IN HERE BELONG TOGETHER?"

High cohesion = good. ExpenseRegister holds expenses and expense operations — one job, done fully. Now imagine it also stored Rohit's photos and cricket scores: same box, three unrelated jobs — LOW cohesion, a junk drawer.

COUPLING · between boxes

"HOW HARD DOES A CHANGE HERE HIT THE OTHERS?"

Low coupling = good. Rohit knows only the register's door: addExpense(…). If the register's insides change, Rohit's code doesn't. If he depended on HOW the total was stored — TIGHT coupling — every internal change would break him.

The mantra worth two marks: HIGH cohesion, LOW coupling.

Inside a box: tightly related (high cohesion). Between boxes: barely acquainted (low coupling). Students reverse it under exam pressure — anchor it to the flat: the register does ONE job, and flatmates talk to it ONLY through the slot.

PUT A NUMBER ON COUPLING — CLASS-1'S EXPLOSION, ONE LAST TIME

TIGHT coupling: 4 flatmates each read the other 3 notebooks directly.

Every box wired to every other: n(n−1)/2 = 4×3/2 = 6 connections. Change one notebook's format and up to 3 people's routines break. At 100 modules: 4,950 wires — the software crisis table, rediscovered as a COUPLING disaster.

6 WIRES ✗
LOW coupling: 4 flatmates each know ONE door — the register's.

One wire per person: n = 4 connections. Change the register's insides and 0 flatmates break — the door stayed the same. At 100 modules: 100 wires, not 4,950 — a 49× reduction, from one design decision.

4 WIRES ✓

Same series, third appearance — scattered notebooks (Class 1), pair-reconciliation (Class 1), and now coupling. One formula, n(n−1)/2, explains why every OOP rule in this class exists. That is not a coincidence; that is the syllabus.

Your full relationship toolkit, one breath: IS-A (inheritance — biryani is a dish) · HAS-A loose (aggregation — hostel has a warden) · HAS-A strict (composition — hostel has Room 204) · boxes cooperate by message passing (requests through doors) · and you judge the result by high cohesion, low coupling. Five terms, five flat-and-hostel pictures — the whole 2-mark section of Unit 1, done.

SELF-STUDY · READ BEFORE CLASS 3

You already met all four pillars today.

Textbooks open with four grand words. You built each one with your hands this hour — here is the map from today's pictures to tomorrow's vocabulary. Ten minutes, before the next class.

Encapsulation

The sealed box itself — facts and operations together, one door, no reaching in. Part 2 was encapsulation before you knew its name.

Inheritance

The IS-A ladder — FoldablePhone getting everything Smartphone has for free. Chapters of this from Unit II onward.

Polymorphism

One door, many behaviours — printSummary() answering differently for a flat than for a hostel. The most exam-loved word of the four.

Abstraction

The blueprint hiding the wiring — Rohit calls addExpense(120) and never sees how the total updates. Show the door, hide the machinery.

Exam-quotable, one line each — copy these into your notes today: Encapsulation — binding data and the methods that operate on it into a single unit, hiding the data from direct outside access. Inheritance — a mechanism by which one class acquires the fields and methods of another (IS-A). Polymorphism — one interface, many implementations; the same call behaving differently on different objects. Abstraction — exposing only essential features while hiding implementation detail.

Ten-minute self-check before Class 3.

Cover the cards above and answer from memory: ① Which pillar is the sealed box from Part 2? ② Which pillar is the IS-A ladder? ③ printSummary() answering differently for a flat and a hostel — which word? ④ "Show the door, hide the machinery" — which word? If any answer takes more than five seconds, re-read that one card. Class 3 uses all four words without stopping to re-explain them.

PART 15 · BEFORE YOU GO

Your folder, your homework, your next hour.

If your machine matches this tree, today succeeded. Two files you wrote, two files javac made for you.

YOUR FOLDER AFTER THIS CLASS — CHECK BEFORE YOU LEAVE
Desktop\java-practice\class-02\
HelloWorld.java <- you typed this · 8 Allman lines
HelloWorld.class <- javac made it · never edit it
AboutMe.java <- activity · line 8 is yours
AboutMe.class <- proof it compiled

HOMEWORK · DUE BEFORE CLASS 3

1 Write & run ThreeLines.java

Three println lines about your day — any three facts. Full round trip: save, javac, java. Bring the output on your phone camera if it worked, the error message if it didn't. Both are welcome.

2 Paper blueprint: LibraryBook

No code — ruled notebook only. Draw the sealed box for a library book: at least 3 facts, at least 3 operations, one door. Ask yourself: who is allowed to change dueDate?

3 Read the four-pillars preview

Part 12 above, ten minutes. Class 3 opens by asking which pillar the sealed box belongs to — first correct hand skips the warm-up question.

Homework 1 and 2 solved below — your own run/sketch first, then compare.

HOMEWORK SOLUTIONS · HW 1 CODE + HW 2 BLUEPRINT
ThreeLines.java — one model answer (your three facts may differ)
1public class ThreeLines
2{
3 public static void main(String[] args)
4 {
5 System.out.println("Woke up at 6 for the bus.");
6 System.out.println("Mess served upma again.");
7 System.out.println("Compiled my first Java file!");
8 }
9}
THE FULL ROUND TRIP

C:\Users\diya\Desktop\java-practice\class-02> javac ThreeLines.java

C:\Users\diya\Desktop\java-practice\class-02> java ThreeLines

Woke up at 6 for the bus.

Mess served upma again.

Compiled my first Java file!

Silence after javac = success. Your three facts will differ — the shape must not: class name matches the filename, Allman braces, semicolon on every println.

HW 2 · LibraryBook blueprint — the model sketch. One sealed box labelled LibraryBook. FACTS inside: title, borrowerName, dueDate (3 minimum — ISBN, shelfCode also fine). OPERATIONS on the wall: borrow(), returnBook(), extendDueDate(). One DOOR through which every request passes.

The question that carried the mark: who may change dueDate?

Only the box itself, through extendDueDate() — never outside code reaching in. If your sketch lets anyone scribble on dueDate directly, the box isn't sealed; that one sentence is exactly the pillar Class 3's warm-up asks about.