Module 1
Module 1
Chapter 1
Introduction
Learning Outcomes:
Background History
This chapter will give you a brief history of how Java software came into life, starting
from the existence of computers. It will also provide you a brief overview of the evolution of the
various computer programming languages.
It was not long ago, well maybe around two decades, that there were still typewriters to
create the documents we need at home, in school or for work. Remember your mother’s recipes
on index cards, your thesis in college, your resume for a job application and many more. Then
here comes the birth of computer systems that made everything a whole lot easier! It was a total
revolution when these miracle machines were introduced. Now, with just a click of the mouse or
a keystroke you have photos printed out to decorate your home, a YouTube video of your high
school ball, or a visually compelling marketing presentation for work.
Object-Oriented Programming
•1954-1957
John Backus with an IBM team developed FORTRAN (considered the first
modern computer programming language but definitely not user-friendly).
•1959
Grace Hopper at Remington Rand developed COBOL (Letter B stands for
Business, which is COBOL’s primary feature that included processing records of
customers, employees and more)
•1972
Dennis Ritchie at AT&T Bell Labs developed the C programming language.
•1986
Bjarne Stroustrup at AT&T Bell Labs developed C++ that supported object-
oriented programming (OOP).
•1995
It was exactly on May 23rd that Sun Microsystems released the first official
version of Java programming language that is considered as an improvement of C++.
This general-purpose software enables you to build and explore databases, write
windowed applications and control handheld devices, among others. Just after five years,
Java already had 2.5 million developers worldwide.
• 2000
The College Board announced in November that Computer Science Advanced
Placement exams will be based on Java by 2003.
• 2002
Microsoft introduced C#, a new language named that inherited most of its
programming features from Java. Sys-Con Media reported in June of the same year that
there was an increasing demand for Java programmers (it has exceeded by 50% as
compared to the demand for C++ programmers).
• 2007
Google started developing apps on Android mobile devices using the Java
language. 2010 Oracle Corporation incorporated Java technology into the Oracle family
by purchasing Sun Microsystems in January
• 2010
eWeek ranked Java in June as first among its “Top 10 Programming Languages
to Keep You Employed” (www.eweek.com/c/a/ Application-Development/Top-10-
Programming-Languagesto-Keep-You-Employed-719257).
• 2013
More than 1.1 billion desktop computers and 250 million mobile phones have
been using Java platform since August 2013
(www.mobiledevicemanager.com/mobiledevicestatistics/250-million-android-devices-in-
use and http://java.com/en/about). Moreover, Blu-ray devices emerged with more
interactive capabilities through the new technology. Java was already considered the most
popular language by various programming groups and communities, such as TIOBE
Object-Oriented Programming
In 1991, James Gosling led a team at Sun Microsystems that developed the first version
of Java (which was not yet called Java). This first version of the language was designed for
programming home appliances, such as washing machines and television sets. Although that may
not be a very glamorous application area, it is no easy task to design such a language. Home
appliances are controlled by a wide variety of computer processors (chips). The language that
Gosling was designing needed to work on all these different processors. Moreover, a home
appliance is typically an inexpensive item, so the manufacturer would be unwilling to invest large
amounts of money into developing complicated compilers. (A compiler translates a program into
a language the processor can understand.) To simplify the tasks of writing compilers (translation
programs) for each class of appliances, the team used a two-step translation process. The
programs are first translated into an intermediate language that is the same for all appliances (or
all computers), and then a small, easy-to-write—and hence, inexpensive—program translates this
intermediate language into the machine language for a particular appliance or computer. This
intermediate language is called Java bytecode, or simply, byte-code. Since there is only one
intermediate language, the hardest step of the two-step translation from program to intermediate
language to machine language is the same for all appliances (or all computers); hence, most of the
cost of translating to multiple machine languages was saved. The language for programming
appliances never caught on with appliance manufacturers, but the Java language into which it
evolved has become a widely used programming language. Today, Java is owned by Oracle
Corporation, which purchased Sun Microsystems in 2010. Why call it byte-code? The word code
is commonly used to mean a program or part of a program. A byte is a small unit of storage (eight
bits to be precise). Computer readable information is typically organized into bytes. So the term
byte-code suggests a program that is readable by a computer as opposed to a person. In 1994,
Patrick Naughton and Jonathan Payne at Sun Microsystems developed a Web browser that could
run (Java) programs over the Internet, which has evolved into the browser known as HotJava.
This was the start of Java’s connection to the Internet. In the fall of 1995, Netscape Incorporated
made its Web browser capable of running Java programs. Other companies followed suit and
have developed software that accommodates Java programs.
What is JAVA?
James Gosling initially developed Java in Sun Microsystems (which was later merged
with Oracle Corporation).
Java is a set of features of C and C++. It has obtained its format from C, and OOP
features from C++.
Java programs are platform independent which means they can be run on any operating
system with any processor as long as the Java interpreter is available on that system.
Java code that runs on one platform does not need to be recompiled to run on another
platform; it's called write once, run anywhere (WORA).
Object-Oriented Programming
Java Virtual Machine (JVM) executes Java code, but it has been written in platform-
specific languages such as C/C++/ASM, etc. JVM is not written in Java and hence cannot
be platform independent, and Java interpreter is a part of JVM.
Earlier Java was only used to design and program small computing devices, but it was
later adopted as one of the platform-independent programming languages, and now according to
Sun, 3 billion devices run Java.
Java is one of the most important programming languages in today's IT industries.
JSP - In Java, JSP (Java Server Pages) is used to create dynamic web pages, such as in
PHP and ASP.
Applets - Applets are another type of Java programs that are implemented on Internet
browsers and are always run as part of a web document.
Mobile - In addition to the above technology, Java is widely used in mobile devices
nowadays, many types of games and applications are being made in Java.
4. Mobile Application - Java is used to create application software for mobile devices.
Currently, Java ME is used for building applications for small devices, and also Java is a
programming language for Google Android application development.
You will need a text editor to write Java programs. There is even more sophisticated IDE
available in the market. But for now, you can consider one of the following:
Object-Oriented Programming
Notepad - On Windows machine, you can use any simple text editor like Notepad
(Recommended for this tutorial), TextPad.
Netbeans - is a Java IDE that is open source and free which can be downloaded
from http://www.netbeans.org/index.html
Eclipse - is also a java IDE developed by the Eclipse open source community and can be
downloaded from http://www.eclipse.org/
EVOLUTIONS OF JAVA
History of Java programming language is usually associated with origin predates of the
web. James Gosling, Patrick Naughton, Chris Warth, Mike Sheridan, and Ed Frank initiated the
Java language project in June 1991. The idea was to develop a language which was platform-
independent and which could create embedded software for consumer electronic devices. It took
18 months to develop and had an initial name as Oak which was renamed to Java in 1995, due to
copyright issues.
Java originally developed by James Gosling at Sun Microsystems(which has since merged into
Oracle Corporation) and released in 1995. JDK 1.0 released in (January 23, 1996).Java SE
10 is a current stable release of Java, and many other previous Java versions are also available.
papers, and so forth. Each of these objects has the ability to perform certain actions, and each of
these actions has some effect on some of the other objects in the world. OOP is a programming
methodology that views a program as similarly consisting of objects that interact with each other
by means of actions. Object-oriented programming has its own specialized terminology. The
objects are called, appropriately enough, objects. The actions that an object can take are called
methods. Objects of the same kind are said to have the same type or, more often, are said to be in
the same class.
NOTABLE FEATURES OF JAVA:
Platform independent - C and C++ are platform dependency languages hence the
application programs written in one Operating system cannot run in any other Operating
system, but in platform independence language like Java application programs written in
one Operating system can able to run on any Operating system.
Simple - Java has included many features of C / C ++, which makes it easy to
understand.
Secure - Java provides a wide range of protection from viruses and malicious
programs. It ensures that there will be no damage and no security will be broken.
Portable - Java provides us with the concept of portability. Running the same program
with Java on different platforms is possible.
Robust - During the development of the program, it helps us to find possible mistakes as
soon as possible.
OOP Concepts
Abstraction
Encapsulation
Inheritance
Polymorphism
Encapsulation. This is the practice of keeping fields within a class private, then
providing access to them via public methods. It’s a protective barrier that keeps the data
and code safe within the class itself. This way, we can re-use objects like code
components or variables without allowing open access to the data system-wide.
Polymorphism. This Java OOP concept lets programmers use the same word to mean
different things in different contexts. One form of polymorphism in Java is method
overloading. That’s when different meanings are implied by the code itself. The other
form is method overriding. That’s when the different meanings are implied by the values
of the supplied variables.
Documentation Section
Package Statement
Import Statements
Interface Statement
Class Definition
Main Method Class
Section Description
Documentation You can write a comment in this section. Comments are beneficial for
Section the programmer because they help them understand the code. These
are optional, but we suggest you use them because they are useful to
understand the operation of the program, so you must write comments
within the program.
Package statement You can create a package with any name. A package is a group of
classes that are defined by a name. That is, if you want to declare many
classes within one element, then you can declare it within a package. It
is an optional part of the program, i.e., if you do not want to declare
any package, then there will be no problem with it, and you will not
get any errors. Here, the package is a keyword that tells the compiler
that package has been created.
It is declared as:
package package_name;
Import statements This line indicates that if you want to use a class of another package,
then you can do this by importing it directly into your program.
Example:
import calc.add;
Interface statement Interfaces are like a class that includes a group of method declarations.
It's an optional section and can be used when programmers want to
implement multiple inheritances within a program.
Class Definition A Java program may contain several class definitions. Classes are the
main and essential elements of any Java program.
Main Method Class Every Java stand-alone program requires the main method as the
Object-Oriented Programming
Here is an example of the Hello Java program to understand the class structure and
features. There are a few lines in the program, and the primary task of the program is to
print Hello Java text on the screen.
Example:
Program Output:
Hello Java
Here are the most important points to note about the Java programs:
You have to keep in mind that, Java code is case sensitive.
To write a Java program, you must have to define class first.
The name of the class in Java (which holds the main method) is the name of the
Java program, and the same name will be given in the filename. As mentioned
above in the sample program; The name of the class is "Hello" in which the main
method is, then this file will be named "Hello.Java".
public static void main When the main method is declared public, it means that it
can also be used by code outside of its class, due to which
the main method is declared public.
The word static used when we want to access a method
without creating its object, as we call the main
method, before creating any class objects.
The word void indicates that a method does not return a
value. main() is declared as void because it does not return a
value.
main is a method; this is a starting point of a Java program.
You will notice that the main method code has been moved to some
spaces left. It is called indentation which used to make a program
easier to read and understand.
String[] args It is an array where each element of it is a string, which has
been named as "args". If your Java program is run through
the console, you can pass the input parameter, and main()
method takes it as input.
System.out.println(); This statement is used to print text on the screen as output,
where the system is a predefined class, and out is an object
of the PrintWriter class defined in the system. The
method println prints the text on the screen with a new
line. You can also use print() method instead of println()
method. All Java statement ends with a semicolon.
Java Interfaces / Environment
When we talk about the Java applications, then it works only on those
machines which have JVM.
What is JVM?
JVM, i.e., Java Virtual Machine.
JVM is the engine that drives the Java code.
Mostly in other Programming Languages, compiler produce code for a
particular system but Java compiler produce Bytecode for a Java Virtual
Machine.
When we compile a Java program, then bytecode is generated. Bytecode is
the source code that can be used to run on any platform.
Bytecode is an intermediary language between Java source and the host
system.
It is the medium which compiles Java code to bytecode which gets
interpreted on a different machine and hence it makes it Platform/Operating
system independent.
Diagram of JVM
Object-Oriented Programming
JVM generates a .class(Bytecode) file, and that file can be run in any OS,
but JVM should have in OS because JVM is platform dependent.
Platform Independent
JVM is the main component of Java architecture, and it is the part of the JRE (Java
Runtime Environment).
A program of JVM is written in C Programming Language, and JVM is Operating
System dependent.
JVM is responsible for allocating the necessary memory needed by the Java program.
JVM is responsible for deallocating memory space.
It contains a set of supporting libraries in combination with core classes and various other
files that are used by JVM at runtime. JRE is a part of JDK (Java Development
Toolkit) but can be downloaded separately.
You need JRE to execute your program, which includes two things:
JVM
Java Library
o Static - Functions that are required at compile time.
o Dynamic - Functions that are required at runtime and not at compile
time.
In detail, the JRE consists of various components; these are listed below:
In this lesson, Teaching and learning is mediated through the use of technology like print,
audio, video and the internet. Students interact with their instructors and each other through
virtual classrooms, email, and web conferencing. For the online modality, the Virtual Classroom
shall be used for the purpose of delivering a lecture and allowing a synchronous discussion with
the students. For the remote modality, Self-directed (SeDI) a learning management system shall
be used to upload the module and to allow asynchronous discussion with the students. This will
also be used as platform for the submission of the requirements.
Object-Oriented Programming
ASSESSMENT TASK
References:
1. https://www.programiz.com/java-programming
2. https://www.javatpoint.com
3. https://beginnersbook.com/2017
4. https://www.w3schools.com/java
5. https://www.geeksforgeeks.org
6. https://www.tutorialspoint.com/java