0% found this document useful (0 votes)
11 views54 pages

MODULE 1 PPT (2)-2

Uploaded by

sanketpajve734
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views54 pages

MODULE 1 PPT (2)-2

Uploaded by

sanketpajve734
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 54

DEPARTMENT OF ARTIFICIAl

INTELLIGENCE AND MACHINE


LEARNING
SEMESTER : 4th

SUBJECT : JAVA PROGAMMING


CHAPTER : Basic Syntactical constructs in java
TOPIC : Introduction to Java program & feature , Class and
object, java token, Application & operators of java
programming .

PRESENTED BY: MS. ARCHANA SAHU


1
Content:

Introduction to Java programming

Feature

Application of java

Type of Java

 Java token

Function of the operators


ARMIET/IT/SEM-6/DMBI

2
Introduction to Java programming language
 Our core Java programming tutorial is designed for

students and working professionals.


Java is an object-oriented, class-based, concurrent,

secured and general-purpose computer-programming


language.
 It is a widely used robust technology.

3
What is Java Programming:

 Java is a programming language and a platform. Java is a high


level, robust, object-oriented and secure programming language.
 Java was developed by Sun Microsystems (which is now the
subsidiary of Oracle) in the year 1995. James Gosling is known
as the father of Java. Before Java, its name was Oak. Since Oak
was already a registered company, so James Gosling and his
team changed the name from Oak to Java.

 Platform: Any hardware or software environment in which a


program runs, is known as a platform. Since Java has a runtime
environment (JRE) and API, it is called a platform.

4
class Simple {

public static void main(String args[]){

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

There are 4 platforms or editions of Java:


1) Java SE (Java Standard Edition)
It is a Java programming platform. It includes Java
programming APIs such as java.lang, java.io, java.net, java.util,
java.sql, java.math etc. It includes core topics like OOPs, String, Regex,
Exception, Inner classes, Multithreading, I/O Stream,
Networking, AWT, Swing, Reflection, Collection, etc.
2) Java EE (Java Enterprise Edition)
It is an enterprise platform that is mainly used to develop web
and enterprise applications. It is built on top of the Java SE
platform. It includes topics like Servlet, JSP, Web Services, EJB, 19
3) Java ME (Java Micro Edition)
It is a micro platform that is dedicated to mobile
applications.
4) Java FX

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.

public class Demo

public static void main(String args[])

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.

The Java compiler translates these tokens into Java bytecode.


Further, these byte codes are executed inside the interpreted Java
environment.

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

words of any programming language. Each keyword


has a special meaning. It is always written in lower
case. Java provides the following keywords:
01. abstract 02. boolean 03. byte 04. break 05. class
06. case 07. catch 08. char 09. continue 10. default
11. do 12. double 13. else 14. extends 15. final
16. finally 17. float 18. for 19. if 20.
implements
21. import 22. 23. int 24. interface 25. long
instanceof
26. native 27. new 28. package 29. private 30. protected
31. public 32. return 33. short 34. static 35. super
36. switch 37. 38. this 39. thro 40. throws
synchronized
25
41. transient 42. try 43. void 44. volatile 45. while
Identifier : Identifiers are used to name a variable, constant, function,
class, and array. It usually defined by the user. It uses letters,
underscores, or a dollar sign as the first character. The label is also
known as a special kind of identifier that is used in the goto statement.
Remember that the identifier name must be different from the reserved
keywords. There are some rules to declare identifiers are:

1) The first letter of an identifier must be a letter, underscore or


a dollar sign. It cannot start with digits but may contain digits.
2) The whitespace cannot be included in the identifier.
3) Identifiers are case sensitive.

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

false, true boolean

'K', '7', '-' char

"javatpoint" String

null any reference type

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:

1)Arithmetic Operators 2)Assignment Operators


3)Relational Operators 4)Unary Operators
5)Logical Operators 6)Ternary Operators
7)Bitwise Operators 8)Shift Operators

30
Operator Symbols

Arithmetic +,-,/,*,%

Unary ++ , - - , !

Assignment = , += , -= , *= , /= , %= , ^=

Relational ==, != , < , >, <= , >=

Logical && , ||

Ternary (Condition) ? (Statement1) :


(Statement2);

Bitwise &,|,^,~

Shift << , >> , >>>

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

SUBJECT : Java programming


CHAPTER : Inheritance Interface and package
TOPIC : Inheritance, Type of Inheritance, Overloading and
overridding Interfaces Package

PRESENTED BY: Archana Sahu


Content:

Kind of patterns to be mined;

 Technologies used;

Major issues in Data Mining.


Inheritance :- Inheritance in Java is a mechanism in
which one object acquires all the properties and
behaviors of a parent object. It is an important part of
OOPs (Object Oriented programming system).
The idea behind inheritance in Java is that you can
create new classes that are built upon existing classes.
When you inherit from an existing class, you can reuse
methods and fields of the parent class. Moreover, you
can add new methods and fields in your current class
also. Syntax
class Subclass-name extends Superclass-
name
{
In the terminology of Java, a class which is inherited is called
a parent or superclass, and the new class is called child or
subclass.
As displayed in the above figure, Programmer is the subclass
and Employee is the superclass. The relationship between
the two classes is Programmer IS-A Employee. It means
that Programmer is a type of Employee.
 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);
}

}
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).

Abstract method: can only be used in an abstract class, and


it does not have a body. The body is provided by the subclass
(inherited from). 50
An abstract class can have both abstract and regular methods:

abstract class Animal


{ public abstract void animalSound();
public void sleep()
{
System.out.println("Zzz");
}
}
From the example above, it is not possible to create an object of the
Animal class:
Animal myObj = new Animal(); // will generate an error

To access the abstract class, it must be inherited from another class.


Let's convert the Animal class we used in the Polymorphism chapter
to an abstract 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)

access the interface methods, the interface must be "implemented"


nda like inherited) by another class with the implements keyword
stead of extends).
he body of the interface method is provided by the "implement" class:
53
Example :-
Interface interface Animal
{ public void animalSound(); // interface method (does not have a body)
public void sleep(); // interface method (does not have a body) } // Pig
"implements" the Animal interface
class Pig implements Animal
{ public void animalSound() { // The body of animalSound() is provided
here System.out.println("The pig says: wee wee"); }
public void sleep()
{ // The body of sleep() is provided here
System.out.println("Zzz"); } }
class Main { public static void main(String[] args) {
Pig myPig = new Pig(); // Create a Pig object
myPig.animalSound();
myPig.sleep(); } }

ARMIET/IT/SEM-6/DMBI 54

You might also like