0% found this document useful (0 votes)
2 views7 pages

Day 13 Java Notes

Uploaded by

yuugin123
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)
2 views7 pages

Day 13 Java Notes

Uploaded by

yuugin123
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 DAY 13 – COMPLETE NOTES

📌 1. Scanner Class & Input Buffer Mechanism


1.1 Scanner Object Creation

Scanner sc = new Scanner([Link]);

Your sir explained that:

[Link] is a static global variable.


It holds the input buffer file.
Scanner uses that file to read user input.

Meaning of [Link]

“Hey buddy, take the input from this buffer file.”


Buffer file contains what the user typed.
Stored as string (e.g., "50\n" ).

Why is [Link] static?

Because:

Static = global ⇒ accessible everywhere


Local variables cannot be accessed outside method
Since Scanner needs to access system input globally → it must be static

⭐ 📌 2. Fully Qualified Name


Your sir said:

[Link]
→ package name + class name = fully qualified name.

Scanner uses this internal path when working with [Link].

⭐ 📌 3. How Scanner Works Internally


Your sir described the exact meaning:

1. User types something.


2. Goes into Input Buffer (string).
3. Stored in [Link] .
4. Scanner reads that file.
5. Converts it internally to required type (int/double/etc).

Diagram (as per transcript)

Keyboard → Input Buffer → Binary → [Link] → Scanner → nextInt()

⭐ 📌 4. Printing Scanner Object


If you print:

[Link](sc);

Output:

[Link]@<address>

This is the address of the Scanner object.

⭐ 📌 5. Why Multiple Scanner Objects Show


SAME Address?

Your sir explained:


Even if you create many scanner objects:

Scanner sc1 = new Scanner([Link]);


Scanner sc2 = new Scanner([Link]);

They reuse the same [Link] file.

So the reference to buffer file is the same.

But object is still “another object”.

Reason:

Scanner is an inbuilt class with a feature — if the input source ([Link]) is the same, it points
to the same memory to save resources.

⭐ 📌 6. Why Student Objects Show


DIFFERENT Addresses
Your sir compared with Scanner:

Student s1 = new Student();


Student s2 = new Student();

Each uses new , so each gets a new memory location.


Example analogy he gave:

Two friends live in same colony (package), same street (class), same building maybe, but
different houses (object address).

So:

Same class
But new keyword always creates NEW OBJECT & NEW ADDRESS.

⭐ 📌 7. Using Scanner to Take Dynamic Input


Your sir took 3 subject marks dynamically:
int s1 = [Link]();
int s2 = [Link]();
int s3 = [Link]();

Meaning of nextInt()

Internally it is like:

int nextInt() {
// reading from buffer
// converting to integer
return integer_value;
}

It returns int → so we can store it.

⭐ 📌 8. Internal Design of nextInt() (Exactly


What Sir Said)
nextInt() is inside Scanner class.
Written internally as:

public int nextInt() {


// read input buffer (string)
// convert to int (typecasting/parsing)
// return the integer
}

Must be public so other packages can access it.

⭐ 📌 9. Student Class (As per Transcript


Explanation)
Your sir’s exact structure:

class Student {

float sem1(int s1, int s2, int s3) {


float total = s1 + s2 + s3;
float avg = total / 3;
return avg; // result returned back to driver class
}
}

Notes:

Method calculates total & average.


Returns average → returned value is stored in driver class.

⭐ 📌 10. Driver Class (Execution Class)


Sir explained:

Driver class = a class that travels to every other class, takes methods, runs them.

Exactly how he wrote:

class Driver {
public static void main(String[] args) {

Scanner sc = new Scanner([Link]);

[Link]("Enter Name:");
String name = [Link]();

[Link]("Enter ID:");
int id = [Link]();

[Link]("Enter Subject Marks:");


int s1 = [Link]();
int s2 = [Link]();
int s3 = [Link]();

Student obj = new Student();


float result = obj.sem1(s1, s2, s3);

[Link]("Average = " + result);


}
}

⭐ 📌 11. Control Flow Between Classes


Sir explained the exact movement:

1. Execution starts in Driver main()


2. main() calls Student.sem1()
3. Control jumps to Student class method
4. Calculates average
5. Returns result back to Driver
6. Driver prints result

⭐ 📌 12. Pass/Fail Using Ternary Operator


(What Sir Demonstrated)

char grade = (result >= 35) ? 'P' : 'F';

If avg ≥ 35 ⇒ Pass
Else ⇒ Fail

Based only on transcript.

⭐ 📌 13. Summary of Key Concepts from Day


13

Concept Explanation (from transcript)

[Link] Static global variable holding input buffer


Concept Explanation (from transcript)

Scanner Takes the input buffer and processes it

nextInt() Reads string → converts → returns int

Object printing Prints memory address

Scanner same address Because same [Link] file reused

Student object new address new keyword always makes new memory

Ternary operator Used for Pass/Fail

Driver Class Execution class controlling program flow

You might also like