Cheatography
https://cheatography.com
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 Scanner(System.in) |
2- Use the method (ex: nextDouble() ) to obtain to (double) value [ double = input.nextDouble ();] |
Reading numbers from the keyboard
Import
Implicit import (الضمني) |
Explicit import (الصريح) |
java.util.*; |
java.util.Scanner; |
Identifiers (شروط التسميه)
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- declaring[التصريح] |
هو تعريف المتغير مع تحديد نوعه دون إعطائه قيمة |
int x; |
2- Assignment[الإسناد] |
هو إعطاء قيمة للمتغير بعد التصريح عنه |
x = 3; |
3- declaring and initialisation[التصريح و التهيئة] |
هو تعريف المتغير وإعطائه قيمة ابتدائية في نفس السطر |
int x = 3; |
Naming Conventions
Choose meaningful and descriptive names |
1 - variables and method names: |
Use lowercase, ex variable : area , ex method : computeArea |
2- Class names: |
Capitalise the first letter of each word in the name, ex : ComputeArea |
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- concatenate all into one
2- use lowercase for the first word
3- capitalise the first letter of each subsequent word
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 programming :
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 :
Complication 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 Expressions
احول الصيغة اللي فوق الى صيغة تفهمها الجافا
الضرب لازم يكون بعلامة*
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; |
|