Showing posts with label Java Theory. Show all posts

How to Run program?

Tuesday, 9 June 2015
Posted by Unknown

Getting started with Java

Developing / Writing a Program

        To write a program in text editor like node pad. Take the following simple program.

class HelloWorld  
{
    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:

cd  C:\Program Files\Java\jdk1.6.0\bin

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 classname

Finally, to execute the program using the following command:

java HelloWorld

Output

Hello World!

History of Java

Posted by Unknown

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:
  1. It must be "simple, object-oriented and familiar".
  2. It must be "robust and secure".
  3. It must be "architecture-neutral and portable".
  4. It must execute with "high performance".
  5. It must be "interpreted, threaded, and dynamic".
Reference:
Wikipedia - Java programming language
Welcome to My Blog

Translate

Popular Post

Total Pageviews

- Copyright © Learning Java Program - Powered by Blogger -