JAVA By, RAJKIRAN EDUNURI B.Tech Computer Science, Guru Nanak - - PowerPoint PPT Presentation

java
SMART_READER_LITE
LIVE PREVIEW

JAVA By, RAJKIRAN EDUNURI B.Tech Computer Science, Guru Nanak - - PowerPoint PPT Presentation

JAVA By, RAJKIRAN EDUNURI B.Tech Computer Science, Guru Nanak Institutions,Hyderabad e- mail : rajkiranedunuri97@gmail.com Website : rockzzweb.wordpress.com JAVA What is JAVA Why Java has Become More Popular *** Java is Case Sensitive


slide-1
SLIDE 1

JAVA

By, RAJKIRAN EDUNURI B.Tech Computer Science, Guru Nanak Institutions,Hyderabad

e-mail : rajkiranedunuri97@gmail.com

Website : rockzzweb.wordpress.com

slide-2
SLIDE 2

JAVA

What is JAVA Why Java has Become More Popular

*** Java is Case Sensitive language

slide-3
SLIDE 3

What is JAVA

Simply, JAVA is an “OBJECT ORIENTED PROGRAMMING LANGUAGE”

slide-4
SLIDE 4

What is OBJECT ORIENTED PROGRAMMING (OOPS)

  • Object Oriented Programming is a programming

method that combines :

  • A) Data
  • B) Instructions For processing that data into a

self-sufficient ‘Object’ that can be used within a program or in other programs..

(Important for interviews)

slide-5
SLIDE 5

CONCEPTS IN OBJECT ORIENTED PROGRAMMING..

  • Classes
  • Objects
  • Abstraction
  • Inheritance
  • Polymorphism
  • Encapsulation
  • This Concepts Make The Java An “ OOP Language..”
slide-6
SLIDE 6

Why Should i learn OOPS

  • OOPS Make Development and maintenance

Easy..

  • OOPS Provides Data Hiding
  • OOPS Provide Ability to Simulate Real-World

event much more Efficiently.

slide-7
SLIDE 7

Java Editor or IDE’S

  • ECLIPSE
  • NETBEANS
  • TEXT EDIT, J-EDIT. -> FOR MAC Operating

System..

  • Notepad/ wordpad, Notepad++ For Windows

platform

slide-8
SLIDE 8

class class_name { public static void main (String [ ] args ) { // Statement 1; // Statement 2; } }

Structure of Java program

Java is Case Sensitive language

slide-9
SLIDE 9

Simple Java Hello World Program

public class hello_world { public static void main (String[ ] args) { System.out.println(“ HELLO WORLD ”); } }

Output : HELLO WORLD

Save Above program with “ hello_world.java “ without Quotes

slide-10
SLIDE 10

Explanation of Previous program

  • As you Know that The O/P of Above program is “ HELLO WORLD”
  • Public -> Access Modifier, If we declare any method/variable or any

class as public, it means that we can access that method/class anywhere in the program…

  • Class -> collection of methods, variables, constructors, etc.. ( in

java we write any method/any logic inside the class )

  • hello_world -> name of the class…
  • Public static void main (String [ ] args ) -> Main method
  • System.out.println( ) -> used to print Any text,Values etc on Screen..
slide-11
SLIDE 11

What is a METHOD…???

  • In general, method is nothing but a Function..
  • Block of statements written in a Separate prototype..
  • Syntax :
  • Data_type method_name() {


Statement1;
 Statement2;
 }

  • Example : void abstraction () {


statement1;
 statement2;
 }

slide-12
SLIDE 12

CLASS

  • Simply, Collection of methods, variables, constructors, etc.. is

called CLASS

  • In java, we write any method/constructor, variables etc inside of the

class..

  • Syntax :
  • class class_name {
  • Ex : class hello_world {
  • NOTE : In java, Main class (sub class) name & file name should be

same, else it will throw an exception that “ Class names Not matched”…

slide-13
SLIDE 13

OBJECTS

  • Simply, Object is an Bundle of Related Variables and

Methods

  • Objects are used to Access methods , variables,

constructors Present inside a class , in other class…

  • Syntax :
  • class_name object_name = new class_name();
slide-14
SLIDE 14

Program to understand concept of Objects

class my_bio { /* Writing method */ /* method is nothing but a function to perform some operation */ void bio_data () { /* Creating method */ String name=“shashi”; String college=“Malla Reddy Institute of technology”; int age=20; System.out.println(“Name : ”+name); System.out.println(“ College : ”+college); System.out.println(“Age : ” +age); } public static void main (String [] args ) { my_bio ob =new my_bio(); /* Created Object to access method */

  • b.bio_data(); /* calling method using object */

} }

Save Above with “ my_bio.java ”

slide-15
SLIDE 15

Output : Name : shashi college : Malla Reddy Institute of technology Age : 20

  • In the Previous Program, we have created a class and

inside the class we have written Some code to the method ( public void bio_data () )

  • Then, we have written main method, created object

( ob ) to class (my_bio) and Called method using “

  • bject_name.method_name(); ”

which Results the Above Output..

slide-16
SLIDE 16

ABSTRACTION

  • Abstraction in the sense, “ HIDING THE DATA ”
  • It Allows us to Hide Some Data and Reveal only

Required data..

  • In Some cases, user want only some data from a

large data..

  • In that cases, Abstraction Becomes handy…
slide-17
SLIDE 17

Program tp Understand concept of ABSTRACTION

class Abstraction { Public static void main(String [ ] args ) { String name=“Shashi”; String college=“Malla Reddy Institute of Technology”; int age=20; String address=“HYDERABAD”; System.out.println(“Name : ”+name); System.out.println(“College : ”+college); System.out.println(“Address : ”+ address); } }

Save Above Program with “ Abstraction.java ”

slide-18
SLIDE 18

OUTPUT :

Name: Shashi College : Malla Reddy Institute of Technology Address : HYDERABAD

  • In the Previous Program, we have declared 4

instances variables ( name, college, age,Address)

  • But we have printed only

Name,College,Address ,but not Age

  • As i require only name,address,college, i

displayed them and hid the Age variable..

  • This Process is called ABSTRACTION…
slide-19
SLIDE 19
  • Performing Different Operation On Different

methods but with same Method Name..

  • Simply, we can say that the “METHOD NAMES

WILL BE SAME BUT OPERATIONS PERFORMED ON METHOD WILL BE DIFFERENT ”

POLYMORPHISM

slide-20
SLIDE 20

Program to Understand Polymorphism

class polymorphism { void calculate(int x) { return sqrt(x); } void calculate(int x) { return (x*x); } Public static void main(String [ ] args ) { Polymorphism ob =new polymorphism(); System.out.println(“Square Root is : ”+ob.calculate(25)); System.out.println(“Square of x is : ”+ob.calculate(2)); } }

Save Above with “ polymorphism.java ”

slide-21
SLIDE 21

Output : Square Root is 5 Square is 4

  • In the previous program, we have created class

(polymorphism) and created 2 methods (calculate) with Same name but operations performed on them was Different..

  • In first method calculate, we performed Square

Root of a number..

  • In Second Method calculate, we performed

Squaring of a number..

slide-22
SLIDE 22

ENCAPSULATION

  • Simply, 


Process of Binding The Data of variables

  • r methods is called ENCAPSULATION
  • In Encapsulation, Names of variables will be

same, but values of them will be different..

slide-23
SLIDE 23

Program to Understand ENCAPSULATION

class a { /* Super Class 1 */ String name=“Shashi”; String college=“Malla Reddy Institute of Technology”; void method1(){ System.out.println(“Name : ”+name); System.out.println(“College : ”+college); } } class b { /* Super class 2 */ String name=“Rajkiran”; String college=“Guru Nanak Institutions”; void method2() { System.out.println(“Name : ”+name); System.out.println(“College : ”+college); } } class encapsulation { /* Sub class */ public static void main(String [ ] args ) { a ob1=new a(); b ob2=new b();

  • b1.method1();
  • b2.method2();

} }

Save with “ encapuslation.java ” as main method is present in sub class

slide-24
SLIDE 24

Output : 
 Name : shashi College : Malla Reddy Institute of Technology Name : Rajkiran College : Guru Nanak Institutions

  • In The Previous Program, we have Declared 3

classes ( 2 super and 1 sub class) Created 1 method in each Super class (variable names are same, but values of them are Different..)

  • we have called the methods using objects in sub

class, which results above output…

slide-25
SLIDE 25

INHERITANCE

  • The Process by which one class acquires the

properties of another class…

  • Simply,In Inheritance, we can use the properties
  • ne class in some other class or more than one

class

  • Keyword : “ extends ”

( Important )

slide-26
SLIDE 26

Program to understand INHERITANCE

class a { void method1() { /* creating a method */ String name=“Shashi”; String college=“Malla Reddy Institute of Technology”; System.out.println(“Name : ”+name); System.out.println(“College : ”+college); } } class b extends a { void method2() { /* creating a method */ String name=“Rajkiran”; String college=“Guru Nanak Institutions”; System.out.println(“Name : ”+name); System.out.println(“College : ”+college); } } class inheritance { public static void main(String [ ] args ) { a ob1=new a(); /* Object to class a */ b ob2=new ob2(); /* Object to class b */

  • b1.method1();
  • b2.method2();
  • b2.method1(); /* calling method1 which is present in class a with ob2 */

} }

Save code with “ inheritance.java ”

slide-27
SLIDE 27

Output

Name : Shashi College : Malla Reddy Institute of Technology Name : Rajkiran College : Guru Nanak Institutions Name : Shashi College: Malla Reddy Institute of Technology

slide-28
SLIDE 28
  • In the Previous program, we have declare 2 classes ( a and b)

and written 2 methods ( 1 in class a and 1 in class b)…

  • In the main class (inheritance), we have created 2 objects (ob1

for class a and ob2 for class b)

  • While calling methods with objects, in first call, we have used
  • b1 to call method1 which is in “class a”
  • In second call, we used ob2 to call method2 which is in “class b”
  • In third call, we used ob2 to call method1 which is in “class a”
  • Here i have Inherited the properties of method1..
  • This Process is called INHERITANCE…

Explanation

slide-29
SLIDE 29

THANK YOU

By, RAJKIRAN EDUNURI B.Tech Computer Science, Guru Nanak Institutions,Hyderabad

e-mail : rajkiranedunuri97@gmail.com

Website : rockzzweb.wordpress.com