ICT 100%

Introduction to Java

Java programming language is a high-level language; java source code can be written in plain text file by ending with .java extension. The .java can then be compiled into .class file by using javac compiler. A .class file contains bytecodes a machine language of the Java Virtual Machine (JVM). The instance of JVM uses java launcher tool to run the application.

An overview

helloWold.java-> COMPILER-> helloWold.class -> JVM -> Program

Why JVM?

JVM is available on all operating systems such as Microsoft windows, Linux and Mac OS and that makes java cross platform programming language. Since JVM is available on all operating systems we can now run .class file.

  • Java is platform independent, meaning that you can write a program once and run it anywhere.
  • Java programs can be embedded in HTML pages and downloaded by Web browsers to bring live animation and interaction to Web clients.
  •  Java source files end with the .java extension.
  •  Every class is compiled into a separate bytecode file that has the same name as the class and ends with the .class extension.
  •  To compile a Java source-code file from the command line, use the javac command.
  •  To run a Java class from the command line, use the java command.
  •  Every Java program is a set of class definitions. The keyword class introduces a class definition. The contents of the class are included in a block.
  • A block begins with an opening brace ({) and ends with a closing brace (}). Methods are contained in a class.
  •  A Java program must have a main method. The main method is the entry point where the program starts when it is executed.
  • Every statement in Java ends with a semicolon (;), known as the statement terminator
  •  Reserved words, or keywords, have a specific meaning to the compiler and cannot be used for other purposes in the program
  •  In Java, comments are preceded by two slashes (//) on a line, called a line comment, or enclosed between /* and */ on one or several lines, called a block comment
  • Java source programs are case sensitive
  • There are two types of import statements: specific import and wildcard import
  •  The specific import specifies a single class in the import statement
  • The wildcard import imports all the classes in a package
  • Programming errors can be categorized into three types: syntax errors, runtime errors, and logic errors
  • Errors that occur during compilation are called syntax errors or compile errors
  • Runtime errors are errors that cause a program to terminate abnormally
  • Logic errors occur when a program does not perform the way it was intended to

Example of Java code

Let begin with a simple Java Program that displays the message such as “Welcome to ICT100% tutorials” on console.

package javaict100; /** * * @author www.ict100.com */ public class ICT100 { public static void main(String args) { // Show the message Welcome to ICT100.com! to console System.out.println("Welcome to ICT100% tutorials"); } }