DOC

The Java Environment

By Jessica Lopez,2014-04-24 13:58
14 views 0
The Java Environment

Java Notes

    The Java Environment

? Editor (Notepad, Textpad)

    ? Java Compiler (javac) ? Virtual machine (VM) Interpreter and run time environment (java )

     Java Source code Java Bytecode file Java VM

Write once run anywhere:

     Java Program Compile

     Bytecode

     Interpreter Interpreter

     Interpreter

     Unix Windows MacOS

? A Java program consists of one or more class definitions, each of which has been compiled into a

    separate .class file of JVM byte code. ? One of the classes must contain a method main(), which indicates the start of program execution.

    ? To execute the program specify the name of the class with the main() method as the argument to the

    java interpreter.

    ? The java file containing a class definition must have the same name as the name of the class it contains.

    ? Java is case sensitive

    ? Java statements end in a semi-colon;

unit2

     - 1 -

Java Notes

    Java program

    Class (es)

    Members(s)

    Variable(s) Method(s)

    Primitive data type(s) Non-primitive data types(s) Statement (s) +variables

    Boolean,char,int,long Objects and arrays

First program

Click on the TextPad editor icon on your computer

    1. use the TextPad editor to type in the first Java program shown in Example 2.1.

    class Welcome

    {

     /* Welcome to Java! Program * Illustrates a simple program displaying a message

     */

     public static void main (String [] args ) {

     System.out.println(“Welcome to Java!”); }

     }

    2. Save it in a file called Welcome.java.

    The JDK compiler will take the file and compile it. If you made no typing errors, the command prompt

    will be returned.

    unit2

     - 2 -

Java Notes

    3. If there are error messages, go back to the edit window, fix the Java program accordingly, then

    recompile.

     Key points on first programs

    A Java Program

    A Java program consists of a set of one or more inter-dependent classes. Classes are a means of

    describing the properties and capabilities of objects in real life that the program has to deal with.

    The properties are called fields and the capabilities are called methods.

    Methods and Statements

    A method is a sequence of instructions to the computer. These instructions are called statements.

    Comments:

    Three types of comments are supported:

    // comment all until the end of this line

    /* start of comment block to

     * end of comment block

     */

    /** comment can be automatically generated into software documentation

     */

    The main method

    Every application program in Java must have a main method, as this is where the program starts

    execution.

    Strings

    Text in quotes is known as a String.

Fundamentals of OOP

    .

    Basic terms

    Terminology Explanation

    A Java Program Java programs are composed of a set of inter-dependent modules called classes

    Class Classes are means for describing the properties and capabilities of the objects that the

    program has to deal with, i.e. a class is a template specifying a set of behaviors on the

    data of the class

    Object Is a concrete realisation of a class description, an object is created as an instance of a

    class.

    Instance The process of generating new objects for a program is referred to as creating an instance

    of a class

    unit2

     - 3 -

Java Notes

    Field The properties of a class are called fields

    Method The capabilities of a class are called methods

    Members Fields and methods are jointly known as members

    Class shown asdotted oblongStudent

    Mary is anObject shown asinstance of Studentsolid oblong

    MaryJohnBart

     Figure 1: Objects created as instances of classes

    unit2

     - 4 -

Java Notes

unit2

- 5 -

Report this document

For any questions or suggestions please email
cust-service@docsford.com