Professional Documents
Culture Documents
Lecture Outline:: Java . ... Lecture1 . . A.L. Ali Hakem
Lecture Outline:: Java . ... Lecture1 . . A.L. Ali Hakem
Ali Hakem
Lecture outline:
1. Introduction to programming
2. Planning for the Computer Programs.
3. What is Java?
4. Structure of Java Program
5. Data type in Java
6. Variables in Java
7. Operators in Java
8. Output command in Java
9. Java Comments
Suggested Readings:
1
Java …….…………...………Lecture1…….……….…… A.L. Ali Hakem
2
Java …….…………...………Lecture1…….……….…… A.L. Ali Hakem
languages in the world some of them are known by only their developers
such as FORTRAN, C/C++, JAVA, Pascal, COBOL, ADA… etc.
There are some tools recommend using one of them before write
programs. Algorithm The tools are, Flowchart, and Pseudocode.
1.2.1 Algorithm
Example2:
Write an algorithm to find the maximum and minimum number in the
list.
Solution:
1- Start.
2- Enter numbers.
3- Find maximum and minimum number.
4- Print maximum and minimum number.
3
Java …….…………...………Lecture1…….……….…… A.L. Ali Hakem
5- End
1.2.2 Flowchart
The flowchart is a pictorial representation of an algorithm uses
symbols (boxes of different shapes) that have standardized meaning to
denote different types of instructions. The instructions within flowchart
are write in boxes. The boxes are connected by solid lines having arrow
marks to indicate the exact sequence in which the instructions are to be
executed. The process of drawing a flowchart for an algorithm called
flowcharting. Figure 1.1 shows the shapes (symbols) that use in flowchart
Example 3
4
Java …….…………...………Lecture1…….……….…… A.L. Ali Hakem
1.2.3 Pseudocode
Pseudocode is a detailed yet readable description of what a computer
program or algorithm must do, expressed in a formally-styled natural
language rather than in a programming language. Pseudocode is sometimes
used as a detailed step in the process of developing a program. It allows
designers or leads programmers to express the design in great detail and
provides programmers a detailed template for the next step of writing code in
a specific programming language.
5
Java …….…………...………Lecture1…….……….…… A.L. Ali Hakem
1- The numerical data type either integer or floating point. The Integers
numbers are defined as a byte (8-bit), short(16-bit), int(32-bit), and
long(64-bit). The floating-point numbers are defined as float(32-bit)
and double(64-bit).
2- The textual data type either Characters or staring. The Characters are
defined as char. The string is defined as String.
3- Boolean is a special type for representing true/false values define as
Boolean
1.6 Variables in Java
6
Java …….…………...………Lecture1…….……….…… A.L. Ali Hakem
visibility, and a lifetime. In Java, all variables must be declared before they
can be used. The basic form of a variable declaration is shown here:
Type Identifier;
The type is one of Java„s atomic types or the name of a class or interface.
The identifier is the name of the variable. You can initialize the variable by
specifying an equal sign and a value. To declare more than one variable of
the specified type, use a comma separated list.
Here are several examples of variable declarations of various types. Note that
some include an initialization
Note:
7
Java …….…………...………Lecture1…….……….…… A.L. Ali Hakem
8
Java …….…………...………Lecture1…….……….…… A.L. Ali Hakem
9
Java …….…………...………Lecture1…….……….…… A.L. Ali Hakem
String a= “Ali”;
System.out.print (“Name=” + a); // print the value of a
Display the result.
Name=Ali
11
Java …….…………...………Lecture1…….……….…… A.L. Ali Hakem
The java comments are statements that are not executed by the
compiler and interpreter. The comments can be used to provide information
or explanation about the variable, method, class or any statement. It can also
be used to hide program code for a specific time. There are two types of
comments in java Single Line Comment and multi-Line Comment.
11