Friday, 10 November 2017

Java : Compiling and Executing Java Program

A program has to be converted to a form that Java Virtual Machine can understand, so any computer with a Java Virtual Machine can interpret and run the program. Compiling a Java program means to convert source code into byte code, which are platform independent.

The Java compiler is invoked at the command line as follows:
C:\>javac prg1.java

Executing the program
Once your program is successfully compiled that means converted into byte codes, you can interpret and run application on any Java VM. Interpreting and running a Java program means invoking the Java VM byte code interpreter, which converts the Java byte codes to platform-dependent machine codes so your computer can understand and run the program.
The Java interpreter invoked at command line as follows:
C:\>java prg1.class

And finally you will see output on command line.


Java : Basic JDK Tools

javac :
javac is the compiler for Java Programming language. javac is used to compile .java file. After compiling .java file it will create a .class file that can be run by java command.
Example : c:\>javac prg1.java

java:
java command is used to run java program. Basically java program is there in .class file created from source file (.java).
Example: c:\>java prg1.class

javadoc:
javadoc is a API documentation generator for Java language, that generates documentation in HTML format from Java source code.

appletviewer:
Appletviewer run and debug applets without a web browser. The appletviewer is solid application to test final release Java Programs.

jar:
jar create and manage Java Archive (JAR) files. Jar is package file format that contains class, text, images and sound files for a java application or applet.

jdb:

The Java Debugger.

Monday, 6 November 2017

Java : JDK, JRE and JVM

JDK (Java Development Kit)
JDK is a bundle of software component. JDK is an implementation of either of Java SE, Java EE or Java ME. It includes the Java Runtime Environment (JRE), an interpreter or loader, a compiler i.e. javac, an archiver i.e. jar, a documentation generator i.e. javadoc and other tools to develop java program. JDK provides collection of tools that are used to develop and run java programs.

JRE (Java Runtime Environment)
JRE contains JVM, class libraries and other supporting files. It does not contain any development tools such as compiler, debugger, etc. JRE provides the libraries, the JVM and other components to run applets and applications written in the Java programming language. JVM runs the program and it uses class libraries and other supporting files provided in JRE. If you want to run any Java program, you need to have JRE installed in the system.

JVM (Java Virtual Machine)
JVM is an abstract machine. It is a specification that provides runtime environment in which java byte code can be executed.
JVMs are available for many hardware and software platforms. JVM is used to execute Java applications. The Java compiler, javac outputs bytecodes and puts them into a .class file. The JVM then interprets these bytecode, which can then be executed by any JVM implementation, thus providing Java’s cross-platform portability. 

Java : Java Editions

JDK 1.0
Code name Oak and released on January 23, 1996
JDK 1.1
Released on February 19, 1997

J2SE 1.2
Code name Playground and released on December , 1998

J2SE 1.3
Code name Kestrel and released on May 8, 2000

J2SE 1.4
Code name Merlin and released on February 6, 2002

J2SE 5.0
Code name Tiger and released on September 30, 2004

J2SE 6
Code name Mustang and released on December 11, 2006

J2SE 7
Code name Dolphin and released on July 28, 2011

J2SE 8
Code name Spider and released on March 18, 2014

J2SE 9
Released on September 21, 2017

Sunday, 5 November 2017

Java : History of Java and Features of Java

History of Java
The history of Java starts from Green team. Java team members also known as Green Team, initiated a task to develop a language for digital devices such as set-top boxes, televisions etc.
James Gosling, Mike Sheridan and Patrick Naughton initiated the Java language project in June 1991. The small team of Sun engineers called Green Team.
Firstly it was called Greentalk by James Gosling and file extension was .gt.
After that, it was called Oak. Oak is symbol of strength and chosen as national tree of many countries like U.S.A., France, Germany, Romania etc.
In 1995, Oak was renamed as Java because it was already a trademark by Oak Technologies.
Java was originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems’ Java platform. The language derives much of its syntax from C and C++, but it has fewer low-level facilities than either of them.

Features of Java
Simple :
Java language is simple because its syntax is based on C++. If you already understand the basic concepts of object-oriented programming, learning Java will be even easier. If you are experienced C++ programmer, then moving to Java will require very little effort. Because Java inherits the C/C++ syntax and many of the object-oriented features of C++.

Object-oriented :
Object-oriented means we organize our software as a combination of different types of objects that incorporates both data and behavior. All program code and data reside within object and classes. The object model in Java is simple and easy extend.

Secure :
Java does not allow one to directly access and manipulate the computer memory as the case in C or C++ with the use of pointers. The use of pointers can provide speed but some time prove dangerous of direct memory manipulation of memory addresses.
Java programs run inside virtual machine sandbox.
A Java sandbox is an area inside the memory. Outside which a Java program can’t make calls to Java resources such as APIs. Java sandbox consists of three components.
Classloader : It adds security by separating the package for the classes of the local file system from those that are imported from network sources.
Bytecode Verifier : It checks the code fragments for illegal code that can violate access right to objects.
Security Manager : It determines what resources a class can access such as reading and writing to the local disk.

Portable :
Java programs can be easily moved from one computer to another. Java compiler generates byte code instruction, we may carry the java byte code to any platform.

Robust :
Robust means strong. Java uses a strong management. Java provides exception handling to manage errors. To gain reliability, java has strict compile time and run time checking for codes. To better understand how java is robust, consider two main reasons for program failure: memory management mistakes and mishandled exceptional conditions.

Multithreaded :
A thread is like a separate program. We can write Java programs that deal with many tasks at once by defining multiple threads. The main advantage of multi-threading is that it doesn’t occupy memory for each thread. It shares common memory area.

Architecture-neutral :
There is no implementation dependant features e.g., size of primitive data types is fixed.
In C language, int data type occupies 2 bytes of memory for 32-bit architecture and 4 bytes of memory for 644-bit architecture. But in Java, it occupies 4 bytes of memory for both 32 and 64 bit architectures.

Interpreted:
Usually a computer language is either compiled or interpreted. Java combines these approaches thus making Java a two-stage system. Java compiler translates source code into byte code instruction. Byte codes are not machine instructions and so java interpreter generates machine code that can be directly executed by the machine that is running the java program. So we can say that java is both a compiled and an interpreted language.

High performance:
Java is faster than traditional interpretation since byte code close to native code.

Distributed:

We can create distributed applications in java. Java is designed for the distributed environment of the Internet, because it handles TCP/IP protocols. Java also supports Remote Method Invocation (RMI). This feature enables a program to invoke methods across a network. 

Whatsapp Tricks : Font Formating like bold, italic, strikethrough


Friends,

In Whatsapp you can send message in bold, italic and strikethrough fonts. If you want to highlight some text then this trick can be used.
Suppose you want to write a message like "Have a nice day". Here in this message "nice" is in bold one.
For that you have to type in whatsapp like
Have a *nice* day.
Means the text you want to bold should be enclosed within "*".

Same way if you want to show in italic then the text should be enclosed within "_" underscore.

And if you want to strike out some text then that text should be enclosed within "~".