module-1
module-1
• Example:
• class Car {
• String color;
• void start() {
• System.out.println("Car is starting");
• }
• }
• Example:
• String str = "Hello, World!";
• System.out.println(str.length());
• System.out.println(str.substring(0, 5));
Constructors
• • Constructor: Initializes a new object.
• • No return type, same name as class.
• Example:
• class Person {
• String name;
• int age;
• Person(String name, int age) {
• this.name = name;
• this.age = age;
• }
• void display() {
• System.out.println(name + " is " + age + " years old.");
• }
• }
• Example:
• class Example {
• int value;
• Example(int value) {
• this.value = value;
• }
• void display() {
• System.out.println("Value: " + this.value);
• }
• }
• Example:
• class Demo {
• @Override
• protected void finalize() throws Throwable {
• System.out.println("Object is being garbage collected");
• }
• public static void main(String[] args) {
• Demo obj = new Demo();
• obj = null;
• System.gc();
• }
• }
Summary
• • Java Architecture: JVM, JRE, JDK
• • JVM Components: Class Loader, Bytecode
Verifier, Execution Engine, Garbage Collector
• • Core Concepts: Classes, Objects, Strings,
Constructors, 'this' keyword, finalize() method
Questions
• Thank you!
• Any questions?
Thank You!