Uploaded by snowdenrin.it

Java Environment

advertisement
Java Program Development Steps
q Java program တစ္ခု၏ compiling ႏွင့္ executing process မ်ားကို
ေအာက္တြင္ေဖာ္ျပထားသည္။
One time only
Editor
Hello.java
Java
Compiler
Every time
Hello.class
Java Runtime
by Zaw Htet Aung
Java
Interpreter
Java Program Development Steps
Task
Tool to use
Output
Write the program
Any text editor
File with .java extension
Compile the program
Java Compiler
File with .class
extension(Java bytecodes)
Run the program
Java Interpreter
Program Output
by Zaw Htet Aung
Java Development Environment
q Option 1 – code ေရးသားရန္အတြက္ text editor တစ္ခုအသံုးျပဳၿပီး
JDK မွ command line java tools(javac) ကိုအသံုးျပဳၿပီး compile
လုပ္ပါ။ထို႔ေနာက္ execution လုပ္ရန္အတြက္ “java” ဆိုသၫ့္
command line java tools ကိုအသံုးျပဳပါ။
q Options 2 – IDE (Integrated Development Environment)
ကိုအသံုးျပဳပါ။
v NetBeans
v Eclipse
v Intellij IEDA
by Zaw Htet Aung
Tools to Use
q Text Editor
v Examples : Sublime Text, Note++, Textmate(Mac only),
Notepad(Windows only),Emacs
q Java command line tools (environment ျပင္ဆင္ထားရန္လ)ို
v javac – compiler, user for compilation
v java – java runtime (java interpreter), use for execution
by Zaw Htet Aung
My First “Helloworld” Java Program
1. public class HelloWorld{
2.
/**
3.
* My first Java program
4.
*/
5. public static void main(String [ ] args ) {
6.
// prints the string “Hello world” on screen
7.
System.out.println(“Hello world”);
8.
}
9. }
by Zaw Htet Aung
Use Text Editor & Commandline Tools
q Step 1: Using text editor, write Java program
v Name it “HelloWorld.java”
q Step 2: Compile the Java program
v javac HelloWorld.java
q Step 3: Run the Java program
v java HelloWorld
by Zaw Htet Aung
Build and run Java Program using
Command-line Tools
by Zaw Htet Aung
Build and run Java Program using
IDE
by Zaw Htet Aung
What is IDE?
q Integrated Development Environment(IDE) ဟာဆိုရင္ၿပီးျပၫ့္စံု
တဲ ့Application Development Environment ကိုေထာက္ပံ့ေပး
ပါတယ္။
v Code editor(with many conveniences such as syntax
highlighting)
v Built-in compiler
v Built-in debugger
v Built-in tester
v Many more built-in features
q Popular IDE’s
v Eclipse or STS (free), NetBeans (Free), IntelliJ
IDEA(Free/Commercial)
by Zaw Htet Aung
Syntax Errors & Runtime Errors
q Syntax(Compile) Errors
v Errors ေတြဟာ အမ်ားအားျဖင့္ေတာ့ typing errors
ေတြအျဖစ္မ်ားပါတယ္။
v Compile time တြင္ ရွာေဖြေတြ႔ရိွခဲ့သၫ့္အတြက္ compile errors
ဟုေခၚဆိုသည္။
q Common Syntax Errors
q Java မွာရိွတဲ့ keyword ေတြမွားေရးတာမ်ိဳး
q statement ရဲ႕ အဆံုးမွာ semi-colon ေမ့ေနတာမ်ိဳး
by Zaw Htet Aung
Syntax Errors & Runtime Errors
q Run-time Errors
v Program ကို မ run ခင္အခ်ိန္အထိ မည္သၫ့္ error မ်ိဳးကိုမွ
ျပသမည္မဟုတ္ေပ။
v ဥပမာ
vမင္းရဲ႕ program ဟာ user ဆီကေန number ေတြပဲ လက္ခံ
ေစခ်င္ေသာ္လည္း user က String ကို႐ိုက္ထည့္ လိုက္တာမ်ိဳး
(ထိုအခါ မင္းရဲ႕ program ဟာ exception ကို
ျဖစ္ပြားေစပါတယ္)
by Zaw Htet Aung
Anatomy of Java Class
The name of
this class
Keyword
public class HelloWorld{
The return type void
mean there’s no return
value.
public static void main(String [ ] args){
method’s name
Public
So,
Every
can
access it
System.out.println (“Hello World”) ;
}
}
by Zaw Htet Aung
This says print
to standard
output(default
to commandline)
The String you want
to print
Every Statement Must
end in a semicolon!
Dissecting “Helloworld” Sample
App
1. public class HelloWorld{
2.
/**
3.
* My first Java program
4.
*/
5. public static void main(String [ ] args ) {
6.
// prints the string “Hello world” on screen
7.
System.out.println(“Hello world”);
8.
}
9. }
by Zaw Htet Aung
Class Declaration
public class HelloWorld {
q class ၏ အမည္အား HelloWorld ဟုအမည္ေပးထားသည္။
q ၎ class တြင္ access modifier public ကိုေရးသားထားသည္။
ထို႔ေၾကာင့္ ထို class အားအျခားမည္သၫ့္ class မွမဆို
ယူငင္သံုးစြဲႏိုင္သည္။
by Zaw Htet Aung
Start of code block
public class HelloWorld {
q Curly brace { သည္ code block တစ္ခု၏ အစ ျဖစ္သည္။
q ယခု code တြင္ curly brace အား HelloWorld ၏ေနာက္တြင္ေရးသား
ထားသည္။ ထိုကဲ့သို႔မဟုတ္ပဲ curly brace အား ေနာက္တစ္ေၾကာင္း
ဆင္း၍ လည္း ေရးသားႏိုင္သည္။ ဥပမာ public class Hello
{
by Zaw Htet Aung
Comment
/**
* My first Java program
*/
q အထက္ေဖာ္ျပပါ ၃ ေၾကာင္းသည္ Java comment တစ္ခုျဖစ္သည္။
q comment မ်ားကို မိမိေရးသားထားေသာ code မ်ားကို မထိခိုက္ေစပဲ
မွတ္စုမ်ား code ၏ ရည္ရြယ္ခ်က္မ်ားကို program အတြင္းထၫ့္သြင္း
ေရးသား လိုသၫ့္အခါ အသံုးျပဳသည္။
q program မ်ားေရးသားရာတြင္ code မ်ားကိုထၫ့္သြင္းေရးသားျခင္း သည္
ေကာင္းေသာ အေလ့အက်င့္တစ္ခုျဖစ္သည္။
by Zaw Htet Aung
main(..) method
public static void main(String [ ] args ) {
q main( ) method သည္ special method တစ္ခုျဖစ္သည္။၎သည္
Java program တစ္ခု၏ starting point ျဖစ္သည္။
q main( ) method မွာ အၿမဲတမ္း String array ပံုစံ argument တစ္ခု
ပါရမည္။
by Zaw Htet Aung
Another Comment
// prints the string “Hello world” on screen
q ၎ စာေၾကာင္းသည္ single line java comment တစ္ခုျဖစ္သည္။
q java တြင္ comment ေရးသားရာတြင္ နည္း(၃) နည္းျဖင့္ ေရးသားႏိုင္
သည္။
by Zaw Htet Aung
System.out.println(..)
System.out.println(“Hello world”);
q System.out.println(“something to print”);
q ၎ စာေၾကာင္းသည္ မိမိ print ထုတ္လိုေသာ အရာအား doublequotation အတြင္းတြင္ ေရးသားကာconsole တြင္ print ထုုတ္ႏိုင္
သည္။
by Zaw Htet Aung
Ending Method and Class blocks
System.out.println(“Hello world”);
}
}
q ၎ close curly braces (၂) ခုတြင္ အေပၚ close curly brace သည္
method ၏ အပိတ္ျဖစ္သည္ ေအာက္ close curly brace သည္ class
၏ အပိတ္ျဖစ္သည္။
by Zaw Htet Aung
Download