JAVA
PROGRAMMING
UNIT-I
DR. HIMANI MAHESHWARI
ASSISTANT PROFESSOR
SCHOOL OF COMPUTING
PROGRAM
• Set of instructions that tell a computer what to do.
• We use programs to interact/talk with computers.
• To write programs we use programming languages.
PROGRAMMING LANGUAGES
• Languages used to write programs.
• Computers are machines
- they do not understand human languages.
• Programs are written in a language that a computer can understand i.e.
programming languages.
MACHINE LANGUAGE (FIRST GENERATION)
• A computer’s native Language.
• Uses zeros and ones (0 &1) - Binary Language.
• Very hard to use.
• Machine dependent- differs among different types of machines.
• Every instruction should be written in machine language before it can
be executed.
• All instructions written in other programming languages must be
translated to machine code instructions.
ASSEMBLY LANGUAGE (SECOND
GENERATION)
• Was developed to make programming easier.
• Machine dependent.
• Introduced keywords like : ADD, SUB, …..
• To add 2 and 3 and get the result: add 2, 3, result
• A program called assembler translates assembly code to machine
language.
HIGH LEVEL LANGUAGE (THIRD GENERATION)
• A new generation of programming languages.
• Uses English words.
• Easy to learn and use.
GENERATION OF PROGRAMMING LANGUAGES
• The machine level programming is it is the first generation of programming language.
• Later on the second generation programming language is basically with assembly
language programming, those are basically suitable for microprocessor level
programming.
• And then next level programming is called the third generation programming language.
There are different programming languages like C, C++, C sharp, Java, the visual BASIC,
FORTRAN all these are basically belongs to this third generation programming language.
• Now, third generation programming language needs a skill from the programmer that
how to solve a problem.
GENERATION OF PROGRAMMING LANGUAGES
• Now recently there is another high level programming is called the fourth
generation programming, popularly called the 4 GL.
• And these basically does not require so, much programming afford from the user
the programmer should tell what to do. So, the third generation language if it
is how to do, then the fourth generation language is what to do.
• And example of fourth generation language is SQL structured query language that
we used to delete the database. So, in this course we will also use this 4 GL; that
means, Java can interact from its 3 GL flavor to the 4 GL things. So, there are
different programming languages paradigm of course, Java belongs to third
generation programming languages.
PARADIGM OF PROGRAMMING LANGUAGES
• Function Oriented: C
• Object Oriented: C++, JAVA
JAVA PROGRAMMING PARADIGMS
• Java is based on the concept of OOP. As name suggest the center of it
all is an object. Objects contain both data and the functionality that
operates on that data. This is controlled by the four paradigms:
1. Encapsulation
2. Inheritance
3. Information hiding
4. Polymorphism
ENCAPSULATION
IN JAVA
Encapsulation in Java is a process
of wrapping code and data
together into a single unit, for
example, a capsule which is mixed
of several medicines.
ENCAPSULATION EXAMPLE
INHERITANCE IN
JAVA
INHERITANCE in Java is a
mechanism in which one object
acquires all the properties and
behaviors of a parent object.
INFORMATION HIDING
POLYMORPHISM
POLYMORPHISM EXAMPLE
HISTORY OF JAVA
• Java was developed by James Gosling, Patrick Naughton, Mike Sheridan (Green Team)
at Sun Microsystems Inc. in 1991. It took 18 months to develop the first working
version.
• The initial name was Green Talk then renamed to Oak but again it was renamed to
Java in 1995 as Oak was a registered trademark of another tech. company.
• The team initiated this project to develop a language for digital devices such as set-
top boxes, television, etc. The history of Java starts with the Green Team. Java team
members (also known as Green Team), initiated this project to develop a language
for digital devices such as set-top boxes, televisions, etc.
• James Gosling, is known as the father of Java.
HISTORY OF JAVA
• Currently, Java is used in internet programming, mobile devices, games, e-business
solutions, etc. Following are given significant points that describe the history of Java.
1) James Gosling, Mike Sheridan, and Patrick Naughton initiated the Java language
project in June 1991. The small team of sun engineers called Green Team.
2) Initially it was designed for small, embedded systems in electronic appliances like set-top
boxes.
3) Firstly, it was called "Greentalk" by James Gosling, and the file extension was .gt.
4) After that, it was called Oak and was developed as a part of the Green project.
5) In 1995, TIME Magazine called Java one of the ten best products of 1995
5) Java Development Kit (JDK) 1.0 released in January 23, 1996.
WHY JAVA WAS NAMED AS "OAK"?
• The name Oak was used by Gosling after an oak tree that remained
outside his office. But they had to later rename it as “JAVA” as it was
already a trademark by Oak Technologies. Oak is a symbol of
strength and chosen as a national tree of many countries like the
U.S.A., France, Germany, Romania, etc.
• In 1995, Oak was renamed as "Java" because it was already a
trademark by Oak Technologies
WHY JAVA PROGRAMMING NAMED "JAVA"?
• The team gathered to choose a new name. The suggested words were
"dynamic", "revolutionary", "Silk", "jolt", "DNA", etc. They wanted something
that reflected the essence of the technology: revolutionary, dynamic, lively, cool,
unique, and easy to spell, and fun to say.
• According to James Gosling, "Java was one of the top choices along with Silk".
Since Java was so unique, most of the team members preferred Java than other
names.
• Java is an island in Indonesia where the first coffee was produced (called Java
coffee). It is a kind of espresso bean. Java name was chosen by James Gosling
while having a cup of coffee nearby his office.
INTRODUCTION
• 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.
APPLICATIONS OF 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.
4. Mobile
5. Embedded System
6. Smart Card
7. Robotics
8. Games, etc.
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. Currently, Servlet, JSP, Struts, Spring, Hibernate, JSF, etc. technologies are
used for creating web applications in Java.
TYPES OF JAVA APPLICATIONS
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.
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, JPA (Java Persistence API), etc.
JAVA PLATFORMS / EDITIONS
3) Java ME (Java Micro Edition)
It is a micro platform that is dedicated to mobile applications.
4) JavaFX
It is used to develop rich internet applications. It uses a lightweight user
interface API.
Comparison C++ Java
Index
Platform- C++ is platform-dependent. Java is platform-independent.
independ
ent
Mainly C++ is mainly used for system programming. Java is mainly used for application programming. It is widely
used for used in Windows-based, web-based, enterprise, and mobile
applications.
Design C++ was designed for systems and applications Java was designed and created as an interpreter for printing
Goal programming. It was an extension of the C systems but later extended as a support network computing. It
programming language. was designed to be easy to use and accessible to a broader
audience.
Goto C++ supports the goto statement. Java doesn't support the goto statement.
Multiple C++ supports multiple inheritance. Java doesn't support multiple inheritance through class. It can
inheritanc be achieved by using interfaces in java.
e
Operator C++ supports operator overloading. Java doesn't support operator overloading.
Overloadi
ng
Pointers C++ supports pointers. You can write a pointer Java supports pointer internally. However, you can't write the
program in C++. pointer program in java. It means java has restricted pointer
support in java.
Compiler C++ uses compiler only. C++ is compiled and run using the Java uses both compiler and interpreter. Java source
and compiler which converts source code into machine code so, code is converted into bytecode at compilation
Interpreter C++ is platform dependent. time. The interpreter executes this bytecode at
runtime and produces output. Java is interpreted
that is why it is platform-independent.
Call by C++ supports both call by value and call by reference. Java supports call by value only. There is no call by
Value and reference in java.
Call by
reference
Structure C++ supports structures and unions. Java doesn't support structures and unions.
and Union
Thread C++ doesn't have built-in support for threads. It relies on Java has built-in thread support.
Support third-party libraries for thread support.
Documentat C++ doesn't support documentation comments. Java supports documentation comment (/** ... */) to
ion create documentation for java source code.
comment
Virtual C++ supports virtual keyword so that we can decide whether Java has no virtual keyword. We can override all
Keyword or not to override a function. non-static methods by default. In other words, non-
static methods are virtual by default.
unsigned C++ doesn't support >>> operator. Java supports unsigned right shift >>> operator
right shift that fills zero at the top for the negative numbers.
>>> For positive numbers, it works same like >>
operator.
Inheritanc C++ always creates a new inheritance tree. Java always uses a single inheritance tree
e Tree because all classes are the child of the Object
class in Java. The Object class is the root of
the inheritance tree in java.
Hardware C++ is nearer to hardware. Java is not so interactive with hardware.
Object- C++ is an object-oriented language. However, in the Java is also an object-oriented language.
oriented C language, a single root hierarchy is not possible. However, everything (except fundamental