Professional Documents
Culture Documents
Chapter(2):
Primitive Data Types& Operations
Contents: محتويات المحاضرة
Overview of Creating, Compiling, and Executing
a Java Program
Examples
2.1. Creating Java Program
You can use any text editor (ex: TextPad, NotePad) to
create and edit a Java source code file
This file must save with the extension .java and must
have the exact same name as the public class name.
ex: Welcome.java - since the public class name is Welcome.
java Welcome
2.3. Identifiers
Programming language use special symbols called
identifiers to name such programming entities as
variables, constants, methods, classes, and packages.
Rules for naming identifiers are:
An identifier is a sequence of characters that consists of
letters, digits, underscores (_), and dollar signs ($).
must start with a letter, an underscore (_), or a dollar sign
($). It cannot start with a digit.
An identifier cannot be a reserved word
An identifier cannot be true, false or null
An identifier can be with any length
2.3. Identifiers
Examples of legal identifiers:
datatype variableName
(-9223372036854775808 to 9223372036854775807)
float Negative range: -3.4028235E + 38 to -1.4E-45 32-bit IEEE 754
فى حالة وجود أكثر من متغير من نفس النوع تكون صيغة التعريف للمتغيرات
:كاآلتى
datatype variable1 , variable2 , ... , variablen;
ex:
int i = 1, k = 50;
int x = y = z = 10;
2.5. Assignment Statement and Expressions
Example(1):
:ماهو ناتج تنفيذ البرنامج اآلتى
guess.java
public class guess {
public static void main(String[ ] args) {
System.out.print( num );
}
}
****
***
**
*
ُ -2معطى المتغيرين int x=3 ، y=5
اكتب برنامج يقوم باآلتى:
( )1تعريف المتغير Zمن نوع int
( )2تخزين حاصل جمع العددين y ،xبالمتغير Z
( )3طباعة المتغير Z