Professional Documents
Culture Documents
Course Code:COMP1112
Java -version
LIFE CYCLE OF A JAVA PROGRAM:
There are three main stages in the life cycle of a
java program.
They are:
Editing the program
Vehicle
Human
Student Techer
Customer
OBJECT AND CLASS
An object is an entity that can be anything(Person, Place or thing)
Every Object has two things:
State and Behavior.
For Example:
1. Dog is an Object.
2. Dog state :Name, Color, Age
3. Dog Behavior: Bark, sleep, running, eat
Black Dog and Red Dog are objects that we create with the help of the
class.
SOURCE CODE
Source code:
A program that is written in high level language is called source
code. It is also know as the sourse program.
The source code cannot be executed by the computer directly. It
must be converted into object code to be executed.
Byte Code:
Java bytecode is the instruction set for the Java Virtual Machine.
It acts similar to an assembler which is an alias representation of
a C++ code.
As soon as a java program is compiled, java bytecode is generated.
In more apt terms, java bytecode is the machine code in the form
of a .class file. With the help of java bytecode we achieve platform
independence in java.
LANGUAGE PROCESSORS:
As we know that a computer understand only machine
language. A program that is written in high level
language or assembly language cannot be run by the
computer directly.
It must be converted into a machine language first
before to execute.
Language Processor or translators is a software that
converts a source code into a object code.
Every language has its own translators.
1.COMPILER:
A compiler is a program that converts the instructions of a high
level language into a machine language as a whole.
A program that is written in high level language is called source
program.
Compiler converts the source program into a machine code which
is known as object programs.
The compiler checks the each statement in the course program
and generate the machine instructions.
It also checks for the syntax error in the program. A source
program that contains an error cannot be compiled.
Every language has its own written compiler and a compiler
translates the programs of only that language for which it is
written.
For example C++ compiler translates only programs that are
written in C++
2.INTERPRETER:
It is a program that converts one statement at a time.
It executes this statement first before to translate the next
statement of the source program.
If there are any errors in the statements. The interpreter will stop
working and displays an error message first.
Advantage is that an error is found immediately. So the
programmer can correct the error during the program development
Disadvantage is that it is not very efficient. It does not produce an
object program. It must convert the program each time it is
executes. Visual basics uses the interpreter.
Compiler transforms code written in a high-level programming
language into the machine code, at once, before program runs,
whereas an Interpreter coverts each high-level program
statement, one by one, into the machine code, during program
run.
Compiler creates objects file while assembler do not.
Compiled code runs faster while interpreted code runs slower.
Compiler displays all errors after compilation, on the other
hand, the Interpreter displays errors of each line one by one.
Compiler converted high level program can be executed many
times, while interpreter converts the high level program each
time it is executed.
3.Assembler:
It is a translating program that translates instructions of an
assembly language into machine language,
Assembely
Language Program Object Program
Assembler
THE FIRST JAVA PROGRAM:
package program1;
public class Program1 {
}
PARAMETERS USED IN FIRST JAVA PROGRAM
System.out.println(“Welcome in Java");
System.out.println(“Programming is fun");
System.out.println(“Problem Driven");
}
ANOTHER PROGRAM:
package program1;
public class Program1 {