Showing posts with label Java Theory. Show all posts
Getting started with Java
Developing / Writing a Program
To write a program in text editor like node pad. Take the following simple program.
{
public static void main(String args[])
{
System.out.println("Hello World!");
}
}
Here HelloWorld is the class name of the program. Choose the following directory to save the file:
C:\Program Files\Java\jdk1.6.0\bin
On Windows, the JDK is placed in the following path or directory by default:
C:\Program Files\Java\jdk1.6.0
Then save this file like "class name.java" i.e., HelloWorld.java.
Compiling the Program
Syntax: javac filename.java
First open the Command Prompt (Press windows key+R then type "cmd" and hit Enter). Then type following code:
Execute the following command to compile your source file to bytecode:
javac HelloWorld.java
Note: If you do not set the PATH variable correctly, when you use the JDK’s tools, you will receive a message like:
'java' is not recognized as an internal or external command,
operable program or batch file.
Running the Program
Syntax: java classnameFinally, to execute the program using the following command:
Output
Hello World!
Introduction
James Gosling, Mike Sheridan, and Patrick Naughton initiated the Java language project in June 1991. The language was initially called Oak after an oak tree that stood outside Gosling's office. Later the project went by the name Green and was finally renamed Java, from Java coffee in 1995.
Gosling designed Java with a C/C++-style syntax that system and application programmers would find familiar. Sun Microsystems released the first public implementation as Java 1.0 in 1995. It promised "Write Once, Run Anywhere" (WORA), providing no-cost run-times on popular platforms.
One design goal of Java is portability, which means that programs
written for the Java platform must run similarly on any combination of
hardware and operating system with adequate runtime support. This is
achieved by compiling the Java language code to an intermediate
representation called Java bytecode, instead of directly to architecture-specific machine code. Java bytecode instructions are analogous to machine code, but they are intended to be executed by a virtual machine (VM) written specifically for the host hardware. End users commonly use a Java Runtime Environment (JRE) installed on their own machine for standalone Java applications, or in a web browser for Java applets.
Why we go to Java?
There were five primary goals in Java language:- It must be "simple, object-oriented and familiar".
- It must be "robust and secure".
- It must be "architecture-neutral and portable".
- It must execute with "high performance".
- It must be "interpreted, threaded, and dynamic".
Wikipedia - Java programming language


