Thursday, July 1, 2010

OO Hello World - Java



The Hello World version of the program in Java!

I was thinking in why I excluded Java from this blog if it is the de facto language for the JVM! Just like C# is for the CLR, so from now on its included :) in the “Most Active .NET and JVM Languages” post and here below the OO Hello World program… enjoy!


By the way, you can see my previous post here: http://carlosqt.blogspot.com/2010/06/oo-hello-world.html
where I give some details on WHY these "OO Hello World series" samples.

Version 1 (Minimal):
The minimum you need to type to get your program compiled and running.

package greetprogram;

class Greet {
    private String name;
    Greet(String name) {
        this.name = name.substring(0,1).toUpperCase() + name.substring(1, name.length());
    }
    void Salute() {
        System.out.println("Hello " + name + "!") ;
    }
}

package greetprogram;
// Greet the world!
class Main {
    public static void main(String[] args) {
        Greet g = new Greet("world");
        g.Salute();
    }
}

Version 2 (Verbose):
Explicitly adding instructions and keywords that are optional to the compiler.

package greetprogram;
import java.lang.*;

public class Greet {
    private String name;
    public Greet(String name) {
        this.name = name.substring(0,1).toUpperCase() + name.substring(1, name.length());
    }
    public void Salute() {
        System.out.println("Hello " + this.name + "!") ;
    }
}

package greetprogram;
// Greet the world!
public class Main {  
    public static void main(String[] args) {
        Greet g = new Greet("world");
        g.Salute();
    }
}

The Program Output:









Java Info:
“The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities. Java applications are typically compiled to bytecode (class file) that can run on any Java Virtual Machine (JVM) regardless of computer architecture. Java is general-purpose, concurrent, class-based, and object-oriented, and is specifically designed to have as few implementation dependencies as possible. It is intended to let application developers "write once, run anywhere". Java is currently one of the most popular programming languages in use, and is widely used from application software to web applications.” Taken from: (http://en.wikipedia.org/wiki/Java_(programming_language))

Appeared:
1995
Current Version:
Developed by:
James Gosling & Sun Microsystems
Creator:
James Gosling
Influenced by:
C (Dennis Ritchie) and C++ (Bjarne Stroustrup)
Predecessor Language
Predecessor Appeared
Predecessor Creator
Runtime Target:
JVM
Latest Framework Target:
JDK 6
Mono Target:
No
Allows Unmanaged Code:
No
Source Code Extension:
“.java”
Keywords:
50
Case Sensitive:
Yes
Free Version Available:
Yes
Open Source:
Yes
Standard:
JSR 316?
Latest IDE Support:
NetBeans 6.9
Eclipse
IntelliJ IDEA
Language Reference:
Extra Info:


No comments:

Post a Comment