You are on page 1of 27

Identifiers & Modifiers

Java SE
Contents

• Identifiers

• Modifiers

• Access Modifier

• Non Access Modifier


Identifiers
• Java ဘ"သ"ရပ&တ(င& အသu,-.ပuသ0&1၊ package, class, interface, method, variables တiu၏
အမည&မ8"-အ"- Identifier ဟu eခ<ပ=သည&။

• စ"လu,-အeရအတ(က&အeနနCင&1 အကD&1အသတ&မEiပ=

• အစeနစ"လu,- အeန.ဖင&1 English Letter မ8"-၊ Currency Code မ8"-၊ underscore မ8"-အ"-
အသu,-.ပuDiuင&ပ=သည&

• အစeနရ"မCလ(G၍ Digit မ8"-ကiuလည&- အသu,-.ပuDiuင&ပ=သည&

• Currency Code မ8"-DCင&1 underscore မ8"-အ"- မည&သ0&1 eနရ"တ(င& မဆiuအသu,-.ပuDiuင&ပ=သည&

• Java Keywords DCင&1 Reserved words မ8"-အ"- အသu,-.ပu၍ မရနiuင&ပ=

• eအ"က&ပ= Special Character မ8"-အ"- အသu,-.ပu၍ မရနiuင&မရနiuင&ပ=



!, @, #, %, ^, &, *, (, ),’, :, ;, [, /, \, }

• Digit မ8"-.ဖင&1 စeသ" words မ8"-အ"- အသu,-.ပu၍ မရပ=


Java Keywords
Java Code Convention
Start with upper case

Classes Should use with Noun

Camel Case
Start with upper case

Interfaces Should use with Adjectives

Camel case


Start with lower case



Methods Should use with verb-noun pair

Camel Case
Start with lower case

Variables short and meaningful names

Camel Case
static final variables are constant

Constants all should be upper case

should use underscores as seperators
Modifiers

• Java ဘ"သ"ရပ&တ(င& Class, Method, Variables မ8"-၏


Default တန&ဖiu-မ8"-အ"- e.ပ"င&-လG အသu,-.ပuလiuပ=က
Modifier မ8"-အ"- အသu,-.ပuDiuင&ပ=သည&

• Modifier မ8"-အ"- Access Modifier DCင&1 Non Access


Modifier ဟu ခ(G.ခ"-Diuင&ပ=သည&
Why we need to control
Access of members?
class Student {
String name;
int age;

void greet() {
System.out.println( My name is + name);
System.out.println( I am + age years old );
}
}
Why we need to control
Access of members?
public class Test {
public static void main(String [] args) {
Student s = new Student();
s.name = Aung Aung ;
s.age = -10;
s.greet();
Can’t control it’s own
} state
}
Access Modifier
• Variable, Method DCင&1 Class တiuသည& Default
အတiuင&-eရ-သ"-ထ"-ပ=က ၎င&-တiuDCင&1 Package တစ&ခu
အတ(င&-တ(င& အတLတက(eရ-သ"-ထ"-eသ" Class မ8"-မC
ဆက&သ(ယ& အသu,-.ပuDiuင&ပ=သည&

• သiuရ"တ(င& Default Access အ"- .ပu.ပင&NပO- အသu,-.ပuလiuပ=က


Access Modifier မ8"-ကiu အသu,-.ပuDiuင&သည&

• အသu,-.ပuDiuင&eသ" Access Modifier မ8"-မC" public,


default, protected DCင&1 private တiu.ဖစ&Pကသည&
Access Modifiers
Modifiers Descriptions

public မည&သ0&1eနရ"မC မဆiu ဆက&သ(ယ& အသu,-.ပuDiuင&မည&

Access Modifier အ"- eရ-သ"-ထ"-.ခင&-မEiပ=က


default
Package အတ(င&-Ei Class မ8"-မC ဆက&သ(ယ&Diuင&မည&

ထiu Class အ"- Inheritance လuပ&ထ"-eသ" Class


protected
မ8"-မC ဆက&သ(ယ&Diuင&မည&

ထiu Class အတ(င&-မC တ.ခ"-


private
ဆက&သ(ယ&Diuင&မည&မဟuတ&eပ
Using Private to protect it’s
own state
class Student { Can’t access from
private String name; other class
private int age;

public Student(String name, int age) {


// controls codes
}

void greet() {
System.out.println( My name is + name);
System.out.println( I am + age years old );
}
}
Non Access Modifiers
• abstract • synchronized

• static • volatile

• final • native

• strictfp

• transient
static modifier
• static modifier အ"- variable, method DCင&1 nested class,
nested interface တiuတ(င& အသu,-.ပuDiuင&ပ=သည&

• static variable မ8"-သည& class မ8"-DCင&1သ" သက&ဆiuင&NပO- JVM


တစ&ခuလu,-တ(င& တစ&ခuတည&-သ" တည&Eiမည&.ဖစ&သည&

• အလ"-တLပင& static method မ8"-သည&လG class DCင&1သ"


သက&ဆiuင&NပO- static variable မ8"-ကiuသ" အသu,-.ပuDiuင&မည& .ဖစ&ပ=သည&

• static nested class DCင&1 nested interfaces မ8"-အePက"င&-ကiu


eန"က& အခန&-မ8"-တ(င& eဖ<.ပပ=မည&
abstract modifier
• abstract modifier အ"- class, interface DCင&1 method တiuတ(င&
eရ-သ"-Diuင&ပ=သည&

• class မ8"-သည& object မ8"-၏ abstraction .ဖစ&သည&ဟu ဆiuပ=သည&

• object မ8"-သည& အစစ&အမCန&.ဖစ&ပ=က class မ8"-သည& သeဘ" တရ"-ကiuသ"


eဆ"င&ပ=သည&

• class မ8"-၏ abstraction ကiu eရ-သ"-လiuသည& အခ=မ8iu-တ(င& abstract modifier


ကiu အသu,-.ပuNပO- abstract မ8"-ကiu eရ-သ"-Diuင&မည&.ဖစ&သည&

• အuပ&စuတLeသ" Class တiuတ(င& သeဘ"တရ"-eဆ"င&eသ" method တစ&ခuကiu


ပiuင&ဆiuင&eစလiuသ0&1 အခ=မ8iu-တ(င& abstract modifier ကiu သu,-NပO- eရ-သ"-Diuင&ပ=သည&
Abstraction of Classes
abstract class
• class အeQတ(င& abstract modifier ကiu အသu,-.ပuNပO- eရ-သ"-ထ"-ပ=က ထiu class
အ"- abstract class အ.ဖစ& သတ&မCတ&မည& .ဖစ&သည&

• မတLညOeသ" class မ8"-အ"- အမ8iu-အစ"- တစ&စu အ.ဖစ&အသu,-.ပuလiueသ"


အခ=မ8iu-တ(င& abstract class မ8"-ကiu အသu,-.ပuပ=သည&

• abstract class မ8"-မC တiuက&Riuက& Object မ8"-အ"- တည&eဆ"က&Diuင&မည&


မဟuတ&ပ=

• ၎င&-အ"- extends လuပ&ထ"-eသ" class မ8"-မC တဆင&1သ" Object ကiu


eဆ"က&လuပ&Diuင&မည& .ဖစ&ပ=သည&

• abstract class မ8"-တ(င& လiuအပ&ပ=က abstract method မ8"-ကiu


eရ-သ"-Diuင&ပ=သည&
abstract class
public abstract class LivingThings {
public abstract void breath();
}

public class Human extends LivingThings {


public void breath() {
System.out.println( breath with ည
lungs );
}
}
Using Abstract Class
public static void takeBreath(LivingThing … ls) {
// codes
}

public static void main(String [] args) {


LivingThings lv1 = new Human();
LivingThings lv2 = new Fish();
LivingThings lv3 = new Bird();

takeBreath(lv1, lv2, lv3);


}
abstract method
• abstract modifier ကiu အသu,-.ပuNပO- abstract method မ8"-ကiu eရ-သ"-Diuင&ပ=သည&

• abstract method မ8"-သည& abstract class အ"- extends လuပ&ထ"-eသ" sub


class မ8"-တ(င& Eiသင&1ePက"င&- eဖ<.ပထ"-eသ" method မ8"- .ဖစ&eသ"ePက"င&
method name, arguments DCင&1 return type (method signature)
သ"eရ-သ"- ရန&လiuအပ&NပO- method body အ"- eရ-သ"- ရန&မလiuအပ&ပ=

• abstract class အ"- extends လuပ&ထ"-eသ" sub class မ8"-တ(င& abstract


class အတ(င&-ပ=ဝင&eသ" abstract method မ8"-အ"- override လuပ&က"
behaviour မ8"-အ"- အ.ပည&အစu,eရ-သ"-eပ-ရမည& .ဖစ&သည&

• abstract method မ8"-အ"- abstract class DCင&1 interface မ8"-တ(င&သ"


eရ-သ"-Diuင&မည& .ဖစ&ပ=သည&
Interface and abstraction
• Interface တစ&ခuသည& class တစ&ခuမC တည&eဆ"က&ထ"-eသ" Object မ8"-အ"-
.ပင&ပမC ဆက&သ(ယ& အသu,-.ပuDiuင&eသ" method မ8"-အ"- စuစည&-eဖ<.ပeပ-ရ"တ(င&
အသu,-.ပuပ=သည&

• ထiuePက"င&1 Interface အတ(င&-စuစည&-ထ"-eသ" method မ8"-တ(င&


မည&သiuလuပ&eဆ"င&မည&ကiu eရ-သ"- ထ"-.ခင&-မEiပG မည&သiuEiရမည& ဆiuသည&ကiuသ"
eဖ<.ပထ"-ပ=သ0&1 abstract method မ8"-ပင&.ဖစ&သည&

• မည&သiuလuပ&eဆ"င&မည& ဆiuသည&ကiu Interface အ"- implements လuပ&ထ"-eသ"


Class မ8"-တ(င& eရ-သ"-ရပ=မည&

• Interface မ8"-သည& Abstract Entity .ဖစ&eသ" ePက"င&1 Interface


အတ(င&-eရ-သ"- ထ"-eသ" method မ8"-သည& default အတiuင&- public abstract
.ဖစ&eနမည& .ဖစ&ပ=သည&
final modifier
• final modifier အ"- class, method DCင&1 variable မ8"-တ(င& eရ-သ"-Diuင&ပ=သည&

• final class မ8"-သည& eန"က&ဆu,- class .ဖစ&.ခင&-ePက"င&1 အ.ခ"-eသ"- class


မ8"-မC တဆင&1 extends လuပ&Diuင&မည& မဟuတ&ပ=

• final method မ8"-သည&လG Sub Class မ8"-မC တဆင&1 Override လuပ&Diuင&.ခင&-


မEiပ=

• final variable မ8"-အ"-လG eန"က&ပiuင&-တ(င& တန&ဖiu-အ"- e.ပ"င&-လG Diuင&eတ"1မည&


မဟuတ&ပ=

• final modifier အ"- Abstract entity .ဖစ&eသ" Interface မ8"-တ(င&


eရ-သ"-Diuင&.ခင&- မEiပ=
abstract vs final
• abstract DCင&1 final modifier တiuသည& ဆD&1က8င&ဘက& သeဘ"-ကiu eဆ"င&ပ=သည&

• abstract class မ8"-သည& class မ8"-၏ abstraction .ဖစ&eသ"ePက"င&1 ၎င&-အ"-


အ.ခ"-eသ" class မ8"-မC extends လuပ&ရန&လiuအပ&ပ=သည&

• final class မ8"-သည& eန"က&ဆu,- class မ8"-.ဖစ&eသ"ePက"င&1 ၎င&-အ"-


အ.ခ"-eသ" class မ8"-မC extends လuပ&Diuင&မည&မဟuတ&eပ

• အလ"-တLပင& abstract method မ8"-အ"- sub class မ8"-မC override


လuပ&ရန&လiuအပ&NပO-၊ final method မ8"-သည& eန"က&ဆu,- method
မ8"-.ဖစ&eသ"ePက"င&1 sub class မ8"-မC override လuပ&Diuင&မည&မဟuတ&ပ=

• ထiuePက"င&1 abstract DCင&1 final modifier တiuအ"- တeနရ"ထGတ(င& အတLတက(


အသu,-.ပuDiuင&မည&မဟuတ&ပ=
synchronized modifier
• methods မ8"- DCင&1 code block မ8"-တ(င&
eရ-သ"-Diuင&ပ=သည&

• Multi Thread မ8"-မC synchronized method မ8"-DCင&1


code block မ8"-အ"- အသu,-.ပuရ"တ(င& Thread တစ&ခu
လuပ&eဆ"င&eနစT& အ.ခ"- Thread မ8"-အ"- အNပiuင&
လuပ&eဆ"င&လiuမရeအ"င& Lock လuပ&eပ-ထ"-Diuင&ပ=သည&

• synchronized modifier အ"- class, interface DCင&1


variable တiuတ(င& eရ-သ"-လiuမရနiuင&ပ=
volatile modifier
• volatile modifier အ"- variable
မ8"-တ(င&eရ-သ"-Diuင&ပ=သည&

• volatile variable မ8"-အ"- မတLညOeသ" Thread မ8"-မC


တန&ဖiu-e.ပ"င&-သည& အခ=မ8iu-တ(င& လu,.ခu,စ("
e.ပ"င&-လGDiuင&မည&.ဖစ&သည&

• volatile modifier အ"- class, interface DCင&1 method


မ8"-တ(င& eရ-သ"-Diuင&မည&မဟuတ&ပ=
native modifier
• method မ8"-တ(င& eရ-သ"-Diuင&ပ=သည&

• C, C++ ကG1သiu အ.ခ"-eသ"- ဘ"သ"ရပ&.ဖင&1


eရ-သ"-ထ"-eသ" Method မ8"- Library မ8"- အ"-
အသu,-.ပueသ" Method မ8"- တ(င& native modifier အ"-
eရ-သ"-ရန&လiuအပ&ပ=သည&

• class, interface DCင&1 variable တiuတ(င& native modifier


အ"- eရ-သ"-လiuမရနiuင&ပ=
strictfp modifier
• strictfp modifier အ"- class, interface DCင&1 method
မ8"-တ(င&eရ-သ"-Diuင&ပ=သည&

• strictfp အ"- အသu,-.ပu.ခင&-အ"-.ဖင&1 မည&သ0&1 platform


မ8iu-မဆiu floating number မ8"-အ"- တ(က&ခ8က&ရ"တ(င&
တLညO စ(" တ(က&ခ8က&Diuင&မည& .ဖစ&သည&

• strictfp modifier အ"- variable မ8"-တ(င& မeရ-သ"-Diuင&ပ=


transient modifier
• transient modifier မ8"-အ"- instance variable မ8"-တ(င& eရ-သ"-Diuင&ပ=သည&

• Memory အeပ<Ei Object မ8"-အ"- Physical Memory


အeပ<တ(င&သiမ&-ဆည&-.ခင&-အ"- Serialise လuပ&သည&ဟu eခ<ပ=သည&

• Object မ8"-အ"- Serialize လuပ&ရ"တ(င& Object ၏ State ကiu eဖ<.ပeသ"


instance variable မ8"-အ"- သiမ&-ဆည&- eပ-မည&.ဖစ&သည&

• Serialize မလuပ&လiueသ" Variable မ8"-တ(င& transient modifier ကiu


သမCတ&eရ-သ"-Diuင&ပ=သည&

• class, interface DCင&1 method မ8"-တ(င& transient modifier ကiu


eရ-သ"-Diuင&.ခင&- မEiပ=

You might also like