java command

Download Report

Transcript java command

MINISTRY OF EDUCATION & HIGHER EDUCATION
COLLEGE OF SCIENCE AND TECHNOLOGY
KHANYOUNIS- PALESTINE
Using Java

First Program in Java

Discussion of the main concepts

Install the JDK and JCreator

Memory Concepts and Data Types

Variables and Identifiers

Arithmetic Operations

Emank X Mezank
Presented & Prepared by: Mahmoud R. Alfarra
2

Computer programmers create applications
by writing computer programs.
 Your e-mail application helps you send and receive e-mail
 your Web browser lets you view Web pages from Web sites
around the world.

A Java application is a computer program
that executes when you use the java
command to launch the Java Virtual Machine
(JVM).
Presented & Prepared by: Mahmoud R. Alfarra
3

Let us consider a simple application that
displays a line of text using Java command.
Presented & Prepared by: Mahmoud R. Alfarra
4


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.
Presented & Prepared by: Mahmoud R. Alfarra
5


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
It is a syntax error if braces do not occur in matching
pairs
Presented & Prepared by: Mahmoud R. Alfarra
6


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.
Presented & Prepared by: Mahmoud R. Alfarra
7
Method System.out.println displays a line of text in
the command window.
 The string in the parentheses is the argument to the
method.

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.

Presented & Prepared by: Mahmoud R. Alfarra
8


begins with // or between /* */, indicating
that the remainder of the line is a comment.
The Java compiler ignores comments.
Presented & Prepared by: Mahmoud R. Alfarra
9
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.
Presented & Prepared by: Mahmoud R. Alfarra
10

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
Presented & Prepared by: Mahmoud R. Alfarra
11

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 …
Presented & Prepared by: Mahmoud R. Alfarra
12
‫إعداد ‪ /‬أ‪.‬‬
‫حممود رفيق‬
‫محدي الفرا‬
‫‪-2010‬‬
‫‪2011‬‬
1
4
2
3
5
6
7
HW 4.1
Install the JDK and JCreator on your PC at home,
and then write a program that prints your name, ID,
GPA, address
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
Presented & Prepared by: Mahmoud R. Alfarra
21


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.
Data type
Identifiers
Presented & Prepared by: Mahmoud R. Alfarra
22

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.
Presented & Prepared by: Mahmoud R. Alfarra
23
‫سيتم تخصيص مساحة في الذاكرة سعتها ‪ 1‬بايت ‪Type1 x = 28 ; //‬‬
‫;‪Type2 y‬‬
‫سيتم تخصيص مساحة في الذاكرة سعتها ‪ 2‬بايت ‪//‬‬
‫بمجرد هذا التعريف يتم‬
‫تخصيص مساحة في الذاكرة‬
‫لتخزين بيانات بحجم يناسب‬
‫النوع املراد‬
‫مقطع من الذكرة‬
‫‪24‬‬
‫‪0‬‬
‫‪0‬‬
‫‪1‬‬
‫‪1‬‬
‫‪1‬‬
‫‪Presented & Prepared by: Mahmoud R. Alfarra‬‬
‫‪0‬‬
‫‪0‬‬
‫‪0‬‬
Size
Values examples
Type
1 Byte
true, false
boolean
2 byte
‘b’, ‘c’ , ‘t’, ‘5’, …
char
1 byte
128, 0, 34, …
byte
2 byte
32768, 67, 34
short
4 byte
2147483648 , 7, 9, 0, …
int
8 byte
9223372036854775808, 878, …
long
4 byte
- 3.5, 234.56, …
float
8 byte
-2345.34, …
double
Presented & Prepared by: Mahmoud R. Alfarra
25

Most programs perform arithmetic calculations.

The arithmetic operators are
Presented & Prepared by: Mahmoud R. Alfarra
26

Java applies the operators in arithmetic expressions
in a precise sequence determined by the following
rules of operator precedence:
Presented & Prepared by: Mahmoud R. Alfarra
27
Presented & Prepared by: Mahmoud R. Alfarra
28
Presented & Prepared by: Mahmoud R. Alfarra
29
Some common escape sequences
Presented & Prepared by: Mahmoud R. Alfarra
30
Presented & Prepared by: Mahmoud R. Alfarra
31
Presented & Prepared by: Mahmoud R. Alfarra
32
Presented & Prepared by: Mahmoud R. Alfarra
33
Presented & Prepared by: Mahmoud R. Alfarra
34
‫قال هللا تعاىل‪:‬‬
‫ِ‬
‫ِ‬
‫(ال جَِت ُد قجوماً ي ِ‬
‫ؤمنو جن ِِب جِ‬
‫لل جواليجوم األجخر ِر يُروا ودو جن‬
‫ُ‬
‫جمن َّ‬
‫اللج جوجرسولجهُ)‬
‫حاد ج‬
‫‪35‬‬
‫‪Presented & Prepared by: Mahmoud R. Alfarra‬‬
Introduction
to OOP
Presented & Prepared by: Mahmoud R. Alfarra
36