What is Java?
Java is an open source object oriented programming language developed by Sun Microsystems. The Java language is commonly used to build a variety of client applications and web systems. Java has been growing in popularity and usage in the field since it's release, and the Java platform was designed to be cross platform compatible with the under the hood work done by the Java Runtime.
Basic Syntax
With Java everything is an object. Each object is represented by a class and is stored in a .java source file. Java programs are a collection of classes that work together.Create a new file HelloWorld.java
class HelloWorld {Before we can execute this, we must compile it. With Java you use the javac command to compile a java class. This will be the only place in this tutorial where we cover compiling as it's the same process for the entire tutorial.
public static void main(String[] args) {
System.out.println("Hello World");
}
}
$ javac HelloWorld.javaThe class should have the same name of the .java file. Functions in Java are commonly called methods. The method main is used as the function to call when the program is executed. Methods will be covered in detail later. Values passed to the program from the command line will be stored in the String array args. The System.out.println method is called and passed Hello World. System.out.println pushes to the display (STDOUT) the passed argument followed by a newline. All code blocks in Java are delimited with { }.
$ java HelloWorld
Hello World
No comments:
Post a Comment