Sie sind auf Seite 1von 34

 FIRST GENERATION – MACHINE LANGUAGE

 Uses binary codes to instruct the machine


 SECOND GENERATION – ASSEMBLY LANGUAGE
 Uses mnemonic symbols to instruct the machine
 Uses an assembler to convert codes to machine
language
 THIRD GENERATION – HIGH LEVEL LANGUAGE
 Uses a more simpler codes to instruct the machine
 Uses a compiler or interpreter to convert codes to
machine language
1
What is Java?
 Java is a high level programming language developed
by Sun Microsystems in the early 1990’s.

 Java is both compiled and interpreted programming


language.

 The goal of the Java designers was to develop a


language where a programmer could write the code
once and run this anywhere, anytime and forever.
2
 Reasons why Java became so popular

1. Simple
2. Platform Independent
3. Robust
4. Secure
5. Multithreading
6. Automatic Garbage Collection

 On the negative side


 Java runs slowly than any other languages
 Compiled
 A compiler is a program that reads a high-level
program and translates it all at once, before
running any of the commands.

 The high-level program is called the source code,


and the translated program is called the object
code or the executable.
 Interpreted
 An interpreter is a program that reads a high-level
program and does what it says.

 In effect, it translates the program line-by-line,


alternately reading lines and carrying out
commands.
 Java compiler translates Java Source Code
into a pseudo machine language called the
Java Byte Code.
 The byte code is the machine language for an
imaginary Java computer.
 To run Java Byte Code, you need to use a Java
Virtual Machine on that computer.
 A JVM is a program that behaves like a
computer.
 This kind of program is called an interpreter.
 IDE – Integrated Development Environment
 JCREATOR

 JAVA VIRTUAL MACHINE


 JDK 1.8

 YOURSELF 
INTRODUCTION TO JAVA LANGUAGE

10
 A program is a sequence of instructions that
specifies how to perform a computation

 Mathematical, like solving a system of equations


or finding the roots of a polynomial
 Symbolic computation, like searching and
replacing text in a document or

11
 The instructions, which we will call statements, look
different in different programming languages, but there are
a few basic operations most languages perform:

 Input: Get data from the keyboard, or a file, or some other device.

 Output: Display data on the screen or send data to a file or other device.

 Math: Perform basic mathematical operations like addition and


multiplication.

 Testing: Check for certain conditions and run the appropriate sequence of
statements.

 Repetition: Perform some action repeatedly, usually with some variation.


12
 Vocabulary
The vocabulary is the set of all the words in the
language.

 Syntax
Syntax consists of the rules for combining words
into sentences, or statements as they are more
usually called in programming language.

 Semantics
Semantics define the rules for interpreting the
meaning of sentences.
 Programming errors are called bugs

 The process of tracking them down and correcting them is


called debugging.

 There are a three kinds of errors that can occur in a program,


and it is useful to distinguish them to track them down more
quickly.
 Syntax Error
 Runtime Error
 Logic Error or Semantics Error
1. Syntax Errors-
This kind of error occurs when we violate a syntax rule.
These errors are detected at compile time period.
Usually, this is kind of error is easiest to find.

2. Runtime Errors
This kind of error occurs when we ask the computer to do
something that is illegal. These errors are detected at
runtime.

3. Logic Errors
This are also called as semantic error. It will compile and
run without generating error messages, but it will not do
the right thing. These errors are very hard to find because
the computer can’t detect it.
import java.io.*;
import java.util.*;

public class hello {

public static void main (String[] args){

System.out.println(“Hello World”);
}
}

package – Java Libraries (a collection of class and


methods) java.io, java.util
class - indicates a name chosen by the
programmer.
class name and filename are the same
main - main is a method it marks the place in the
program where execution begins.
System.out.println – statements/ commands
16
17
18
 Java program is divided into tokens

 A token is the smallest individual unit in a java


program.

 Tokens are classified into 5 categories:


1. Identifiers
2. Keywords
3. Separators
4. Literals
5. Operators
 Identifiers
 Represents names assigned to variables, methods and
classes. The compiler uniquely identifies these names.
Rules when creating an identifier
 An identifier must only begin with a letter, underscore or
dollar sign.
 No spaces in between
 An identifier can only contain 2 special characters.
Underscore and dollar sign only.

 Keywords
 Predefined identifiers are reserved by Java. You can’t use
these words as your identifiers.
abstract assert boolean break
byte case catch char
class const continue default
do double else enum
extends false final finally
float for goto if
implements import instanceof int
interface long native new
null package private public
protected return short static
strictfp super switch this
synchronized throw throws true
transient try void volatile
while
 Separators
 Informs the java compiler of the grouping of
program elements. (), {}, comments

 Literals
 Constant values in a program

 Operators
 Specify an evaluation or calculation to be
performed on data or object
 java.util.*; - this package contains the IO

 Standard Output
 System.out.println( );
 System.out.print

Example;
System.out.println(“Hello World”);
System.out.println(a);
System.out.print(“Java World”);
System.out.print(x);
 Standard Input
Should declare the package and object
 static Scanner scan = new Scanner(System.in);
▪ scan.nextInt() – accept integer input
▪ scan.nextLine() – accept string input
▪ scan.nextDouble() – accept double input
 Example:
String name;
name = scan.nextLine()
INTRODUCTION TO JAVA LANGUAGE

25
 An item whose values changes during the execution of a
program.

 Variable declaration
 Before using any variable, you must first declare it. This is done in a
variable declaration statement.
 Example: int age;
double Celsius;

 Variable Initialization
 A variable can be initialized by giving a default value.
 Example: int age = 12;
double Celsius = 3.0;
 A data type describes the kind of data that will
fit into a variable.

 There are two kinds of data types:


 Primitive and Reference

 Reference Data Types


 Objects
▪ String
▪ Math
▪ Date
 Primitive Data Types can be classified into :
 Numeric (int, double,float)
 Char
 Boolean
Type Approximate Size in Bits Minimal Range

byte 1 byte -128 - 127

short 2 bytes -32,768 to 32,767

int 4 bytes -2,147,483,648 to -2,147,483,647

-9223372036854775808 to
long 8 bytes
9223372036854775807

32-bit IEEE 754 floating-point


float 4 bytes
numbers
64-bit IEEE 754 floating-point
double 8 bytes
numbers
 Expression – is any combination of operators
and operands

 Operators:
Operators are tools for manipulating data. An
operator is a symbol which represents some
particular operation to be performed on the
data.

 Operators operate on a constant or variable


which are called operands.
Kinds of Operators:
 Arithmetic – are used to perform mathematical /
numerical operation. They are divided into 2 classes
▪ Unary and binary.

 Comparison / Relational - are used to test the


relationship between a variable and a constant or vice
versa or both.

 Logical- Symbols that are used to combine or negate


expression containing relational expression
Operator Symbol Definition
Assignment
= Simple assignment operator
Operator
Additive operator (also used for
+
String concatenation)
- Subtraction operator
Arithmetic
* Multiplication operator
Operators
/ Division operator
% Remainder operator
Operator Symbol Definition
Unary plus operator; indicates
+
positive
Unary minus operator; negates an
-
Unary Operators expression
Increment operator; increments a
++
value by 1
Decrement operator; decrements a
--
value by 1
Logical compliment operator; inverts
!
the value of a boolean
Operator Symbol Definition
== Equal to
!= Not equal to
> Greater than
Equality and
Relational >= Greater than or equal to
Operators < Less than
<= Less than or equal to

&& AND
Logical
Operators || OR

Das könnte Ihnen auch gefallen