1. INTRODUCTION OF JAVA
Java is an object oriented programming language. Originally called Oak, Java was designed
for the development of software for consumer electronic devices like TVs, VCRs, toaster etc.
Although Java was modeled after C and C++ languages, it differs form C and C++ in many
ways.
The Four Types of Java Applications
The following are the four types of applications you can build in Java:
Applets (mini applications)
GUI applications
Command line applications
Packages (libraries)
Java is a general purpose; object oriented programming language developed by Sun
Microsystems of USA in 1991.
JAVA FEATURES
The inventers of Java wanted to design a language which could offer solutions to some of the
problems encountered in modern programming. Sun Micro-systems officially describe Java
with the following attributes:
Simple & Familiar
Secure
Compiled & Interpreted
Platform-independent & Portable
Object-oriented
Robust
Distributed
Multithreaded
High performance
Dynamic & Extensible
SIMPLE AND FAMILIAR
Java was designed to be easy for professional programmer to learn and use
effectively.
Java inherits the C/C++ syntax and many of the OOPs features of C++. In Java, there are
a small number of clearly defined ways to accomplish a given task.
SECURE.
Java systems not only verify all memory access but also ensure that no viruses are
communicated with an applet.
The absence of pointers in Java ensures that programs can not gain access to memory
without proper authorization.
COMPILED AND INTERPRETED
2. Usually a computer language is either compiled or interpreted. Java combines both compiled
& interpreted, these approaches thus making Java a two stage system.
1. COMPILATION
Java compiler translates source code into bytecode instructions.
Bytecode- Bytecode is a highly optimized set of instructions designed to be executed by
the Java run time system, which is called the Java virtual machine (JVM).
2. INTERPRETATION
JVM is an interpreter for bytecode. Java program is executed by the JVM. It generates
machine code that can be directly executed by the machine.
PLATFORM INDEPENDENT & PORTABLE
Java programs can be easily moved from one computer system to another, anywhere and
anytime.
Changes and upgrades in operating system processor and system resources will not force
any changes in java programs.
This is the reason by Java has become a popular language on internet. We can download a
Java Applet from a remote computer onto our local system via Internet & execute it
locally.
Java compiler generates bytecode instructions that can be implemented on any machine.
JAVA IS OBJECT-ORIENTED
Java is a true object-oriented language. Almost everything in java is an object.All
program code and data reside within object and classes. Therefore, it's part of a family of
languages that focuses on defining data as objects and the methods that may be applied to
those objects.
Many OOP languages support multiple inheritance, which can sometimes lead to
confusion or unnecessary complications. Java doesn't. Java supports only single
inheritance. Java allows you to create totally abstract classes known as interfaces.
Polymorphism.
Abstraction.
Encapsulation.
ROBUST
Java is a robust language.
It provides many safeguards to ensure reliable code.
Java also incorporates the concept of exception handling which captures series errors &
eliminates any risk of crashing the system.
DISTRIBUTED
Java is designed as a distributed language for creating application on network .
It has the ability to share both data and programs.
Java has revived interfaces in a package called Remote Method Invocation (RMI). This
feature brings an unparalleled level of abstraction to client/server programing.
3. MULTITHREADED & INTERRACTIVE
Multithreaded means handling multiple tasks simultaneously .
Java supports multithreaded programming We need not wait for the application to finish
one task before beginning another.
Java runtime comes with tools that support multiproccess synchronization & construct
smoothly running interactive systems.
DYNAMIC & EXTENSIBLE
Java is a dynamic language.
Java is capable of dynamically linking in new class libraries, methods and objects.
Java can also determine the type of class through a query, making it possible to either
dynamically link or abort depending on the response.
HIGH PERFORMANCE
Java performance is impressive for an interpreted language, mainly due to the use of
intermediate bytecode.
The Java bytecode was carefully designed so that it would be easy to translate directly
into native machine code for very high performance by using a just-in-time compiler.
HOW JAVA DIFFER FROM C AND C++
Java is a true object oriented language while c++ is basically C with object oriented
extension.
Java does not support operator overloading.
Java adds new operators such as instanceof and >>>
Java adds labbelled break and continue statements.
Java does not contain the data types stuct, union and enum.
Java does not have any preprocessor like #define , #include.
Java does not have template classes as in C++.
Java does not support multiple inheritances of classes. This is accomplished using a
new feature called “interface”.
Java does not support global variables. Every method and variable is declared within a
class.
Java does not use pointers.
Java has replaced the destructor function with a finalize () function.
There are no header files in Java.
Steps to set path
1. Open command prompt
2. Copy the path of jdk: c:>program filesjavajdk1.8.0_181bin
4. 3. Enter into your folder where your file is stored by using CD
command.
4. path= paste copied path like c:>program
filesjavajdk1.8.0_181bin
HelloWorld! simple Java Programs
public class HelloWorld
{
public static void main(String args[])
{
System.out.println("Hello World!!");
}
}
How to start working with Java
1. Create the File
The first step to create the HelloWorld application is to copy the text into a file called
HelloWorld.java using your favorite text editor like notepad.
2. Compile the Code
To compile the program, you need to first install the JDK. Then, use the program javac
included with the JDK to convert the text. To run javac, on a Macintosh drag the source file
over the javac icon at a command prompt. The javac program creates a file called
HelloWorld.class from the HelloWorld.java file. Inside this file (HelloWorld.class) is text
known as bytecodes which can be run by the Java interpreter.
javac HelloWorld.java
3. Run the Programa
Now that you have compiled the program, you can run it by typing at the command prompt:
java HelloWorld
After you do this, the computer should print to the screen
Hello World!!