MODULE 1 PPT (2)-2
MODULE 1 PPT (2)-2
Feature
Application of java
Type of Java
Java token
2
Introduction to Java programming language
Our core Java programming tutorial is designed for
3
What is Java Programming:
4
class Simple {
System.out.println("Hello Java");
5
Feature:-
The primary objective of Java programming language
creation was to make it portable, simple and secure
programming language. Apart from this, there are also
some excellent features which play an important role
in the popularity of this language. The features of Java
are also known as Java buzzwords.
A list of the most important features of the Java
language is given below.
Simple
Object-oriented
Portable
Platform Independent
Secured
Robust
Architecture neutral interpreted
High Performance
7
Multithreaded
Distributed
Dynamic
8
Simple :-
Java is very easy to learn, and its syntax
is simple, clean and easy to understand. According to Sun
Microsystem , Java language is a simple programming language
because:
Java syntax is based on C++ (so easier for programmers to
learn it after C++).
Java has removed many complicated and rarely-used features,
for example, explicit pointers, operator overloading, etc.
There is no need to remove unreferenced objects because
there is an Automatic Garbage Collection in Java.
9
Object-oriented :-
Java is an object-oriented programming language. Everythin
Java is an object. Object-oriented means we organize our software
as a combination of different types of objects that incorporate both
data and behavior.
Object-oriented programming (OOPs) is a methodology that simplifi
software development and maintenance by providing some rules.
Basic concepts of OOPs are:
1) Object 2) Class 3) Inheritance 4) Polymorphism
5) Abstraction 6) Encapsulation
10
Platform Independent :-
Java is platform independent because it is different fr
other languages like C, C++, etc . which are compiled into
platform specific machines while Java is a write once, run
anywhere language. A platform is the hardware or softwar
environment in which a program runs.
There are two types of platforms software-base
hardware-based. Java provides a software-based platform.
11
The Java platform differs from most other platforms in the
sense that it is a software-based platform that runs on top
of
other hardware-based platforms. It has two components:
The Java platform differs from most other platforms in the
sense that it is a software-based platform that runs on top
of
other hardware-based platforms. It has two components:
1) Runtime Environment
2) API(Application Programming Interface)
12
Java code can be executed on multiple platforms, for
example, Windows, Linux, Sun Solaris, Mac/OS, etc. Java
code is compiled by the compiler and converted into
bytecode. This bytecode is a platform-independent code
because it can be run on multiple platforms, i.e., Write
Once and Run Anywhere (WORA).
13
Secured :-
Java is best known for its security. With Java, we can
develop virus-free systems. Java is secured because:
No explicit pointer
Java Programs run inside a virtual machine sandbox
14
Application
According to Sun, 3 billion devices run
Java. There are many devices where Java is
currently used. Some of them are as follows:
1) Desktop Applications such as acrobat
reader, media player, antivirus, etc.
2)Web Applications such as irctc.co.in,
javatpoint.com, etc.
3) Enterprise Applications such as banking
applications.
. 15
4) Mobile
5) Embedded System
6) Smart Card
7) Robotics
8) Games, etc
16
Types of Java Applications
There are mainly 4 types of applications that can be created
using Java programming:
1) Standalone Application
Standalone applications are also known as desktop applications
or window- based applications. These are traditional software that
we need to install on every machine. Examples of standalone application
are Media player, antivirus, etc. AWT and Swing are used in Java for
creating standalone applications.
2) Web Application
An application that runs on the server side and creates a
dynamic page is called a web application.
17
Currently, Servlet, JSP, Struts, Spring, Hibernate, JSF, etc.
technologies are used for creating web applications in Java.
3) Enterprise Application
An application that is distributed in nature, such as banking
applications, etc. is called an enterprise application. It has advantages
like high-level security, load balancing, and clustering. In Java, EJB is
used for creating enterprise applications.
4) Mobile Application
An application which is created for mobile devices is called a
mobile application. Currently, Android and Java ME are used for
creating mobile applications.
18
Java Platforms / Editions
ARMIET/IT/SEM-6/DMBI 20
Java TOKENS
The Java compiler breaks the line of code into text (words) is
called Java tokens. These are the smallest element of the Java program.
The Java compiler identified these words as tokens. These tokens are
separated by the delimiters. It is useful for compilers to detect errors.
Remember that the delimiters are not part of the Java tokens.
21
For example, consider the following code.
System.out.println("javapoint");
}
In the above code snippet, public, class, Demo, {, static, void,
main, (, String, args, [, ], ), System, ., out, println, javapoint,
etc. are the Java tokens.
23
Types of Tokens
Java token includes the following:
1) Keywords
2) Identifiers
3) Literals
4) Operators
5) Separators
6) Comments
24
Keywords: These are the pre-defined reserved
26
Some valid identifiers are:
PhoneNumber
PRICE
radius
a
a1
_phonenumber
$circumference
jagged_array
12radius //invalid
ARMIET/IT/SEM-6/DMBI 27
Literals: In programming literal is a notation that represents
a fixed value (constant) in the source code. It can be
categorized as an integer literal, string literal, Boolean literal,
etc. It is defined by the programmer. Once it has been defined
cannot be changed. Java provides five types of literals are as
follows:
1) Integer
2) Floating Point
3) Character
4) String
5) Boolean
Literal Type
23 int
9.86 double
"javatpoint" String
29
Operators: In programming, operators are the special symbol that tells the
compiler to perform a special operation. Java provides different types of
operators that can be classified according to the functionality they provide.
There are eight types of operators in Java, are as follows:
30
Operator Symbols
Arithmetic +,-,/,*,%
Unary ++ , - - , !
Assignment = , += , -= , *= , /= , %= , ^=
Logical && , ||
Bitwise &,|,^,~
ARMIET/IT/SEM-6/DMBI 31
Loops :-
Java For Loop
When you know exactly how many times you want to loop
through a block of code, use the for loop instead of
a while loop:
Syntax
for (statement 1; statement 2; statement 3)
{ // code block to be executed }
Statement 1 is executed (one time) before the execution of the
code block.
Statement 2 defines the condition for executing the code block.
Statement 3 is executed (every time) after the code block has
The example below will print the numbers 0 to 4:
Example
for (int i = 0; i < 5; i++)
{ System.out.println(i);
}
Statement 1 is executed (one time) before the
execution of the code block.
Statement 2 defines the condition for executing the
code block.
Statement 3 is executed (every time) after the code
block has been executed.
ARMIET/IT/SEM-6/DMBI 33
DEPARTMENT OF INFORMATION
TECHNOLOGY
SEMESTER : 3th
Technologies used;
float salary=40000;
}
int bonus=10000;
}
Types of inheritance :- There are three type of inheritance.
Single Inheritance :- When a class inherits another
class, it is known as a single inheritance. In the example
given below, Dog class inherits the Animal class, so
there is the single inheritance.
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();
}}
Multilevel Inheritance :- When there is a chain of
inheritance, it is known as multilevel inheritance. As you can
see in the example given below, BabyDog class inherits the
Dog class which again inherits the Animal class, so there is a
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();
}}
Hierarchical Inheritance :- When two or more classes
inherits a single class, it is known as hierarchical inheritance.
In the example given below, Dog and Cat classes inherits the
Animal class, so there is 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();
c.meow();
c.eat();
//c.bark();/
}
}
44
class Cat extends Animal{
void meow()
{System.out.println("meowing...");}
}
class TestInheritance3{
public static void main(String args[]){
Cat c=new Cat();
c.meow();
c.eat();
//c.bark();
}
Overloading :- Methods are used in Java to describe
the behaviour of an object. Methods are a collection of
statements that are group together to operate. In Java, it is
possible to create methods that have the same name, but
different argument lists in various definitions, i.e., method
overloading is possible in Java, which is one of the unique
features of Object Oriented Programming (OOP). In this
chapter, we will learn about how method overloading is
written and how it helps us within a Java program. Syntax
public class Student
{ public void add(int i, int j)
{ .... } public void add(int i) { .... } }
class Multiply {
void mul (int a, int b) {
System.out.println("Sum of two=" + (a * b));
}
void mul(int a, int b, int c) {
System.out.println("Sum of three=" + (a * b *
c));
}
}
public class Polymorphism {
public static void main(String args[]) {
Multiply m = new Multiply();
m.mul(6, 10);
m.mul(10, 6, 5);
}
}
Output :-
Sum of two=60
Sum of three=300
Overriding :- Declaring a method in the subclass
which already exists there in the parent class is known as
method overriding. When a class is inheriting a method
from a superclass of its own, then there is an option of
overriding the method provided it is not declared as final.
The advantage of using overriding is the ability to classify
a behavior that's specific to the child class, and the child
class can implement a parent class method based on its
necessity.
class college {
public void move() {
System.out.println("College is open");
}
}
class univ extends college {
public void move() {
System.out.println("University is open too");
}
}
public class stud {
public static void main(String args[]) {
college a = new college();
college b = new univ();
a.move();
b.move();
}
}
Abstract Classes and Methods :- Data abstraction is the
process of hiding certain details and showing only essential
information to the user.
Abstraction can be achieved with either abstract classes or
interfaces (which you will learn more about in the next chapter
The abstract keyword is a non-access modifier, used for classes
and methods:
Abstract class: is a restricted class that cannot be used to create
objects (to access it, it must be inherited from another class).
ARMIET/IT/SEM-6/DMBI 51
Example :- Abstract class
abstract class Animal
{ // Abstract method (does not have a body)
public abstract void animalSound();
// Regular method
public void sleep()
{ System.out.println("Zzz");
}
} //
Subclass (inherit from Animal)
class Pig extends Animal
{
public void animalSound()
{ // The body of animalSound() is provided here 3
System.out.println("The pig says: wee wee"); } }
class Main
{ public static void main(String[] args)
{
Pig myPig = new Pig(); //
Create a Pig object myPig.animalSound(); myPig.sleep(); } }
52
terfaces:- Another way to achieve abstraction in Java, is with interfac
interface is a completely "abstract class" that is used to group related
ethods with empty bodies
terface Animal
public void animalSound(); // interface method (does not have a body)
ublic void run(); // interface method (does not have a body)
ARMIET/IT/SEM-6/DMBI 54