Professional Documents
Culture Documents
Offered By SWAYAM
Presented By;
Dr. Nidhi H. Divecha,
S.K. Patel institute of Management and Computer Studies,
Kadi Sarva Vishwavidyalaya
Gandhinagar
05/12/2020 1
Details of Course
Course Title Java programming language
05/12/2020 2
Learning Objectives
To learn why Java is useful for desktop and web applications.
To learn how to implement object-oriented designs with Java.
To identify Java language components and how they work together in
applications.
To design and program stand-alone Java applications.
To learn how to extend Java classes with inheritance and dynamic binding.
To learn how to use exception handling in Java applications.
05/12/2020 3
Course Outline
05/12/2020 4
What is Java?
Java is a popular programming language, created in 1995.
It is owned by Oracle, and more than 6 billion devices run
Java.
It is used for:
Mobile applications (specially Android apps)
Desktop applications
Web applications
Web servers and application servers
Games
Database connection
And much, much more!
05/12/2020 5
Why Java?
•Its open source – FREE
•Can be run on UNIX,Windows,LINUX,etc
•GUI/Applet capabilities
•Write Once Run Any ware(WORA)
05/12/2020 6
How to run
•JDK – Java Development Kit
•Basic compiler, linker, and libraries
•JRE – Java Runtime Environment
•It is the implementation of JVM, Predefined set of java classes available to use
•JVM – Java Virtual Machine
• Loads, verifies and executes code
05/12/2020 7
How to run
Java Applications
javac – java compiler
Commandline - javac classname.java
java – executes application
Commandline - java classname
Java Applets – java applications that are embedded in
and run in a browser
Appletviewer – shows sample in browser
Commandline – appletviewer appletpage.html
05/12/2020 8
General Syntax of Java Program
05/12/2020 12
Primitive Data Types
05/12/2020 13
Escape sequences
Sequence Purpose
\b Backspace
\t Horizontal tab
\n Line feed
\f Form feed
\r Carriage return
\" Double quote
\' Single quote
\\ Backslash
\uxxxx Unicode character
05/12/2020 14
Java Comment Delimiters
05/12/2020 15
Arithmetic Operator
Arithmetic Multiplicative *, / , %
Operators
Arithmetic +, -
multiplicative */%
Arithmetic
additive +-
Shift shift << >> >>>
comparison < > <= >= instanceof
Relational
equality == !=
bitwise AND &
Bitwise bitwise exclusive OR ^
bitwise inclusive OR |
logical AND &&
Logical
logical OR ||
Ternary ternary ?:
05/12/2020 17
Java Control Statements
05/12/2020 18
Working with Array
OUTPUT: 20
Arrays Class:
05/12/2020 19
Working with Strings
3 boolean endsWith(String suffix) - Tests if this string ends with the specified suffix.
6 String toLowerCase() - Converts all of the characters in this String to lower case using the rules of the default locale.
7 String toUpperCase() - Converts all of the characters in this String to upper case using the rules of the default locale.
05/12/2020 20
Java Methods
A method is a block of code which only runs when it is called.
05/12/2020 22
Java Class
Syntax:
modifier class myClass {
// instance variables
//constructor
//method declarations
};
//Creating Student class.
public class Student
{
int id; //variable
Student() { id=0; } // default constructor
} //end of class
//Creating another class which contains the main method
class Student_info
{
public static void main(String args[])
{
Student s1 =new Student(126);
Student s1 =new Student(126,”Nidhi”); }
} 05/12/2020 25
Inheritance in Java
Inheritance represents the IS-A relationship which is also known as a parent-child relationship.
Super Class/Parent Class: Superclass is the class from where a subclass inherits the features.
class Subclass-name extends Superclass-name
{
//methods and fields
}
05/12/2020 26
Types of inheritance in Java
On the basis of class, there can be three types of inheritance in
java:
2. Multilevel
3. Hierarchical.
05/12/2020 27
Single Inheritance
When a class inherits another class, it is known as a single inheritance.
class Employee{
float salary=40000;
}
class Programmer extends Employee
{
int bonus=10000;
public static void main(String args[])
{
Programmer p=new Programmer();
System.out.println("Programmer salary is:"+p.salary);
System.out.println("Bonus of Programmer is:"+p.bonus);
}
}
05/12/2020 28
Multilevel Inheritance
When there is a chain of inheritance, it 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();
}
05/12/2020 29
}
Hierarchical Inheritance
When two or more classes inherits a single class, it is known as hierarchical inheritance.
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("meowing...");}
}
class TestInheritance3{
public static void main(String args[])
{
Cat c=new Cat();
Dog d=new Dog();
c.eat();
c.meow();
d.eat();
d.bark();
}
} 05/12/2020 30
Multiple Inheritance
When one class inherits multiple classes, it is known as multiple inheritance.
interface Printable
{
void print();
}
interface Showable
{
void show();
}
class A7 implements Printable,Showable
{
public void print(){System.out.println("Hello");}
public void show(){System.out.println("Welcome");}
public static void main(String args[])
{
A7 obj = new A7();
obj.print();
obj.show();
}
} 05/12/2020 31
Hybrid Inheritance
When combines more than one type of inheritance, it is known as multiple inheritance.
interface A {
public void methodA();
}
interface B extends A {
public void methodB();
}
interface C extends A {
public void methodC();
}
class HybridInheritance implements B, C {
public void methodA() {
System.out.println("Calling methodA");
}
public void methodB() {
System.out.println("Calling methodB");
}
public void methodC() {
System.out.println("Calling methodC");
}
public static void main(String args[]) {
HybridInheritance obj = new HybridInheritance();
obj.methodA();
obj.methodB();
obj.methodC();
}
}
05/12/2020 32
Abstract class
Abstract Class:
05/12/2020 33
Exception Handling
05/12/2020 34
Learning Outcomes
05/12/2020 35
THANK YOU
05/12/2020 36