What Is Java Lecture1
What Is Java Lecture1
Application
According to Sun, 3 billion devices run Java. There are many devices where Java is currently
used. Some of them are as follows:
1) Standalone 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.
3) Enterprise Application
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.
It includes core topics like OOPs, String, Regex, Exception, Inner classes, Multithreading,
I/O Stream, Networking, AWT, Swing, Reflection, Collection, etc.
4) JavaFX
It is used to develop rich internet applications. It uses a light-weight user interface API(GUI
toolkit such as checkbox, radio button).
The history of Java is very interesting. Java was originally designed for interactive
television, but it was too advanced technology for the digital cable television industry at the
time. The history of java starts with Green Team. The developers of Java want to make it
simple because it has to work on electronics devices where less memory is available.
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.
However, it was suited for internet programming. Later, Java technology was incorporated
by Netscape.
The principles for creating Java programming were "Simple, Robust, Portable, Platform-
independent, Secured, High Performance, Multithreaded, Architecture Neutral, Object-
Oriented, Interpreted and Dynamic".
2) Originally designed for small, embedded systems in electronic appliances like set-top
boxes.
3) Firstly, it was called "Greentalk" by James Gosling, and file extension was .gt.
4) After that, it was called Oak and was developed as a part of the Green project.
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.
8) Java is an island of Indonesia where first coffee was produced (called java coffee).
Sun Microsystems was an American company. Sun was endowed in Feburary, 1982.The
institution is most popularly known for the development of JAVA language. It also created
the Solaris Operating System and the File System for Networks. Sun remarkably contributed
in the development of various technologies including RISC, UNIX, client and virtualized
computing. And then in the year 2009 it was declared that Sun will be acquired by Oracle.
11) In 1995, Time magazine called Java one of the Ten Best Products of 1995.
03377634169
Simple
Java is very easy to learn, and its syntax is simple, clean and easy to understand. According
to Sun, Java language is a simple programming language with limited language constructs
o Java syntax is based on C++ (so easier for programmers to learn it after C++).
o Java has removed many complicated and rarely-used features, for example, explicit
pointers, operator overloading, structures, goto statement, multiple inheritance,
header files etc.
o There is no need to remove unreferenced objects because there is an Automatic
Garbage Collection in Java.
Object-oriented
Java is an object-oriented programming language. Everything in Java is an object. Object-
oriented means we organize our software as a combination of different types of objects that
incorporates both data and behavior.
Object-oriented programming (OOPs) is a methodology that simplifies software
development and maintenance by providing some rules.
Platform Independent
Java is platform independent because it is different from other languages like C, C++, etc.
which are compiled into platform specific machines while Java is a write once, run anywhere
language. platform independent means writing code in one operating system e.g windows
XP and execute it on other platforms e.g unix, linux. A platform is the hardware or software
environment in which a program runs.
There are two types of platforms software-based and hardware-based. Java provides a
software-based platform.
The Java platform differs from most other platforms in the sense that it is a software-based
platform that runs on the top of other hardware-based platforms. It has two components:
1. Runtime Environment
2. API(Application Programming Interface)
Java code can be run on multiple platforms, for example, Windows, Linux, Sun Solaris,
Mac/OS, etc. Java code is compiled by the compiler and converted into bytecode. This
bytecode is a platform-independent code because it can be run on multiple platforms, i.e.,
Write Once and Run Anywhere(WORA).OR Java byte code is not machine dependent i.e. it
can run on any machine with any processor and any operating system.
Different type of JVMS are available for different operating systems such as SUN JVM, Microsoft JVM
and IBM JVM.
Portable
If a program yields the same result on each machine then the program is called portable. Java Programs
are portable, which is the result of Java system independence nature. Java is portable because it
facilitates you to carry the Java bytecode to any platform. It doesn't require any
implementation.
Secured
Java is best known for its security. With Java, we can develop virus-free systems. So virus
threats can be eliminated or minimized by using Java. Java is secured because:
o No explicit pointer
o Java Programs run inside a virtual machine sandbox
o Class loader: Class loader in Java is a part of the Java Runtime Environment (JRE)
which is used to load Java classes into the Java Virtual Machine dynamically. It adds
security by separating the package for the classes of the local file system from those
that are imported from network sources.
o Bytecode Verifier: It checks the code fragments for illegal code that can violate
access right to objects.
o Security Manager: It determines what resources a class can access such as reading
and writing to the local disk.
Java language provides these securities by default. Some security can also be provided by
an application developer explicitly through SSL, JAAS, Cryptography, etc.
Robust
Robust simply means strong. Java program is strong as they do not easily crash like C/C++
program. Java is robust because there are several reasons:
o It uses strong memory management.
o There is a lack of pointers that avoids security problems.
o Most of the C++ programs crash in the middle because of not allocating sufficient
memory or forgetting the memory to be freed by the program. Such problems will
not occur in Java as the user will not care about memory allocation and de-
allocation. There is automatic garbage collection in java which runs on the Java
Virtual Machine to get rid of objects which are not being used by a Java application
anymore.
o Java has excellent in-built exception handling feature which identifies the error and
handle it and the type checking mechanism (high Data type to lower data type) in
Java. All these points make Java robust.
o Exception is an error which occurs at random and abruptly terminates the program
for example loss of data. Overcoming such problem is called exception handling.No
harm will happen, if an exception occurs in Java.
Architecture-neutral
Java is architecture neutral because there are no implementation dependent features, for
example, the size of primitive types is fixed.
In C programming, int data type occupies 2 bytes of memory for 32-bit architecture and 4
bytes of memory for 64-bit architecture. However, it occupies 4 bytes of memory for both
32 and 64-bit architectures in Java.
Distributed
Information can be distributed to various computers on a network with the help of Java
program. Using Java, we can capture information and distribute it to clients; this is possible
as Java can handle protocols like TCP/IP and UDP which are core communication protocols
used in internet.
Java is distributed because it facilitates users to create distributed applications in Java. Java
Distributed applications are applications that can be executed over the network. Java.net
provides built in classes to facilitate the development of distributed applications. RMI and
EJB technologies are used for creating distributed applications. This feature of Java makes
us able to access files by calling the methods from any machine on the internet.
High-performance
Java is both interpreted and compiled language. We use both compiler and interpreter for
execution of Java programs, Interpreter for single statement and compiler for loop
statements, so, Both interpreter and JIT compiler work together to run the program, which
in turn increases the overall performance of Java program. It is still a little bit slower than a
compiled language (e.g., C++).
Multi-threaded
A thread represents an individual process to execute a group of statements. JVM uses
different threads to execute different blocks of code. Creating multiple threads is called
multi-threaded. A thread is like a separate program, executing concurrently. We can write
Java programs that deal with many tasks at once by defining multiple threads. For instance,
You have created a java application via which u can listen a music, watching a video clip
and downloading certain file. It can be done by defining multiple threads for performing
different jobs at the same time.
The main advantage of multi-threading is that it doesn't occupy memory for each thread. It
shares a common memory area. Threads are important for multi-media, Games, Web
applications, etc.
Dynamic
Java is a dynamic language i.e. new class and methods can be linked to the program at run
time, if the program needs them. It supports dynamic loading of classes. It means classes
are loaded on demand. It also supports functions from its native languages, i.e., C and C+
+. Methods from C and C++ language can linked in java program at run time.
Scalability: Java platform can be implemented on wide range of computers with various
levels of recourses from embedded devices to mainframe computers because java is
compact and platform independent.
Mainly used for C++ is mainly used for system Java is mainly used for application
programming. programming. It is widely used in
window, web-based, enterprise and
mobile applications.
Design Goal C++ was designed for systems Java was designed and created as an
and applications programming. interpreter for printing systems but
It was an extension of C later extended as a support network
programming language. computing. It was designed with a goal
of being easy to use and accessible to a
broader audience.
Compiler and C++ uses compiler only. C++ Java uses compiler and interpreter
Interpreter is compiled and run using the both. Java source code is converted
compiler which converts source into bytecode at compilation time. The
code into machine code so, C+ interpreter executes this bytecode at
+ is platform dependent. runtime and produces output. Java is
interpreted that is why it is platform
independent.
Call by Value C++ supports both call by Java supports call by value only. There
and Call by value and call by reference. is no call by reference in java.
reference
Structure and C++ supports structures and Java doesn't support structures and
Union unions. unions.
Virtual Keyword C++ supports virtual keyword Java has no virtual keyword. We can
so that we can decide whether override all non-static methods by
or not override a function. default. In other words, non-static
methods are virtual by default.
unsigned right C++ doesn't support >>> Java supports unsigned right shift >>>
shift >>> operator. operator that fills zero at the top for
the negative numbers. For positive
numbers, it works same like >>
operator.
Inheritance Tree C++ creates a new inheritance Java uses a single inheritance tree
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.
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