JAVA INTRODUCTION 12 th scvience points .pptx

suryasarath2308 0 views 28 slides Oct 10, 2025
Slide 1
Slide 1 of 28
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28

About This Presentation

JAVA INTRODUCTION 12 th scvience poin


Slide Content

JAVA INTRODUCTION Object-Oriented : Java is an object-oriented programming language, meaning it focuses on objects and classes to organize code . Platform Independent : Java follows the "Write Once, Run Anywhere" philosophy. Code written in Java can run on any platform that has a Java Virtual Machine (JVM ). Simplicity : Java is designed to be easy to use and accessible. It’s more straightforward than languages like C++ by removing some complex features like pointers . Robust : Java has strong memory management and exception handling, reducing the chances of errors and improving stability . Multithreading : Java supports multithreading, which allows the execution of multiple tasks simultaneously, enhancing performance . Security : Java provides several layers of security, such as bytecode verification and the Java sandbox model, which makes it safe to run untrusted code.

Terminology: 1. JDK 2. JRE 3. JVM JDK : Java Development Kit If run any applications we need JDK have to installed JDK versions: 1.0 to 1.9 Mostly V1.8 is used now JRE: Java Runtime Environment It is a pre-defined. class files (i.e.) library files JVM: Java Virtual Machine It is mainly used to allocate the memory and compiling

OOPS CONCEPT Object Oriented Programing Structure OOPS is a method of implementation in which programs are organized as collection of objects, class and methods Oops principles are Class Method Object Abstraction Encapsulation Inheritance Polymorphism

CLASS Class is nothing but collection of methods or collection of objects. Project name : Should be in Pascal notation Pascal notation : Each word of the first letter should be in capital src - Source file Class name: Pascal notation Package creation: ex, org.cts.scope -All small letters Syntax: (First type class name and click ctrl +space) public class Bank { } // Bank is a class name

METHOD: Set of action to be performed Method name: camel notation Camel notation: First word should be small after every word of the first letter should be capital Syntax: public void dummy() { // Here dummy is a method name } Main Method: public static void main(String[] args ) { } Main method type main and click ctrl +space

OBJECT Run time memory allocation Using object we call the any methods Syntax: (Class name) (Object name) =new (Class name) (); Alignment-> ctrl + shift+ F Run -> ctrl +F11

Example program : 1. StudentDatabase public class StudentInfo { public void Studentname () { System.out.println (" Name:Vengat "); } public void studentList () { System.out.println (); } public void StudentMark () { System.out.println ("Mark:1005"); } public void StudentAddress () { System.out.println ("Address: Chennai"); }

Object Creation public static void main(String[] arg ) { StudentInfo info = new StudentInfo (); info.Studentname (); info.StudentMark (); Heap Memory: Object are stored in heap memory To reduce object memory we go for inheritance

INHERITANCE We can access one class property into another class using 'extend' keyword and reusable purpose Child class-> Sub class Parent class-> Super class There are 5 types of Inheritance Single Inheritance Multilevel Inheritance Multiple Inheritances Hybrid Inheritance Hierarchical Inheritance

Single inheritance Single inheritance means that a subclass inherits from only one superclass. It allows a subclass to use the methods and properties of its parent class. class Parent { void show() { System.out.println ("Parent class method."); } } class Child extends Parent { void display() { System.out.println ("Child class method."); } }

Multilevel inheritance Multilevel inheritance occurs when a class inherits from a class, which in turn inherits from another class class Grandparent { void show() { System.out.println ("Grandparent class method."); } } class Parent extends Grandparent { void display() { System.out.println ("Parent class method."); } } class Child extends Parent { void print() { System.out.println ("Child class method."); } }

Multiple inheritance Java does not support multiple inheritance through classes to avoid ambiguity and conflicts caused by the diamond problem.Java allows multiple inheritance using interfaces. A class can implement multiple interfaces to achieve multiple inheritance . interface A { void methodA (); } interface B { void methodB (); } class C implements A, B { public void methodA () { System.out.println ("Method A from Interface A"); } public void methodB () { System.out.println ("Method B from Interface B"); } }

Hybrid inheritance Hybrid inheritance is a combination of two or more types of inheritance (single, multilevel, multiple) in a single program . interface A { void methodA (); } interface B { void methodB (); } class C implements A { public void methodA () { System.out.println ("Method A from Interface A"); } } class D extends C implements B { public void methodB () { System.out.println ("Method B from Interface B"); } }

Hierarchical inheritance Hierarchical inheritance occurs when multiple child classes inherit from a single parent class class Parent { void show() { System.out.println ("Parent class method."); } } class Child1 extends Parent { void display1() { System.out.println ("Child1 class method."); } } class Child2 extends Parent { void display2() { System.out.println ("Child2 class method."); } }

POLYMORPHISM Poly-many Taking more than one forms is called polymorphism It has 2 types , Method overloading(static binding/compile time polymorphism) Method overriding(dynamic binding/run time polymorphism)

Method overloading Method Overloading in Java is a concept where multiple methods with the same name can exist within a class, but they must differ in the number or type of parameters. It allows you to perform similar tasks with different input values or arguments . Key Points about Method Overloading : Methods must have the same name . Methods must have different parameter lists (either in number or type of parameters ). Return type can be different but it doesn't play a role in overloading . It increases code readability by allowing you to use the same method name for different actions.

Example Program Example Program: public class StudentInfo { private void studentId ( int num ) { } private void studentId (String name) { \\ depends on order } private void studentId (String email, int ph ) { \\depends on data type } private void studentId ( int dob, String add) { \\depends on datatype count } public static void main(String[] arg ) { StudentInfo info = new StudentInfo (); } } In the same method the argument can't use int and byte because int &byte both are numbers. so it doesn't work. public void employeeID ( int num , byte num2) is not correct

Method overriding Method Overriding in Java occurs when a subclass provides a specific implementation for a method that is already defined in its superclass. The method in the subclass must have the same name, return type, and parameters as the method in the superclass . Key Points about Method Overriding : The method in the subclass must have the same signature (name, return type, and parameters) as the method in the superclass . The method in the subclass replaces the method in the superclass when it is called using an object of the subclass . Method overriding is used to achieve runtime polymorphism (dynamic method dispatch).

Example Program // Superclass class Animal { void sound() { System.out.println ("Animal makes a sound"); } } // Subclass class Dog extends Animal { @Override void sound() { System.out.println ("Dog barks"); } } public class Main { public static void main(String[] args ) { Animal myDog = new Dog(); // Parent class reference, Child class object myDog.sound (); // Calls overridden method in Dog class } }

ABSTRACTION Hiding the implementation part is called abstraction It has 2 types, 1.Partially abstraction(abstract class) 2.Fully abstraction(interface) 1.Partially Abstraction(Abstract class): It will support abstract method and non-abstract method. We can’t create object for abstract class because in the method signature we didn't mention any business logic. In abstract method, we only mention abstract signature, won't create business logic It have 2 class, abstract class(sub class) and super class. we create object and business logic only in super class, won't create in abstract class

Example Program // Abstract class abstract class Animal { // Abstract method (no implementation) abstract void sound(); } // Subclass (Concrete class) class Dog extends Animal { // Providing implementation of abstract method void sound() { System.out.println ("Dog barks"); } } public class Main { public static void main(String[] args ) { Animal myDog = new Dog(); // Creating object of Dog class myDog.sound (); // Calls the sound method of Dog } }

Encapsulation Encapsulation is the process of wrapping data (variables) and code (methods) together as a single unit. It restricts direct access to the data and provides control using getters and setters . Benefits of Encapsulation: ✅ Better data control and security ✅ Flexibility to modify logic without affecting external code ✅ Easy to maintain and extend

Example Program class Person { private String name; // Private variable // Setter method public void setName (String name) { this.name = name; } // Getter method public String getName () { return name; } } public class Main { public static void main(String[] args ) { Person p = new Person(); p.setName ("John"); // Set value System.out.println ( p.getName ()); // Get value } }

Types of Variables in Java Java has three types of variables : Local Variable Instance Variable Static(Class) Variable

Local Variable Declared inside a method, constructor, or block Scope is limited to the block where it's defined . No default value – must be initialized before public class Main { public void display() { int num = 10; // Local variable System.out.println ("Local variable: " + num ); } }

Instance Variable Declared inside a class but outside a method . Created when the object is created and destroyed when the object is destroyed . Default values are: for int , null for objects, false for boolean . public class Main { int age = 25; // Instance variable public void display() { System.out.println ("Instance variable: " + age); } }

Static (Class) Variable Declared with the static keyword inside a class but outside any method . Shared by all objects of the class . Created when the class is loaded and destroyed when the class is unloaded public class Main { static int count = 0; // Static variable public void increment() { count++; } }

Scope of Variable Type Scope Default Value Keyword Local Inside method No None Instance Inside class Yes None Static Inside class Yes static