0
INTRODUCTION TO JAVA
WHAT IS JAVA?
• Java is an object oriented programming language.
• Java is platform independent.
• Java is used in mobile ...
HISTORY OF JAVA
• Java was developed by James Gosling from sun microsystems in the
year 1995.
• In January 1996, JDK1.0 wa...
Versions of java
Features of java
• Simple
• Secure
• Portable
• Object-Oriented
• Robust
• Multithreaded
• Architecture neutral
• Interpre...
Types of SDK’s in java
• Java SE
• Java EE
• Java ME
• Java Embedded
• Java DB
• Web Tier
• Java Card
• Java TV
Java virtual machine
• Java Virtual Machine is used for converting the bytecode into the
machine understandable format.
• ...
How java program is executed?
How to compile and run java program
• The java program should be saved with an extension “.java”
• The command to compile ...
Sample Java program – Hello World
Main Concepts of OOP
• Encapsulation
• Inheritance
• Polymorphism
• Abstraction
Encapsulation
• Encapsulation is the technique of making the fields in a class private
and providing access to the fields ...
Access Specifiers in java
• public
• private
• protected
• Default
Public access specifier
• A class, method, constructor, interface etc., declared public can be
accessed from any other cla...
Private access specifiers
• Methods, Variables and Constructors that are declared private can
only be accessed within the ...
Sample code for private access specifier
Protected access specifier
• Variables, methods and constructors which are declared protected in
a superclass can be acces...
Sample code for protected access specifier
Default specifier
• The default specifier is used to make a class visible to all the other
classes in its package but not ...
Inheritance
• Inheritance is a compile-time mechanism in Java that allows you to
extend a class with another class
• The k...
Types of inheritance
• Simple inheritance
• Multilevel inheritance
• Hierarchical inheritance
• Hybrid inheritance
Simple inheritance
• There are only 1 base class and 1 derived class
• Syntax:
Class Parentclass
{
}
Class Dclass extendsP...
Simple inheritance sample code and output
Multilevel inheritance
• It contains derived classes which are in turn base class to another class.
class Base
{
}
class D...
Multilevel inheritance sample code and
output
Hierarchical inheritance
• It contains one base class and more than one derived class.
class Base
{
}
class Derived1 exten...
Sample code and output for Hierarchical
inheritance
Hybrid inheritance
• It is a combination of any two or more inheritances.
Sample code for hybrid inheritance
Interface
• An interface in Java is similar to a class, but the body of an interface
can include only abstract methods and...
Syntax for interface
interface interfacename
{
method_declaration();
}
class A implements interfacename
{
method_declarati...
Interface sample code
Interface sample output
Any queries??
Thank you 
Upcoming SlideShare
Loading in...5
×

Java introduction

123

Published on

Brief explanation about java and oops concepts "encapsulation" "inheritance" and "interface"

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
123
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
10
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "Java introduction"

  1. 1. INTRODUCTION TO JAVA
  2. 2. WHAT IS JAVA? • Java is an object oriented programming language. • Java is platform independent. • Java is used in mobile phones and other embedded devices.
  3. 3. 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.
  4. 4. Versions of java
  5. 5. Features of java • Simple • Secure • Portable • Object-Oriented • Robust • Multithreaded • Architecture neutral • Interpreted • High Performance • Distributed • Dynamic
  6. 6. Types of SDK’s in java • Java SE • Java EE • Java ME • Java Embedded • Java DB • Web Tier • Java Card • Java TV
  7. 7. 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
  8. 8. How java program is executed?
  9. 9. 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”
  10. 10. Sample Java program – Hello World
  11. 11. Main Concepts of OOP • Encapsulation • Inheritance • Polymorphism • Abstraction
  12. 12. 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.
  13. 13. Access Specifiers in java • public • private • protected • Default
  14. 14. 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.
  15. 15. 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.
  16. 16. Sample code for private access specifier
  17. 17. 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.
  18. 18. Sample code for protected access specifier
  19. 19. 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
  20. 20. 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.
  21. 21. Types of inheritance • Simple inheritance • Multilevel inheritance • Hierarchical inheritance • Hybrid inheritance
  22. 22. Simple inheritance • There are only 1 base class and 1 derived class • Syntax: Class Parentclass { } Class Dclass extendsParentclass { }
  23. 23. Simple inheritance sample code and output
  24. 24. 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 { }
  25. 25. Multilevel inheritance sample code and output
  26. 26. Hierarchical inheritance • It contains one base class and more than one derived class. class Base { } class Derived1 extends Base { } class Derived2 extends Base{ }
  27. 27. Sample code and output for Hierarchical inheritance
  28. 28. Hybrid inheritance • It is a combination of any two or more inheritances.
  29. 29. Sample code for hybrid inheritance
  30. 30. 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
  31. 31. Syntax for interface interface interfacename { method_declaration(); } class A implements interfacename { method_declaration(){ } }
  32. 32. Interface sample code
  33. 33. Interface sample output
  34. 34. Any queries??
  35. 35. Thank you 
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×