1. Using Java
MINISTRY OF EDUCATION & HIGHER EDUCATION
COLLEGE OF SCIENCE AND TECHNOLOGY
KHANYOUNIS- PALESTINE
2. First Program in Java
Discussion of the main concepts
Install the JDK and JCreator
Memory Concepts and DataTypes
Variables and Identifiers
Arithmetic Operations
Emank X Mezank
2Presented & Prepared by: Mahmoud R. Alfarra
3. Computer programmers create applications
by writing computer programs.
Your e-mail application helps you send and receive e-mail
yourWeb browser lets you view Web pages fromWeb sites
around the world.
A Java application is a computer program
that executes when you use the java
command to launch the JavaVirtual Machine
(JVM).
3Presented & Prepared by: Mahmoud R. Alfarra
4. Let us consider a simple application that
displays a line of text using Java command.
4Presented & Prepared by: Mahmoud R. Alfarra
5. Every program in Java consists of at least one
class declaration that is defined by the
programmer.
These are known as programmer-defined
classes or user-defined classes.
5Presented & Prepared by: Mahmoud R. Alfarra
6. Java class declarations normally contain one
or more methods.
For a Java application, exactly one of the
methods must be called main and must be
defined as shown
6Presented & Prepared by: Mahmoud R. Alfarra
It is a syntax error if braces do not occur in matching
pairs
7. Instructions perform an action namely, to
print the string of characters contained
between the double quotation marks.
We refer to characters between double
quotation marks simply as strings.
7Presented & Prepared by: Mahmoud R. Alfarra
8. Method System.out.println displays a line of text in
the command window.
The string in the parentheses is the argument to the
method.
8Presented & Prepared by: Mahmoud R. Alfarra
Method print displays one line of text in the
command window and position the cursor next
the last character.
Println position the output cursor at the
beginning of the next line in the command.
9. begins with // or between /* */, indicating
that the remainder of the line is a comment.
The Java compiler ignores comments.
9Presented & Prepared by: Mahmoud R. Alfarra
10. 10Presented & Prepared by: Mahmoud R. Alfarra
Java is case sensitive. Not using the proper uppercase and
lowercase letters for an identifier normally causes a
compilation error.
It is an error for a public class to have a file name that is not
identical to the class name (plus the .java extension) in terms
of both spelling and capitalization.
Omitting the semicolon at the end of a statement is a syntax
error.
11. From the sun site
▪ http://java.sun.com/javase/downloads/index.jsp.
download jdk-6-windows-i586.exe
Setup normally (next then next …)
But be care where it will be installed in your
PC
11Presented & Prepared by: Mahmoud R. Alfarra
12. 12Presented & Prepared by: Mahmoud R. Alfarra
From the site of Jcreator or my web site
▪ http://www.jcreator.com/
▪ Staff.cst.ps/mfarra
Download the JCreator Pro
And then trace the following slides to setup …
20. 7
Install the JDK and JCreator on your PC at home,
and then write a program that prints your name, ID,
GPA, addressHW 4.1
21. Identifiers are names used to identify
variables, methods, classes …
An identifier consist of letters,numbers, _ , $
But must:
Begin with letter.
not contain space.
not a reserved word
21Presented & Prepared by: Mahmoud R. Alfarra
22. A variable is a location in the computer's
memory where a value can be stored for use
later in a program.
All variables must be declared with a name
and a type before they can be used.
22Presented & Prepared by: Mahmoud R. Alfarra
Data type Identifiers
23. Data types in Java are divided into two
categories primitive types and reference.
A primitive-type variable can store exactly
one value of its declared type at a time.
Every variable has a name, a type, a size and
a value.
23Presented & Prepared by: Mahmoud R. Alfarra
26. Most programs perform arithmetic calculations.
The arithmetic operators are
26Presented & Prepared by: Mahmoud R. Alfarra
27. Java applies the operators in arithmetic expressions
in a precise sequence determined by the following
rules of operator precedence:
27Presented & Prepared by: Mahmoud R. Alfarra