0% found this document useful (0 votes)
7 views

Introduction To Java

Java

Uploaded by

Anusha B
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Introduction To Java

Java

Uploaded by

Anusha B
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

Java Chapter -2: Introduction to Java

History of Java
James Gosling initiated Java language project in June 1991 for use in one of his many set-top box
projects. The language, initially called ‘Oak’ after an oak tree that stood outside Gosling's office,
also went by the name ‘Green’ and ended up later being renamed as Java, from a list of random
words.
Sun released the first public implementation as Java 1.0 in 1995. It promised to Write Once, Run
Anywhere (WORA), providing no-cost run-times on popular platforms.
On 13 November 2006, Sun released much of Java as free and open source software under the
terms of the GNU General Public License (GPL).
On 8 May 2007, Sun finished the process, making all of Java's core code free and open-source,
aside from a small portion of code to which Sun did not hold the copyright.
Java was started as a project called "Oak" by James Gosling in June 1991. Gosling's goals were
to implement a virtual machine and a language that had a familiar C-like notation but with
greater uniformity and simplicity than C/C++. The first public implementation was Java 1.0 in
1995. It made the promise of "Write Once, Run Anywhere", with free runtimes on popular
platforms. It was fairly secure and its security was configurable, allowing for network and file
access to be limited. The major web browsers soon incorporated it into their standard
configurations in a secure "applet" configuration. popular quickly. New versions for large and
small platforms (J2EE and J2ME) soon were designed with the advent of "Java 2". Sun has not
announced any plans for a "Java 3".
In 1997, Sun approached the ISO/IEC JTC1 standards body and later the Ecma International to
formalize Java, but it soon withdrew from the process. Java remains a proprietary de facto
standard that is controlled through the Java Community Process. Sun makes most of its Java
implementations available without charge, with revenue being generated by specialized
products such as the Java Enterprise System. Sun distinguishes between its Software
Development Kit (SDK) and Runtime Environment (JRE) which is a subset of the SDK, the
primary distinction being that in the JRE the compiler is not present.

Java – feature:
Following are the notable features of Java:
Object Oriented
In Java, everything is an Object. Java can be easily extended since it is based on the
Object model.
Platform Independent
Unlike many other programming languages including C and C++, when Java is compiled,
it is not compiled into platform specific machine, rather into platform-independent byte

TLP
Java Chapter -2: Introduction to Java

code. This byte code is distributed over the web and interpreted by the Virtual Machine
(JVM) on whichever platform it is being run on.
Simple
Java is designed to be easy to learn. If you understand the basic concept of OOP Java,
it would be easy to master.
Secure
With Java's secure feature it enables to develop virus-free, tamper-free systems.
Authentication techniques are based on public-key encryption.
Architecture-neutral
Java compiler generates an architecture-neutral object file format, which makes the
compiled code executable on many processors, with the presence of Java runtime
system.
Portable
Being architecture-neutral and having no implementation dependent aspects of the
specification makes Java portable. The compiler in Java is written in ANSI C with a clean
portability boundary, which is a POSIX subset.
Robust
Java makes an effort to eliminate error-prone situations by emphasizing mainly on
compile time error checking and runtime checking.
Multithreaded
With Java's multithreaded feature it is possible to write programs that can perform many
tasks simultaneously. This design feature allows the developers to construct interactive
applications that can run smoothly.
Interpreted
Java byte code is translated on the fly to native machine instructions and is not stored
anywhere. The development process is more rapid and analytical since the linking is an
incremental and light-weight process.
High Performance
With the use of Just-In-Time compilers, Java enables high performance.
Distributed
Java is designed for the distributed environment of the internet.
Dynamic
Java is considered to be more dynamic than C or C++ since it is designed to adapt to an
evolving environment. Java programs can carry an extensive amount of run-time
information that can be used to verify and resolve accesses to objects at run-time.

TLP
Java Chapter -2: Introduction to Java

Difference between Java and C++ :

There are many differences and similarities between the C++


programming language and Java. A list of top differences between C++ and
Java are given below:

Comparison Index C++ Java

Platform- C++ is platform- Java is platform-


independent dependent. independent.

Mainly used C++ is mainly used Java is mainly used


for for system for application
programming. programming. It is
widely used in
window, web-
based, enterprise
and mobile
applications.

Design Goal C++ was designed Java was designed


for systems and and created as an
applications interpreter for
programming. It printing systems
was an extension but later extended
of C programming as a support
language. network
computing. It was
designed with a
goal of being easy
to use and

TLP
Java Chapter -2: Introduction to Java

accessible to a
broader audience.

Goto C++ supports Java doesn't


the goto statement. support the goto
statement.

Multiple C++ supports Java doesn't


inheritance multiple support multiple
inheritance. inheritance through
class. It can be
achieved
by interfaces in
java.

Operator C++ Java doesn't


Overloading supports operator support operator
overloading. overloading.

Pointers C++ Java supports


supports pointers. pointer internally.
You can write However, you can't
pointer program in write the pointer
C++. program in java. It
means java has
restricted pointer
support in java.

TLP
Java Chapter -2: Introduction to Java

Compiler and C++ uses compiler Java uses compiler


Interpreter only. C++ is and interpreter
compiled and run both. Java source
using the compiler code is converted
which converts into bytecode at
source code into compilation time.
machine code so, The interpreter
C++ is platform executes this
dependent. bytecode at
runtime and
produces output.
Java is interpreted
that is why it is
platform
independent.

Call by Value C++ supports both Java supports call


and Call by call by value and by value only.
reference call by reference. There is no call by
reference in java.

Structure and C++ supports Java doesn't


Union structures and support structures
unions. and unions.

Thread C++ doesn't have Java has built-


Support built-in support for in thread support.
threads. It relies on

TLP
Java Chapter -2: Introduction to Java

third-party libraries
for thread support.

Documentation C++ doesn't Java supports


comment support documentation
documentation comment (/** ...
comment. */) to create
documentation for
java source code.

Virtual C++ supports Java has no virtual


Keyword virtual keyword so keyword. We can
that we can decide override all non-
whether or not static methods by
override a function. default. In other
words, non-static
methods are virtual
by default.

unsigned right C++ doesn't Java supports


shift >>> support >>> unsigned right shift
operator. >>> operator that
fills zero at the top
for the negative
numbers. For
positive numbers,
it works same like
>> operator.

TLP
Java Chapter -2: Introduction to Java

Inheritance C++ creates a new Java uses a single


Tree inheritance tree inheritance tree
always. always because all
classes are the
child of Object
class in java. The
object class is the
root of
the inheritance tree
in java.

Hardware C++ is nearer to Java is not so


hardware. interactive with
hardware.

Object- C++ is an object- Java is also


oriented oriented language. an object-
However, in C oriented language.
language, single However,
root hierarchy is everything (except
not possible. fundamental types)
is an object in
Java. It is a single
root hierarchy as
everything gets
derived from
java.lang.Object.

TLP
Java Chapter -2: Introduction to Java

Note
o Java doesn't support default arguments like C++.

o Java does not support header files like C++. Java uses the import keyword to
include different classes and methods.

Difference between Java and C :

Sr. Key Java C


No.

Introduced Java was developed after C as On other hand C was introduced


compared on introducing year.It before Java and was developed by
1
was developed by James Gosling Dennis M. Ritchie between 1969
in 1995. and 1973.

Type Java is a high level language and On other hand C is a middle-level


is more data oriented also language and is more procedure-
2 known globally as Object- oriented also known globally as
Oriented language. Procedural Programming
Language.

Compilation Upto some extent it could be On other hand C is a compiled


stated as there is no compilation language that is it converts the
in Java as it is an Interpreted code into machine language so
language that is in Java, the code that it could be understood by the
3
is first transformed into machine or system.
bytecode and that bytecode is
then executed by the JVM (Java
Virtual Machine).

Functional As already mentioned Java is an On other hand C is a Procedural


Units Object Oriented language and Programming Language and hence
4
hence has Objects as the has functions as the functional
functional units. units.

TLP
Java Chapter -2: Introduction to Java

Sr. Key Java C


No.

Inheritance Along with the other features of On other hand C does not
and OOPs Java also contains the supports Inheritance which is very
Threading property of Inheritance which is useful for code re usability.Thus C
very useful in code reuse is not preferred when one has to
5
ability.Also Java supports relate the things according to the
concept of Threading. real world as per inheritance
relation.Also C does not supports
Threading.

TLP
Java Chapter -2: Introduction to Java

Java and internet


Java is an object oriented language and a very simple language. Because it has no space for
complexities. At the initial stages of its development it was called as OAK. OAK was designed for
handling set up boxes and devices. But later new features were added to it and it was renamed as
Java. Java became a general purpose language that had many features to support it as the internet
language. Few of the features that favors it to be an internet language are:
Cross Platform Compatibility: The java source files (java files with .java extension) after
compilation generates the bytecode (the files with .class extension) which is further converted into
the machine code by the interpreter. The byte code once generated can execute on any machine
having a JVM. Every operating system has it's unique Java Virtual Machine (JVM) and the Java
Runtime Environment (JRE).
Support to Internet Protocols: Java has a rich variety of classes that abstracts the Internet
protocols like HTTP , FTP, IP, TCP-IP, SMTP, DNS etc .
Support to HTML: Most of the programming languages that are used for web application uses the
html pages as a view to interact with the user. Java programming language provide it's support to
html. For example. Recently the extension package jipxhtml is developed in java to parse and
create the html 4.0 documents.
Support to Java Reflection APIs: To map the functionalities, Java Reflection APIs provides the
mechanism to retrieve the values from respective fields and accordingly creates the java objects.
These objects enables to invoke methods to achieve the desired functionality.
Support to XML parsing: Java has JAXP-APIs to read the xml data and create the xml document
using different xml parsers like DOM and SAX. These APIs provides mechanism to share data
among different applications over the internet.
Support to Web Services : Java has a rich variety of APIs to use xml technology in diverse
applications that supports N-Tiered Enterprise applications over the internet. Features like JAXB ,
JAXM, JAX-RPC , JAXR etc enables to implement web services in java applications. It makes java
a most suited internet language.
Support to java enabled Mobile devices: Java programming language is made in such a way so
that it is compatible with mobile devices also. Java language also works with any java enabled
mobile devices that support MIDP 1.0/2.0 including the symbian OS mobile devices.
Support to Personal Digital Assistants: Java language is compatible with Personal Java 1.1 such
as chaiVM, Jeode, CrEME, and JV-Lite2 or with all the later version and it also support PDAs like
HP/Compaq, iPAQ, Fujitsu-Siemens Pocket Loox and SimPad, HHP, NEC, Samsung, Sharp
Electronics, Toshiba, psion m5, and any other device with Windows CE/Pocket PC
2002/2003/2005).

Java environment:
A Java™ runtime environment (JRE) is a set of components to create and run a Java
application. A JRE is part of a Java development kit (JDK).

TLP
Java Chapter -2: Introduction to Java

A JRE is made up of a Java virtual machine (JVM), Java class libraries, and the Java class
loader. JDKs are used to develop Java software; JREs provide programming tools and
deployment technologies; and JVMs execute Java programs.

How does a Java runtime environment work?


A Java runtime environment runs on top of the OS and provides additional Java-specific
resources. It abstracts the OS and creates a consistent platform on which to run and deploy
Java applications. The 3 components of the JRE work together within this environment to
successfully run a Java application.

The Java class libraries contain collections of prewritten code that can be called when needed.
The class loader connects class libraries with the JVM and loads them into the JVM while the
program is running. The JVM then executes the code.

Local Environment Setup


If you are still willing to set up your environment for Java programming language, then this section
guides you on how to download and set up Java on your machine. Following are the steps to set
up the environment.

Java SE is freely available from the link Download Java. You can download a version based
on your operating system.
Follow the instructions to download Java and run the .exe to install Java on your machine. Once
you installed Java on your machine, you will need to set environment variables to point to correct
installation directories −

Setting Up the Path for Windows


Assuming you have installed Java in c:\Program Files\java\jdk directory −
o Right-click on 'My Computer' and select 'Properties'.

o Click the 'Environment variables' button under the 'Advanced' tab.

o Now, alter the 'Path' variable so that it also contains the path to the Java executable.
Example, if the path is currently set to 'C:\WINDOWS\SYSTEM32', then change your
path to read 'C:\WINDOWS\SYSTEM32;c:\Program Files\java\jdk\bin'.

Setting Up the Path for Linux, UNIX, Solaris, FreeBSD


Environment variable PATH should be set to point to where the Java binaries have been
installed. Refer to your shell documentation, if you have trouble doing this.
Example, if you use bash as your shell, then you would add the following line to the end of your
'.bashrc: export PATH = /path/to/java:$PATH'

Popular Java Editors


To write your Java programs, you will need a text editor. There are even more sophisticated
IDEs available in the market. But for now, you can consider one of the following −

TLP
Java Chapter -2: Introduction to Java

• Notepad − On Windows machine, you can use any simple text editor like Notepad
(Recommended for this tutorial), TextPad.
• Netbeans − A Java IDE that is open-source and free which can be downloaded
from https://www.netbeans.org/index.html.
• Eclipse − A Java IDE developed by the eclipse open-source community and can be
downloaded from https://www.eclipse.org/

Java virtual machine:

The Java Virtual Machine is a program whose purpose is to execute other programs. It's a
simple idea that also stands as one of our greatest examples of coding kung fu. The JVM upset
the status quo for its time, and continues to support programming innovation today.

What the JVM is used for

The JVM has two primary functions: to allow Java programs to run on any device or operating
system (known as the "Write once, run anywhere" principle), and to manage and optimize
program memory. When Java was released in 1995, all computer programs were written to a
specific operating system, and program memory was managed by the software developer. So
the JVM was a revelation.

WHAT IS: JAVA


By Matthew Tyson
JAN 17, 2020 12:32 PM

TLP
Java Chapter -2: Introduction to Java

What is the JVM? Introducing the Java Virtual Machine


The JVM manages system memory and provides a portable execution
environment for Java-based applications

TLP
Java Chapter -2: Introduction to Java

IDG / Oracle / Vasabii / Getty Images

TLP
Java Chapter -2: Introduction to Java

The Java Virtual Machine is a program whose purpose is to execute other programs. It's a
simple idea that also stands as one of our greatest examples of coding kung fu. The JVM
upset the status quo for its time, and continues to support programming innovation today.

What the JVM is used for

The JVM has two primary functions: to allow Java programs to run on any device or
operating system (known as the "Write once, run anywhere" principle), and to manage and
optimize program memory. When Java was released in 1995, all computer programs were
written to a specific operating system, and program memory was managed by the software
developer. So the JVM was a revelation.

TLP
Java Chapter -2: Introduction to Java

JavaWorld / IDG

Figure 1: High-level view of the JVM

Having a technical definition for the JVM is useful, and there's also an everyday way that
software developers think about it. Let's break those down:

• Technical definition: The JVM is the specification for a software program that executes
code and provides the runtime environment for that code.
• Everyday definition: The JVM is how we run our Java programs. We configure the
JVM's settings and then rely on it to manage program resources during execution.

When developers talk about the JVM, we usually mean the process running on a machine,
especially a server, that represents and controls resource usage for a Java app. Contrast
this to the JVM specification, which describes the requirements for building a program that
performs these tasks.

TLP
Java Chapter -2: Introduction to Java

JDK vs JRE vs JVM

What is JDK?
JDK is a software development environment used for making applets and Java applications. The
full form of JDK is Java Development Kit. Java developers can use it on Windows, macOS,
Solaris, and Linux. JDK helps them to code and run Java programs. It is possible to install more
than one JDK version on the same computer.

What is JRE?
JRE is a piece of a software which is designed to run other software. It contains the class
libraries, loader class, and JVM. In simple terms, if you want to run Java program you need JRE.
If you are not a programmer, you don't need to install JDK, but just JRE to run Java programs.
Though, all JDK versions comes bundled with Java Runtime Environment, so you do not need to
download and install the JRE separately in your PC. The full form of JRE is Java Runtime
Environment.

What is JVM?
JVM is an engine that provides a runtime environment to drive the Java Code or applications. It
converts Java bytecode into machine language. JVM is a part of Java Run Environment (JRE). It
cannot be separately downloaded and installed. To install JVM, you need to install JRE. The full
form of JVM is Java Virtual Machine.
In many other programming languages, the compiler produces machine code for a specific
system. However, Java compiler produces code for a virtual machine which is called as JVM.

Difference between JDK, JRE and JVM


Here are the major differences between JDK vs. JRE vs. JVM:

JDK JRE JVM

The full form The full form The full form


of JDK is of JRE is Java of JVM is
Java Runtime Java Virtual
Development Environment. Machine.
Kit.

JDK is a It is a JVM executes


software software Java byte
development bundle which code and

TLP
Java Chapter -2: Introduction to Java

kit to provides provides an


develop Java class environment
applications libraries with for executing
in Java. necessary it.
components
to run Java
code.

JDK is JRE is also JVM is


platform platform platform-
dependent. dependent. independent.

It contains It contains Software


tools for class libraries development
developing, and other tools are not
debugging, supporting included in
and files that JVM JVM.
monitoring requires to
java code. execute the
program.

It is the It is the JVM is a


superset of subset of subset of
JRE JDK. JRE.

The JDK The JRE is It is the Java


enables the part of platform
developers Java that component
to create creates the that executes
Java JVM. source code.
programs
that can be
executed and

TLP
Java Chapter -2: Introduction to Java

run by the
JRE and JVM.

JDK comes JRE only JVM bundled


with the contain in both
installer. environment software JDK
to execute and JRE
source code.

BLOG

Main

Blog

Mobile Development

Benefits and Drawbacks of Java

Jan 22, 2020

TLP
Java Chapter -2: Introduction to Java

Benefits and Drawbacks of Java

Contents

o Introduction

o Benefits of Java

o Drawbacks of Java

o Final Words: So When Should I Use Java?

TLP
Java Chapter -2: Introduction to Java

If you finally made up your mind to go for software development, you definitely have to weigh all
the pros and cons of IT outsourcing and offshoring. And the prior step these thoughts is another
vital step – choosing the right technology stack for the project. So if you are still in two minds
whether Java outsourcing is something you need or maybe it’s better to opt for some other
technology, it might be because you lack some details to get the full picture. We gathered the
pros and cons of Java here to help you.

Introduction
If somebody asks you to name 5 technologies that you know, Java will probably be among
them. And actually, if we take the Stack Overflow’s Developer survey conducted in 2019, more
than 53% of developers named Java as their most loved language.
One of the grounds for such admiration is not surprising since Java itself is much more than just
a technology. That’s an entire complex of tools which embraces nearly everything one needs for
Java development. So it consists of the elements listed below:

1. Java Development Kit (JDK) – that’s the first thing a developer downloads to start any
development on Java. JDK itself is a software package which comprises the compiler,
documentation, utilities and Java Runtime Environment (JRE).
2. Java Runtime Environment – a software layer running on top of a computer's operating
system. It basically includes Java Virtual Machine (JVM) and the standard Java Class Library.
JRE merges the code with the required libraries, then launches the JVM (a tool converting Java
bytecode into machine code) for the execution of the code. Plus it ensures the dependencies to
be available to the Java programs you develop.
3. Integrated Development Environment (IDE) – the app which allows its user to run, edit and
compile the code. A number of IDEs have features like syntax highlighting and code completion,
which eases the process of coding. If we take the top 3 IDEs which Java developers adore, they
will be IntelliJ IDEA, Eclipse, and NetBeans.
Frankly speaking, Java is almost everywhere around. If your smartphone has the Android
platform then its full of Java, as that’s the main technology used for Android development. Still
not too convincing? Then here are some more examples: Big Data, web apps and state
websites, scientific computing – all of them mostly have Java “inside”. And initially, mobile
games also were written in Java (we’re talking about the period of the 2000s before the
smartphones were invented).
As we are through with the introduction part, we shall continue with the gist of our
“investigation”: the advantages and disadvantages of Java.

Benefits of Java
Until 2016 (the year when Kotlin had its first official stable release) Java was irreplaceable in
Android development and this happened for a very simple reason: Java was the only official
programming language for Android development. Though nowadays it has a competitor named
Kotlin, still today there’s a great variety of options for web development using Java. Despite the
high competition with other technologies, Java doesn’t fall behind and still has a number of pros
to offer which can persuade one to make the choice in its favour.

1. It’s a high-level language. This notion implies a programming language to be much like
human language rather than a machine one. Consequently, it should be easy and simple to

TLP
Java Chapter -2: Introduction to Java

write, read and maintain.


2. Its stability. The solutions created with the help of Java are said to be stable. That partly
happens so because a new version of Java with new features is released every day with
advanced features.
3. It’s object-oriented. Since Java belongs to object-oriented programming, it allows a
developer to write typical programs and to reuse the code. So one can state classes, generate
objects inside classes, work and maintain interaction between two objects.
4. Its maintenance is fairly cheap. The nature of work of a Java program does not rely upon
some unique hardware infrastructure, so it’s possible to run the server in any machine. Result:
it’s inexpensive to maintain.
5. It’s security. Java is the first technology which provided security as an integral part of the
design. JVM possesses a special identifier which detects the bytecode and checks prior to
running.
6. It’s multithreaded. Internally a Java program can carry out several tasks at one time.
7. Distributed computing. That’s a method when several computers work together in a
network. That’s definitely an advantage as it allows to develop apps on networks which can
contribute to both the functionality of application and data.
8. It’s portable (platform-independent). The portability implies that a developer has to write
just one code once and the program can be started on any platform. The only condition is that
this platform should support JVM.
9. It’s robust. Java is said to be a most reliable and powerful language. Its compilers manage
to identify every single type of error in your code. Besides that, Java has such great features as
exception handling and garbage collection which also prove Java to be reliable.

Drawbacks of Java
Unfortunately, like any technology, Java has not only advantages but also a bunch of
disadvantages. The several significant cons of Java are:

1. Java’s performance. If we compare Java programs to those written in С or C++ which are
natively compiled, it’s easily noticed that they are much slower.
2. Its memory. In Java, the memory is managed through garbage collection, so anytime the
garbage collector works, it deteriorates the way the app performs. The main reason for that is
that the garbage collector works only when all other threads are not working.
3. Costs for the commercial license. Since 2019 Oracle expects the users to pay for Java
Standard Edition 8 when used for purposes such as business, commerce and production. So
when you need updates and bug fixing, you’ll be charged by the number of users you have or
for the processor. It hurts a lot when you start counting the new costs.
4. The look is not native (desktop). Programmers utilize a variety of tools special for each
language in order to build the graphical user interface, GUI for short. Of course, we shouldn’t
forget about Android Studio, which was initially designed for Android mobile development so the
apps both feel and look native. Therefore, as soon as the conversation goes to the user
interface of desktop programs, Java is certainly lagging behind and you’ll have to conduct really
thorough research to find a tool that will be just fine to create your graphical user interface.
5. Java’s verbosity makes the code rather complicated. Java implies that one needs to use
many words used as it’s quite similar to the natural language of humans a lot. The developers
almost literally write down their commands and thoughts so the code is drastically huge
(especially when compared to Python).

TLP
Java Chapter -2: Introduction to Java

TLP

You might also like