java introduction
DESCRIPTION
Brief explanation about java and oops concepts "encapsulation" "inheritance" and "interface"TRANSCRIPT
![Page 1: Java introduction](https://reader035.vdocument.in/reader035/viewer/2022070303/54b6daa54a7959ca538b46bb/html5/thumbnails/1.jpg)
INTRODUCTION TO JAVA
![Page 2: Java introduction](https://reader035.vdocument.in/reader035/viewer/2022070303/54b6daa54a7959ca538b46bb/html5/thumbnails/2.jpg)
WHAT IS JAVA?
• Java is an object oriented programming language.
• Java is platform independent.
• Java is used in mobile phones and other embedded devices.
![Page 3: Java introduction](https://reader035.vdocument.in/reader035/viewer/2022070303/54b6daa54a7959ca538b46bb/html5/thumbnails/3.jpg)
HISTORY OF JAVA
• Java was developed by James Gosling from sun microsystems in the year 1995.
• In January 1996, JDK1.0 was released in the name of OAK.
• The JDK 1.0.2 was the first stable version.
• James Gosling, Mike Sheridan and Patrick Naughton initiated the green project in June 1991.
![Page 4: Java introduction](https://reader035.vdocument.in/reader035/viewer/2022070303/54b6daa54a7959ca538b46bb/html5/thumbnails/4.jpg)
Versions of java
![Page 5: Java introduction](https://reader035.vdocument.in/reader035/viewer/2022070303/54b6daa54a7959ca538b46bb/html5/thumbnails/5.jpg)
Features of java
• Simple
• Secure
• Portable
• Object-Oriented
• Robust
• Multithreaded
• Architecture neutral
• Interpreted
• High Performance
• Distributed
• Dynamic
![Page 6: Java introduction](https://reader035.vdocument.in/reader035/viewer/2022070303/54b6daa54a7959ca538b46bb/html5/thumbnails/6.jpg)
Types of SDK’s in java
• Java SE
• Java EE
• Java ME
• Java Embedded
• Java DB
• Web Tier
• Java Card
• Java TV
![Page 7: Java introduction](https://reader035.vdocument.in/reader035/viewer/2022070303/54b6daa54a7959ca538b46bb/html5/thumbnails/7.jpg)
Java virtual machine
• Java Virtual Machine is used for converting the bytecode into the machine understandable format.
• JVM provides an abstraction between the java program and the operating system.
• Key components in JVM are
• Class loader
• Bytecode verifier
• Just In Time (JIT) compiler
![Page 8: Java introduction](https://reader035.vdocument.in/reader035/viewer/2022070303/54b6daa54a7959ca538b46bb/html5/thumbnails/8.jpg)
How java program is executed?
![Page 9: Java introduction](https://reader035.vdocument.in/reader035/viewer/2022070303/54b6daa54a7959ca538b46bb/html5/thumbnails/9.jpg)
How to compile and run java program
• The java program should be saved with an extension “.java”
• The command to compile the java program is “javac name.java ”
• The command to run the java program is “java name”
![Page 10: Java introduction](https://reader035.vdocument.in/reader035/viewer/2022070303/54b6daa54a7959ca538b46bb/html5/thumbnails/10.jpg)
Sample Java program – Hello World
![Page 11: Java introduction](https://reader035.vdocument.in/reader035/viewer/2022070303/54b6daa54a7959ca538b46bb/html5/thumbnails/11.jpg)
Main Concepts of OOP
• Encapsulation
• Inheritance
• Polymorphism
• Abstraction
![Page 12: Java introduction](https://reader035.vdocument.in/reader035/viewer/2022070303/54b6daa54a7959ca538b46bb/html5/thumbnails/12.jpg)
Encapsulation
• Encapsulation is the technique of making the fields in a class private and providing access to the fields via public methods.
• The main benefit of encapsulation is the ability to modify our implemented code without breaking the code of others who use our code.
• Encapsulation gives maintainability, flexibility and extensibility to our code.
![Page 13: Java introduction](https://reader035.vdocument.in/reader035/viewer/2022070303/54b6daa54a7959ca538b46bb/html5/thumbnails/13.jpg)
Access Specifiers in java
• public
• private
• protected
• Default
![Page 14: Java introduction](https://reader035.vdocument.in/reader035/viewer/2022070303/54b6daa54a7959ca538b46bb/html5/thumbnails/14.jpg)
Public access specifier
• A class, method, constructor, interface etc., declared public can be accessed from any other class.
• Therefore fields, methods, blocks declared inside a public class can be accessed from any class belonging to the Java Universe.
• If the public class we are trying to access is in a different package, then the public class still need to be imported.
![Page 15: Java introduction](https://reader035.vdocument.in/reader035/viewer/2022070303/54b6daa54a7959ca538b46bb/html5/thumbnails/15.jpg)
Private access specifiers
• Methods, Variables and Constructors that are declared private can only be accessed within the declared class itself.
• Private access modifier is the most restrictive access level. Class and interfaces cannot be private.
• Variables that are declared private can be accessed outside the class if public getter methods are present in the class.
• Using the private modifier is the main way that an object encapsulates itself and hide data from the outside world.
![Page 16: Java introduction](https://reader035.vdocument.in/reader035/viewer/2022070303/54b6daa54a7959ca538b46bb/html5/thumbnails/16.jpg)
Sample code for private access specifier
![Page 17: Java introduction](https://reader035.vdocument.in/reader035/viewer/2022070303/54b6daa54a7959ca538b46bb/html5/thumbnails/17.jpg)
Protected access specifier
• Variables, methods and constructors which are declared protected in a superclass can be accessed only by the subclasses in other package or any class within the package of the protected members' class.
• The protected access modifier cannot be applied to class and interfaces. Methods, fields can be declared protected, however methods and fields in a interface cannot be declared protected.
![Page 18: Java introduction](https://reader035.vdocument.in/reader035/viewer/2022070303/54b6daa54a7959ca538b46bb/html5/thumbnails/18.jpg)
Sample code for protected access specifier
![Page 19: Java introduction](https://reader035.vdocument.in/reader035/viewer/2022070303/54b6daa54a7959ca538b46bb/html5/thumbnails/19.jpg)
Default specifier
• The default specifier is used to make a class visible to all the other classes in its package but not visible to classes from other packages
![Page 20: Java introduction](https://reader035.vdocument.in/reader035/viewer/2022070303/54b6daa54a7959ca538b46bb/html5/thumbnails/20.jpg)
Inheritance
• Inheritance is a compile-time mechanism in Java that allows you to extend a class with another class
• The keyword extends is used for inheriting a Class.
• The class which extends some other class is called as derived class
• The base class is called as the super class or parent class.
![Page 21: Java introduction](https://reader035.vdocument.in/reader035/viewer/2022070303/54b6daa54a7959ca538b46bb/html5/thumbnails/21.jpg)
Types of inheritance
• Simple inheritance
• Multilevel inheritance
• Hierarchical inheritance
• Hybrid inheritance
![Page 22: Java introduction](https://reader035.vdocument.in/reader035/viewer/2022070303/54b6daa54a7959ca538b46bb/html5/thumbnails/22.jpg)
Simple inheritance
• There are only 1 base class and 1 derived class
• Syntax:
Class Parentclass
{
}
Class Dclass extendsParentclass
{
}
![Page 23: Java introduction](https://reader035.vdocument.in/reader035/viewer/2022070303/54b6daa54a7959ca538b46bb/html5/thumbnails/23.jpg)
Simple inheritance sample code and output
![Page 24: Java introduction](https://reader035.vdocument.in/reader035/viewer/2022070303/54b6daa54a7959ca538b46bb/html5/thumbnails/24.jpg)
Multilevel inheritance
• It contains derived classes which are in turn base class to another class.class Base{}class Derived1 extends Base{}class Derived2 extends Derived1{}
![Page 25: Java introduction](https://reader035.vdocument.in/reader035/viewer/2022070303/54b6daa54a7959ca538b46bb/html5/thumbnails/25.jpg)
Multilevel inheritance sample code and output
![Page 26: Java introduction](https://reader035.vdocument.in/reader035/viewer/2022070303/54b6daa54a7959ca538b46bb/html5/thumbnails/26.jpg)
Hierarchical inheritance
• It contains one base class and more than one derived class.
class Base
{
}
class Derived1 extends Base
{
}
class Derived2 extends Base{ }
![Page 27: Java introduction](https://reader035.vdocument.in/reader035/viewer/2022070303/54b6daa54a7959ca538b46bb/html5/thumbnails/27.jpg)
Sample code and output for Hierarchical inheritance
![Page 28: Java introduction](https://reader035.vdocument.in/reader035/viewer/2022070303/54b6daa54a7959ca538b46bb/html5/thumbnails/28.jpg)
Hybrid inheritance
• It is a combination of any two or more inheritances.
![Page 29: Java introduction](https://reader035.vdocument.in/reader035/viewer/2022070303/54b6daa54a7959ca538b46bb/html5/thumbnails/29.jpg)
Sample code for hybrid inheritance
![Page 30: Java introduction](https://reader035.vdocument.in/reader035/viewer/2022070303/54b6daa54a7959ca538b46bb/html5/thumbnails/30.jpg)
Interface
• An interface in Java is similar to a class, but the body of an interface can include only abstract methods and final fields (constants).
• A class implements an interface by providing code for each method declared by the interface.
• The keyword used in interface concepts are interface and implements
![Page 31: Java introduction](https://reader035.vdocument.in/reader035/viewer/2022070303/54b6daa54a7959ca538b46bb/html5/thumbnails/31.jpg)
Syntax for interface
interface interfacename
{
method_declaration();
}
class A implements interfacename
{
method_declaration(){ }
}
![Page 32: Java introduction](https://reader035.vdocument.in/reader035/viewer/2022070303/54b6daa54a7959ca538b46bb/html5/thumbnails/32.jpg)
Interface sample code
![Page 33: Java introduction](https://reader035.vdocument.in/reader035/viewer/2022070303/54b6daa54a7959ca538b46bb/html5/thumbnails/33.jpg)
Interface sample output
![Page 34: Java introduction](https://reader035.vdocument.in/reader035/viewer/2022070303/54b6daa54a7959ca538b46bb/html5/thumbnails/34.jpg)
Any queries??
![Page 35: Java introduction](https://reader035.vdocument.in/reader035/viewer/2022070303/54b6daa54a7959ca538b46bb/html5/thumbnails/35.jpg)
Thank you