You are on page 1of 4

JAVA LEARNING

Anatomy of JAVA

1. PACKAGE : A container to group related classes


2. CLASS : A container for related function
a. We use PascalNamingConvention (Use capital in every first letter)
3. METHOD : Function tha is part of the class
a. We use camelNamingConvention (Use capital in every first letter except the first
word)

Symbol in typing code in JAVA

C in blue circle : Define Class

M in red circle : Define method/function in the class

F in yellow circle : Define feild

Example :

Class Main {

void main () {

…..

Understanding

COMPILATION and EXECUTION

Compilation step

SOURCE CODE (src) JAVA Compiler Byte Code


.java .class

JAVA Virtual NATIVE CODE :


Byte Code
Machine (JVM) Windows, Mac etc

Shortcut :

- Shift + F10 : print code


- Alt + F12 : Open terminal
- Alt + 1 : open project structure
- Shift + F6 : Rename src
Terminal Command :

- Ctrl + l : Clear
-

TYPING CODE :

1. Comments
a. One line [ // ]
b. More than 1 lines [ */ /*]
2. Variables
a. Int
b. String
c. Double
3. Primitive data types (Storing simple values)

TYPE BYTES RANGE


Byte 1 [-128,127]
Short 2 [-32k, 32k]
Int 4 [-2B, 2B]
Long (add L) 8
Float (add F) 4
double 8
char 2 A,B,C
boolean 1 True, False

4. Non-Primitive/Reference data types (Storing complex object : date, mail message


5. Difference Primittive and Non-Premitive
a. Primitive : Store in different memory address [Just copy]
b. Non-primitive : Same reference
c. Primitive : storing simple values
d. Reference : Storing complex values
e. When declare Primitive, we do not allocate memory but in Reference always
allocate memory
f. Primitive type don’t have members/cannot add members to class ( letter m in red
circle) but reference can add members to class.
Example : Date now = new Date();
Now.getTime()
6. String class [Series of character]
a. Class  Name
b. Can add method/data type to charector  (name.toUpperCase()); *red font is
method OR member
c. Method can’t modify the original string but method change the new string, It is
because string cannot inmutable/unchange
d. Parameter : define / method argument : actual value
7. Package and import keyword
a. Folder project
b. Can import different packages
c. Anything come from Java.lang, there is no import
8. Reserved keyword
a. Use for language itself : Package, Public, Class Void, Main
9. Arithmetic operation
a. System.out.println(10 + 2);
10. Math class
a. To perform extra operation numbers
b. Math java.lang
c. This can add a lot of method
d. Examples Math.max  Maximum number beween 2 numbers
e. Examples : System.out.println(Math.max(2, 10));  it will print 10.0
11. Comparison operators
a. To compare values
b. Boolean [variable name] = value a > value b
c. Examples :
int khalidAge = 18;
int mariamAge = 20;
boolean compare = khalidAge > mariamAge;
System.out.println(khalidAge > mariamAge);

It will print true or false


12. Logical operators
a. Combine multiple boolean expression
13. If statements
a. Execute certain section of code depending result on boolean expression
14. Ternary operator
15. Switch statement
16. Arrays
a. Use Array to store a list of item, numbers, prople, messages
b. To create one variable and put more than one values
c. It’s put on variable to make more than one value in single variable
d. Examples :
i. For integers : int [ ] numbers = {0, 1, 2, 3};  this means 4 size of arrays
ii. String : String [ ] names = {“Ali”, “Maria”};
iii. To print : System.out.println(Arrays.toString(numbers));  will print content
iv. To print : System.out.println(numbers.length);  will print quantity of arrys
or index
17. Arrays and indexes
a. ++ means increment by 1  example : int number = 0; / number++; /
System.out.println(number);  1
b. Or we can use like this : [ += ]/[ -= ] to add more than 1  example : int number = 1;
/ number += 4; / System.out.println(number);  5
18. Multi dimensial Arrays

You might also like