Show Menu
Cheatography

Java 1 Cheat Sheet (DRAFT) by

Quick review of some table in Java

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Reading input from the console

1- create a Scanner object [ Scanner input = new Scanne­r(S­yst­em.in)
2- Use the method (ex: nextDo­uble() ) to obtain to (double) value [ double = input.n­ex­tDouble ();]

Reading numbers from the keyboard

Import

Implicit import (الضمني)
Explicit import (الصريح)
java.u­til.*;
java.u­til.Sc­anner;

Identi­fiers (شروط التسميه)

1- An identifier is a sequence of characters that consist of letters, digits, underscore _ , dollar sign$
2- must start with a letter_or $ , it can’t with digits
3- can’t be a received word (Java keywords)
4- can’t be true, false, null
5- can be of any lenght

Variables

1- declar­ing­[ال­تصريح]
‏ هو تعريف المتغير مع تحديد نوعه دون إعطائه قيمة
int x;
2- Assign­men­t[ا­لإسناد]
‏هو إعطاء قيمة للمتغير بعد التصريح عنه
x = 3;
3- declaring and initia­lis­ati­on[­التصريح و التهيئة]
‏هو تعريف المتغير وإعطائه قيمة ابتدائية في نفس السطر
int x = 3;

‏Naming Conven­tions

Choose meaningful and descri­ptive names
1 - variables and method names:
Use lowercase, ex variable : area , ex method : comput­eArea
2- Class names:
Capitalise the first letter of each word in the name, ex : Comput­eArea
3 - constants names:
- Capitalise all letters, ex : PI
- use underscore to separate words, ex : MAX_VALUE
Variables and method names :
If the name consist of several words :
1- concat­enate all into one
2- use lowercase for the first word
3- capitalise the first letter of each subsequent word

Numerical Data Types

Numberic Operators

5/2 yields 2 —> int / int = int
5.0 / 2 yields 2.5 —> double / int = double
5%2 yields 1 باقي القسمة
Remainder operator is very useful in progra­mming :
even%2 = 0
odd %2 =1

Number literals

Integer literals :
An integer literals is assumed to be of the int type
To denote an integer literal of the long type appond it with L or l
double literals :
Floating point literal is treated as a double type value
1- making a number a float
Add F or f
2- making a number a double
Add D or d
Note :
Compli­cation error would occur if literals were to large for the variable to hold
ex : byte b = 1000;
The double type value are more accurate then float type value

Arithmetic Expres­sions

احول الصيغة اللي فوق الى صيغة تفهمها الجافا
الضرب لازم يكون بعلامة*

Increment and Decrement

Augmented Assignment operators

Conversion Rules قواعد التحويل

If one of the operands is double, the other is converted into double.
Otherwise, if one of the operands is float, the other is converted into float
Otherwise, if one of the operands is long, the other is converted into long.
Otherwise, both operands are converted into int.

Implicit casting

Implicit casting
Explicit casting
ex: int x = 10; —> double y = x;
ex : int x = (int)10.0;