Documente Academic
Documente Profesional
Documente Cultură
•PRITI PATIL
•SOHA PATHAN
•GAYATRI SURAVASE
(BE CSE)
INTRODUCTION
What is java?
JVM
How it works?
Object
Class
Access control
INTRODUCTION-What is java?
• Programming Language-
• Another programming language using which we can develop
applets, standalone applications, web applications and
enterprise applications.
• Platform Independent-
• A java program written and compiled on one machine can be
executed on any other machine(irrespective of the operating
system).
• Object Oriented –
• Compiles to object oriented programming concepts.Your
program is not object oriented unless you code that way.
• Compiled and interpreted-
• The .java file is compiled to a .class file and the .class file is
interpreted to machine code.
JVM
JVM stands for
Java Virtual Machine
class Hello {
public static void main(String[] args) {
System.out.println(“Hello World !!!”);
}
}
Sub Class/Child Class: Subclass is a class which inherits the other class. It
is also called a derived class, extended class, or child class.
The extends keyword indicates that you are making a new class that derives
from an existing class. The meaning of "extends" is to increase the functionality.
In the terminology of Java, a class which is inherited is called a parent or super
class, and the new class is called child or subclass
Types of inheritance
•Single inheritance
•Multilevel inheritance
•Hierarchical inheritance
Single inheritance
Single inheritance is damn easy to understand.
When a class extends another one class only then
we call it a single inheritance. The below flow diagram
shows that class B extends only one class which is A.
Here A is a parent class of B and B would be a child
class of A.
class Animal{
void eat()
{
System.out.println("eating...");}
}
class Dog extends Animal{
void bark()
{
System.out.println("barking...");}
}
class TestInheritance
{
public static void main(String args[])
{
Dog d=new Dog();
d.bark();
d.eat();
}
Output:
barking... eating..
Multilevel inheritance
When a class extends a class, which extends anther
class then this is called multilevel inheritance. For
example class C extends class B and class B extends
class A then this type of inheritance is known as
multilevel inheritance.
class Animal{
void eat(){System.out.println("eating...");}
}
class Dog extends Animal{
void bark(){System.out.println("barking...
");}
}
class BabyDog extends Dog{
void weep(){System.out.println("weeping.
..");}
}
class TestInheritance2{
public static void main(String args[]){
BabyDog d=new BabyDog();
d.weep();
d.bark();
d.eat();
}}
Output:
weeping... barking... eating...
Hierarchical inheritance
In Hierarchical Inheritance, one class serves as a super
class (base class) for more than one sub class . In below
image, the class A serves as a base class for the derived
class B,C and D.
class Animal{
void eat(){System.out.println("eating...");
}
}
class Dog extends Animal{
void bark(){System.out.println("barking..
.");}
}
class Cat extends Animal{
void meow(){System.out.println("meowi
ng...");}
}
class TestInheritance3{
public static void main(String args[]){
Cat c=new Cat();
c.meow();
c.eat();
//c.bark();//C.T.Error
}}
Output:
meowing... eating...
Why multiple inheritance is not supported
in java?
Checked Exception
Unchecked Exception
Error
1) Checked Exception
2) Unchecked Exception
3) Error
Error is irrecoverable e.g. OutOfMemoryError, VirtualMachineError,
AssertionError etc
Exception handling keywords
Try
Catch
Finally
Throw
Throws
class TestFinallyBlock
{
public static void main(String args[])
{
try
{
int data=25/5;
System.out.println(data);
}
catch(NullPointerException e)
{
System.out.println(e);
}
finally
{
System.out.println("finally block is always executed");
}
System.out.println("rest of the code...");
}
}
Output:5
finally block is always executed
rest of the code...
Thank you!