Professional Documents
Culture Documents
KG College of Arts and Science Affiliated by Bharathiar University and Accredited by Naac Kgisl Campus, Saravanampatti, Coimbatore, Tamilnadu, India
KG College of Arts and Science Affiliated by Bharathiar University and Accredited by Naac Kgisl Campus, Saravanampatti, Coimbatore, Tamilnadu, India
Class : II BCA‘B’
Semester : III
Prepared by : J.S.Kavithamani
Assistant Professor
Department of Computer Applications
KG College of Arts and Science
Unit – I
Fundamentals of Object-Oriented Programming
& Java Evolution
•Java is a general-purpose, concurrent, object-oriented,
class-based, and the runtime environment(JRE) which
consists of JVM which is the cornerstone of the Java
platform.
•It is used for:
INTRODUCTIO • Mobile applications (specially Android apps)
N TO JAVA • Desktop applications
• Web applications
• Web servers and application servers
• GamesDatabase connection
• And much, much more!
• Java works on different platforms (Windows, Mac,
Linux, Raspberry Pi, etc.)
• It is one of the most popular programming language in
the world
• It is easy to learn and simple to use
• It is open-source and free
Why Use • It is secure, fast and powerful
Developer Dennis Ritchie in 1972 Bjarne Stroustrup in 1979 James Gosling in 1991
Interpreted language
Translator Compiler only Compiler only
(Compiler + interpreter)
Datatypes (union,
Supported Supported Not supported
structure)
No constructor neither
Destructors Supported Not supported
destructor
Storage Classes Supported ( auto, extern ) Supported ( auto, extern ) Not supported
• we created a Java file called MyClass.java, and
we used the following code to print "Hello
World" to the screen:
MyClass.java
public class MyClass {
public static void main(String[]
Java Syntax args) {
System.out.println("Hello
World");
}
}
•
• Every line of code that runs in Java must be
inside a class. In our example, we named
the class MyClass. A class should always
start with an uppercase first letter.
Example • Note: Java is case-sensitive: "MyClass" and
explained "myclass" has different meaning.
• The name of the java file must match the
class name. When saving the file, save it
using the class name and add ".java" to the
end of the filename.
Java Tokens
A smallest individual unit in source code is known as Token
Java Tokens
•Use lowercase
For example:
package pack1;
package mypack1;
5%4 will result in 1 (remainder) -5%4 will result in -1 5%-4 will result in 1 -5%-4 will result in -1
•Relational Operator: <, >, <=, >=, ==, != Output will be either true or false
5>6 will result in false
5>=6 will result in false (either greater than or equal to)
5<6 will result in true
5<=6 will result in true (either less than or equal to)
5==6 will result in false (equal to)
5!=6 will result in true (not equal to)
•Assignment Operator: = Assign the value on left hand side to right hand side. For example:
A=10+5, will assign 15 to A
}
Structure of a Java Class
}
Structure of a Java Class
}
Structure of a Java Class
}
}
Structure of a Java Class
}
}
Structure of a Java Class
}
}
Structure of a Java Class
}
}
Structure of a Java Class
move(5);
Structure of a Java Method Call
atWorldEdge()
Structure of a Java Method Call
if( atWorldEdge() )
Structure of an If-Structure
if( condition ) {
true branch
}
Structure of an If-Structure
if( condition ) {
true branch
}
Structure of an If-Structure
if( condition ) {
true branch
} else {
false branch
}
JAVA PROGRAMMING
Introduction to JAVA
Contents
• What is JAVA?
• What is OOP?
• Why Java?
• Characteristics of JAVA
• Overview of Java.
• The difference between Java and C++?
• A Simple JAVA Program
What is JAVA?
• Developed by Sun Microsystems (James
Gosling)
• A general-purpose Object-Oriented language
• Based on C/C++
• Designed for easy Web/Internet applications
• Widespread acceptance
What is Object Oriented Programming?
Object-oriented programming is a method of implementation in
which programs are organized as cooperative collections of
objects, each of which represents an instance of some class, and
whose classes are all members of one or more hierarchy of classes
united via inheritance relationships.
Principles of OOP
•All object-oriented programming languages provide
mechanisms that help you implement the object-
oriented model.
• They are:
• Encapsulation
• Inheritance
• Polymorphism
Data Encapsulation
Encapsulation is the mechanism that binds together code and the
data it manipulates, and keeps both safe from outside interference
and misuse.
class Account {
int x=10;
float withdraw();
void deposit(float amount); float
balance;
}
Advantages of Encapsulation
• Protection
• Consistency
• Allows change
Inheritance
•Inheritance is the process by which one object acquires the
properties of another object.
11
Java, Web, and Beyond
• Java Applets
12
Characteristics of Java
•Java Is Simple
•Java Is Object-Oriented
•Java Is Distributed
•Java Is Interpreted
•Java Is Robust
•Java Is Secure
•Java Is Architecture-Neutral
•Java Is Portable
•Java's Performance
•Java Is Multithreaded
•Java Is Dynamic
13
Java Disadvantages
•In 1992, the Green Project was spun off and its interest directed
toward building highly interactive devices for the cable TV industry.
This failed to materialize.
•In 1994, the focus of the original team was re-targeted, this time to
the use of Internet technology. A small web browser called HotJava
was written.
•Oak was renamed to Java after learning that Oak had already been
trademarked.
A Simple Java Program
39
Compiling Java Source Code
Java was designed to run object programs on any
platform.
With Java, you write the program once, and compile the
source program into a special type of object code, known as
bytecode.
The byte-code can then run on any computer with a Java Virtual
Machine, as shown below.
Java Bytecode
Java Virtual Machine is a software Java Virtual
Machine
that interprets Java byte-code.
Any
Computer
40