Programming Languages‎ > ‎Java‎ > ‎

01. Introduction to Java

What is Java?

Java is a relative new programming language created in the mid-1990's by Sun Microsystems Corporation. They made Java, "A simple, object-oriented, distributed, interpreted, robust, secure, architecture-neutral, portable, high-performance, multithreaded, and dynamic language."


Few Important Java Terms

- class is a piece of a Java program which is a container for data and methods (like a template, or a C structure definition with functions and data)
- object is an instance of a particular class (similar to a C structure variable)
- method is a module of a program which can be executed when called (same as a C/C++ function)
- applet is a program that runs in a Web browser when an HTML document containing the applet is loaded into the browser (more on applets later)
- HTML is a language used in web pages
- application program is a program that runs independently of a Web browser


How to Run a Java Program

Example of Simple Java Program

public class Example1
{   // start of class Example1
     public static void main(String args[])
     {   // start of main
          System.out.println("Welcome to Java Programming!");
          System.out.println("Testing " + 1 + 2 + 3 + "...");
     } // end main
} // end class Example

The output of the above example:

Welcome to Java Programming!
Testing 123...

Notes:

  • // indicates that whatever follows to the end of the line is a comment (C++ style) (C comments /* */ are also allowed)
  • public (when used in a class definition) is an access specifier and says that the class may be accessed by any Java code that can access the package in which it is declared.
  • class means that Java class is being defined
  • Example1 is the name of the class being defined (if it is public, it must be the same name as the file in which it is contained, with the .java extension)
  • public (when used in a method definition) means that the method being defined is visible to everyone who has access to the class
  • static means that the method is instance-independent, and therefore may be called without someone's doing an instantiation of the class itself (don't worry if you don't understand this now because you don't really need to understand "static" until Chapter 5)
  • void means that the method returns nothing
  • main is the name of the method.  Every program must have one main method.  This is where execution begins and ends in a Java application program (not applet)
  • String is the name of the Java library string class
  • args[] refers to String arguments being passed in (to be discussed later)
  • System.out is an object which has a method call printlnSystem.out.println is a call that will display its argument onto the output screen

Comments