I Bca Java Theory Unit I Part 2
I Bca Java Theory Unit I Part 2
Applications of OOP
The basic thought behind object-oriented language is to make an object by combining data
and functions as a single unit and then operate on that data.
In procedural approach, the focus is on business process and the data needed to support the
process.
For example, in the last decade, a problem bothered every programmer, popularly known as
the Y2K problem. Everybody related to the computer industry was afraid of what will happen
past midnight 31 December 1999. The problem arises due to the writing convention of the
year attribute. In early programming days, a programmer wrote a year in two digits, so there
was a problem to distinguish the year 1900 from 2000 because if we write only the last two
digits of a year, the computer cannot differentiate between the two. Nobody perceived this
problem and used the date and year code as and when required, thus aggravating the problem.
The solution to this problem was to analyze multiple lines of codes everywhere and change
the year to four digits rather than two. It seems simple to change the state variable of year but
analyzing a code of several thousands of lines to find how many times you have used date in
your code is not an easy task.
If object-oriented programming language had been used, we could have created a Date class
with day, month, and year attributes in it. Wherever the date functionality would be required,
a Date object would be created and used.
At a later point of time, if a change is required, for example, the year of Date class needs to
be changed to four digits, then this change would be incorporated in the class only and this
change would automatically be reflected in all the objects of the Date class whenever they are
created and used.
So, the change would have to be done at one place only, i.e., the class and wherever the
objects of the class are being used, the changes would be reflected automatically. There is no
need to analyze the whole code and change it.
In OOP, we access data with the help of objects, so it is very easy to overcome a problem
without modifying the whole system.
History of Java
It is often believed that the Java was developed specifically for the World Wide Web.
Java as it was initially developed was intended for the Web. However, it was improved to be
a standard programming language for the Internet application.
Bill Joy, the Vice President at Sun Micro systems, was thought to be the main person to
conceive the idea of a programming language that later became Java. In late 1970s, Bill Joy
wanted to design a language that could contain the best features of languages like MESA and
C. He found that C++ was inefficient for rewriting Unix operating system. In 1991, it was
this desire to invent a better programming tool that propelled Joy in the direction of Sun’s
mammoth project called as the ‘ Stealth Project.’
This name was given by Scott McNealy, Sun’s president. In January 1991, a formal team of
persons like Bill Joy, James Gosling, Mike Sheradin, Patrick Naughton (formerly the project
leader of Sun’s Open Windows user environment), and several other individuals met in
Aspen, Colorado for the first time to plan for the Stealth Project.
Stealth Project was all about developing consumer electronic devices that could all be
centrally controlled and programmed from a handheld remote control like device. James
Gosling was made responsible for suggesting a proper programming language for the project.
Initially he thought of using C++, but soon after was convinced about the inadequacy of C++
for this particular project. He took the first step towards the development of an independent
language that would fit the project objectives by extending and modifying C++.
The idea of naming the language as ‘Oak’ struck Gosling while staring at an oak tree outside
his office window. Unfortunately, this name had already been patented by some other
programming language. Owing to the fear of copyright violation, the name ‘Oak’ was
dropped. The team struggled to find a proper name for the language for many days. After so
many brainstorming sessions, one day finally a thought struck their mind during a trip to the
local coffee shop as recalled by Gosling. The term ‘Java’ in USA is generally a slang used for
coffee. Java is also the name of a coffee produced on the islands of Java in Indonesia.
There are some other views also towards the naming convention used for naming the
language as Java. One of it speculates that the name Java came from several individuals
involved in the project: James Gosling, Arthur Van Goff, Andy Bechtolsheim.
Java Essentials
Java is a platform-independent, object-oriented programming language. Java encompasses
the following features:
A High-level Language Java is a high-level language that looks very similar to C and
C++ but offers many unique features of its own.
Java Bytecode Bytecode in Java is an intermediate code generated by the compiler,
such as Sun’s javac, that is executed by the JVM.
Java Virtual Machine (JVM) JVM acts as an interpreter for the bytecode, which
takes bytecodes as input and executes it as if it was a physical process executing
machine code.
Tools such as javac (compiler), java (interpreter), and others are provided in a bundle,
popularly known as Java Development Kit (JDK). JDK comes in many versions (enhanced in
each version) and is different for different platforms such as Windows and Linux. A runtime
bundle is also provided as a part of JDK (popularly known as Java Runtime Environment).