»ÃÐÇѵÔÀÒÉÒ JAVA
ÀÒÉÒ¨ÒÇÒ à»š¹ÀÒÉÒâ»Ãá¡ÃÁàªÔ§Çѵ¶Ø·Õè¾Ñ²¹Ò¢Öé¹
â´Â Dr.James Gosling áÅзÕÁÇÔÈǡâͧà¢Ò «Ö觺ÃÔÉÑ·
Sun Micr...
¤ÇÒÁËÁÒÂÀÒÉÒ¨ÒÇÒ (Java Language)
ÀÒÉÒ¨ÒÇÒ (Java Language) ¤×Í ÀÒÉÒ¤ÍÁ¾ÔÇàµÍÏ
·Õè¶Ù¡¾Ñ²¹Ò¢Öé¹â´ÂºÃÔÉÑ· Sun Microsystems à»...
¨Ø´à´‹¹¢Í§ÀÒÉÒ¨ÒÇÒ (Java Language)
1) ໚¹ÀÒÉÒÊíÒËÃѺ¡ÒÃà¢Õ¹â»Ãá¡ÃÁàªÔ§Çѵ¶Ø
(OOP: Object Oriented Programming)
2) Java ¤...
ª¹Ô´¢Í§â»Ãá¡ÃÁ Java
1) Java Application
໚¹¡ÒùíÒâ»Ãá¡ÃÁ Java ÁÒà¢Õ¹໚¹â»Ãá¡ÃÁ·ÕèÊÒÁÒö¹íÒÁÒ㪌
§Ò¹ä´ŒÍ‹ҧÍÔÊÃЪ¹Ô´¢Í§...
â¤Ã§ÊÌҧ ÀÒÉÒ Java
µÑÇÍ‹ҧઋ¹
public class ª×èͤÅÒÊ
{
public static void main(String[] agrs)
{
»ÃÐ⤤íÒÊÑ觵‹Ò§æ ¢Í§â»...
â¤Ã§ÊÌҧ ÀÒÉÒ Java
à¤Ã×èͧËÁÒ 㹡ÒäǺ¤ØÁ Structure
1.1 Comment ¤×Í¢ŒÍ¤ÇÒÁ·Õèá·Ã¡à¢ŒÒä»ã¹â»Ãá¡ÃÁ ᵋäÁ‹Áռŵ‹Í¡ÒÃ
·íÒ§Ò¹...
â¤Ã§ÊÌҧ ÀÒÉÒ Java
1.4 Separators ¤×Í ÍÑ¡ÉÃËÃ×Íà¤Ã×èͧËÁÒ·Õè㪌ẋ§á¡¤íÒã¹ÀÒÉÒ ÁÕ
´Ñ§µ‹Í仹Õé!
- à¤Ã×èͧËÁÒ () 㪌ÊíÒË...
â¤Ã§ÊÌҧ ÀÒÉÒ Java
- à¤Ã×èͧËÁÒÂ{ }㪌ÊíÒËÃѺ
¡íÒ˹´¢Íºà¢µ¢Í§ method áÅÐ class
ઋ¹ class A{
}
Private void hello(){
}
2....
â¤Ã§ÊÌҧ ÀÒÉÒ Java
- à¤Ã×èͧËÁÒ [ ] 㪌ÊíÒËÃѺ
1. ¡íÒ˹´µÑÇ á»ÃẺ Array
ઋ¹ String a[ ];
2. ¡íÒ˹´¤‹Ò index ¢Í§µÑÇ á»Ã...
àÁ¸Í´áÊ´§¼Å·Ò§¨ÍÀÒ¾¾×é¹°Ò¹
¡ÒÃÃѺ¢ŒÍÁÙÅ·Ò§¤ÕºÍÏ´ã¹ÀÒÉÒ¨ÒÇҨеŒÍ§ÊÌҧÍͺà¨ç¡µ¢Í§
¤ÅÒÊ Scanner ¢Öé¹ÁÒâ´Â¨ÐµŒÍ§»ÃСÒȵÑÇ...
à​Á¸Í´ÊíÒËÃѺ͋ҹ¢ŒÍÁÙÅ»ÃÐàÀ·µ‹Ò§æ
àÁ¸Í´ ¡Ò÷íÒ§Ò¹
nextByte() ÃѺ¢ŒÍÁÙÅàÅ¢¨Ò¹Ç¹àµçÁª¹Ô´ Byte ·Ò§á»‡¹¾ÔÁ¾
nextDouble() ÃѺ...
àÁ¸Í´áÊ´§¼Å·Ò§¨ÍÀÒ¾¾×é¹°Ò¹
ã¹ÀÒÉÒ¨ÒÇÒ¨Ð㪌àÁ¸Í´ print áÅÐ println 㹡ÒÃáÊ´§¼Å·Ò§¨ÍÀÒ¾
â´Â¨ÐÍÂÙ‹ã¹Íͺà¨ç¡µ out «Öè§ÍÂً㹤...
Escape sequence ÊíÒËÃѺàÁ¸Í´áÊ´§¼Å·Ò§¨ÍÀÒ¾¾×é¹°Ò¹
escape sequence ª×èÍ ¤ÇÒÁËÁÒÂ
n Newline ¢Ö鹺Ã÷ѴãËÁ‹
t Horizontal tab ...
ª¹Ô´¢Í§¢ŒÍÁÙÅ µÑÇá»ÃáÅФ‹Ò¤§·Õè
ª¹Ô´¢Í§¢ŒÍÁÙÅ µÑÇá»ÃáÅФ‹Ò¤§·Õè
ã¹ÀÒÉÒ¨ÒÇÒẋ§¢ŒÍÁÙÅÍ͡໚¹Êͧ»ÃÐàÀ·ãËÞ‹æ ¤×Í
1. ¢ŒÍÁÙÅẺ...
ª¹Ô´¢Í§¢ŒÍÁÙÅ µÑÇá»ÃáÅФ‹Ò¤§·Õè
¢ŒÍÁÙÅẺµÃáÐ
ÁÕ 2 ¤‹Ò ¤×Í true(¨ÃÔ§) ¡Ñº false(à·ç¨)
¢ŒÍÁÙÅẺµÑÇÍÑ¡¢ÃÐ
µÑÇÍÑ¡¢ÃÐÁÕ¤ÇÒÁÂ...
ª¹Ô´¢Í§¢ŒÍÁÙÅ µÑÇá»ÃáÅФ‹Ò¤§·Õè
»ÃÐàÀ·¢ŒÍÁÙÅ ¢¹Ò´ ª‹Ç§¡ÒÃà¡çº¢ŒÍÁÙÅ
boolean 1 ºÔµ à¡çº true ËÃ×Í false
char 2 亵 à¡çºÃËÑ...
ª¹Ô´¢Í§¢ŒÍÁÙÅ µÑÇá»ÃáÅФ‹Ò¤§·Õè
¡ÒáíÒ˹´ª×èÍáÅФՏàÇÔÏ´ ÁÕ¡®´Ñ§¹Õé
1. ¢Öé¹µŒ¹´ŒÇ A – Z , a – z , $ ËÃ×Í _ à·‹Ò¹Ñé¹
2. ...
¡ÒôíÒà¹Ô¹¡Ò÷ҧ¤³ÔµÈÒʵÏ
µÑÇ´íÒà¹Ô¹¡Ò÷ҧ¤³ÔµÈÒʵÏ
µÑÇ´íÒà¹Ô¹¡Òà ¤ÇÒÁËÁÒ µÑÇÍ‹ҧ¹Ô¾¨¹
+ ºÇ¡ total = const + tax;
- Å...
¡ÒôíÒà¹Ô¹¡Ò÷ҧ¤³ÔµÈÒʵÏ
µÑÇ´íÒà¹Ô¹¡Ò÷ҧ¤³ÔµÈÒʵÏẺ‹Í
ÅíҴѺ¤ÇÒÁÊíÒ¤Ñޢͧà¤Ã×èͧËÁÒ 1.() 2.++,-- 3.%,/,* 4.+,-
5.<,...
¡ÒôíÒà¹Ô¹¡Ò÷ҧ¤³ÔµÈÒʵÏ
ã¹ÀÒÉÒ¨ÒÇÒ »ÃÐ⤠(statement) ¨Ð¨º´ŒÇÂà¤Ã×èͧËÁÒ ;
(semicolon) àÊÁÍ ´Ñ§¹Ñé¹â»Ãá¡ÃÁÊÒÁÒöà¢Õ¹ ...
¡ÒÃà»ÅÕ蹢ͧ¢ŒÍÁÙÅ
¡ÒÃà»ÅÕè¹»ÃÐàÀ·¢Í§¢ŒÍÁÙÅ
¤ÍÁä¾àÅÍÏÀÒÉÒ¨ÒÇÒÊÒÁÒöá»Å§¢ŒÍÁÙÅãËŒÁÕÃٻẺ·ÕèÊÍ´¤ÅŒÍ§¡Ñ¹ä´Œ ÁÕ 2 ÃٻẺ¤×...
¡ÒÃà»ÅÕ蹢ͧ¢ŒÍÁÙÅ
ã¹ÀÒÉÒ¨ÒÇÒÁÕ¡ÒÃà»ÅÕè¹á»Å§»ÃÐàÀ·¢ŒÍÁÙŴѧ¹Õé
1. ¶ŒÒµÑǶ١´íÒà¹Ô¹¡ÒõÑÇ˹Öè§à»š¹ double µÑǶ١´íÒà¹Ô¹¡Ò...
¤ÅÒÊʵÃÔ§
¡ÒÃÊÌҧ String
String ໚¹ Class ˹Öè§ã¹ Package ¢Í§ÀÒÉÒ¨ÒÇÒª×èÍ java.lang ·íÒ
˹ŒÒ·Õèã¹ ¡ÒÃà¡çº¢ŒÍÁÙÅ·Õè໚¹ “...
¤ÅÒÊʵÃÔ§
àÃÒÊÒÁÒöàÃÕ¡㪌àÁ¸Í´ä´Œâ´ÂàÃÕ¡µÑÇá»Ã͌ҧÍÔ§¢Öé¹µÒÁ´ŒÇÂ
à¤Ã×èͧËÁÒ¨شáÅеÒÁ´ŒÇÂàÁ¸Í´ «Öè§ÁÕÃٻẺ´Ñ§¹Õé
µÑÇá»...
¡ÒÃ㪌 import
ã¹ÀÒÉÒ¨ÒÇÒ¤ÅÒʵ‹Ò§æ¨Ð¶Ù¡ÃÇÁänj໚¹á¾ç¡à¡¨«Öè§ÊÒÁÒöàÃÕ¡㪌´ŒÇÂ
¤íÒÊÑè§ import
à¾×èͺ͡ãËŒ¤ÍÁä¾àÅÍÏÃٌNjҨÐ...
พื้นฐานภาษา Java
พื้นฐานภาษา Java
Próximos SlideShares
Carregando em…5
×

พื้นฐานภาษา Java

240 visualizações

Publicada em

บทที่2 พื้นฐานภาษา Java

Publicada em: Educação
0 comentários
0 gostaram
Estatísticas
Notas
  • Seja o primeiro a comentar

  • Seja a primeira pessoa a gostar disto

Sem downloads
Visualizações
Visualizações totais
240
No SlideShare
0
A partir de incorporações
0
Número de incorporações
21
Ações
Compartilhamentos
0
Downloads
3
Comentários
0
Gostaram
0
Incorporações 0
Nenhuma incorporação

Nenhuma nota no slide

พื้นฐานภาษา Java

  1. 1. »ÃÐÇѵÔÀÒÉÒ JAVA ÀÒÉÒ¨ÒÇÒ à»š¹ÀÒÉÒâ»Ãá¡ÃÁàªÔ§Çѵ¶Ø·Õè¾Ñ²¹Ò¢Öé¹ â´Â Dr.James Gosling áÅзÕÁÇÔÈǡâͧà¢Ò «Ö觺ÃÔÉÑ· Sun Microsystems µŒÍ§¡ÒùíÒÀÒÉÒ¨ÒÇÒÁÒ㪌᷹ ÀÒÉÒ C++ ¨¹ã¹»‚ ¤.È. 1995 ÀÒÉÒ¨ÒÇÒàÃÔèÁ໚¹·Õè¹ÔÂÁ á¾Ã‹ËÅÒÂ
  2. 2. ¤ÇÒÁËÁÒÂÀÒÉÒ¨ÒÇÒ (Java Language) ÀÒÉÒ¨ÒÇÒ (Java Language) ¤×Í ÀÒÉÒ¤ÍÁ¾ÔÇàµÍÏ ·Õè¶Ù¡¾Ñ²¹Ò¢Öé¹â´ÂºÃÔÉÑ· Sun Microsystems ໚¹ÀÒÉÒ ÊíÒËÃѺà¢Õ¹â»Ãá¡ÃÁ·ÕèʹѺʹع¡ÒÃà¢Õ¹â»Ãá¡ÃÁàªÔ§ Çѵ¶Ø (OOP : Object-Oriented Programming) â»Ãá¡ÃÁ·Õèà¢Õ¹¢Ö鹶١ÊÌҧÀÒÂ㹤ÅÒÊ ´Ñ§¹Ñ鹤ÅÒʤ×Í·Õè à¡çºàÁ·Í´ (Method) ËÃ×;ĵԡÃÃÁ (Behavior) «Öè§ÁÕ Ê¶Ò¹Ð (State) áÅÐÃÙ»¾Ãó (Identity) »ÃШíÒ ¾ÄµÔ¡ÃÃÁ (Behavior)
  3. 3. ¨Ø´à´‹¹¢Í§ÀÒÉÒ¨ÒÇÒ (Java Language) 1) ໚¹ÀÒÉÒÊíÒËÃѺ¡ÒÃà¢Õ¹â»Ãá¡ÃÁàªÔ§Çѵ¶Ø (OOP: Object Oriented Programming) 2) Java ¤×Í platform independence ËÁÒ¤ÇÒÁÇ‹Ò ¤ÇÒÁÊÒÁÒö¢Í§â»Ãá¡ÃÁ·Õèà¢Õ¹´ŒÇ java ÊÒÁÒö·íҧҹ䴌㹠Ãкº»¯ÔºÑµÔ¡Ò÷Õè µ‹Ò§¡Ñ¹ â´ÂäÁ‹µŒÍ§´Ñ´á»Å§á¡Œä¢ãËÁ‹ 3) Free áÅР໚¹â»Ãá¡ÃÁ»ÃÐàÀ· Open Source
  4. 4. ª¹Ô´¢Í§â»Ãá¡ÃÁ Java 1) Java Application ໚¹¡ÒùíÒâ»Ãá¡ÃÁ Java ÁÒà¢Õ¹໚¹â»Ãá¡ÃÁ·ÕèÊÒÁÒö¹íÒÁÒ㪌 §Ò¹ä´ŒÍ‹ҧÍÔÊÃЪ¹Ô´¢Í§â»Ãá¡ÃÁ Java 2) Java Applets ໚¹¡ÒùíÒ Java ÁÒà¢Õ¹໚¹â»Ãá¡ÃÁઋ¹à´ÕÂǡѹ ᵋäÁ‹ÊÒÁÒö àÃÕ¡㪌§Ò¹ä´ŒµÒÁÅíҾѧ µŒÍ§¹íÒÁÒãÊ‹äÇŒã¹àÍ¡ÊÒà HTML áÅŒÇ㪌 â»Ãá¡ÃÁ Web Browser ËÃ×Í Utilities ¢Í§ Java à¾×èÍàÃÕ¡´Ù¼ÅÅѾ¸
  5. 5. â¤Ã§ÊÌҧ ÀÒÉÒ Java µÑÇÍ‹ҧઋ¹ public class ª×èͤÅÒÊ { public static void main(String[] agrs) { »ÃÐ⤤íÒÊÑ觵‹Ò§æ ¢Í§â»Ãá¡ÃÁ; ..................................................; } }
  6. 6. â¤Ã§ÊÌҧ ÀÒÉÒ Java à¤Ã×èͧËÁÒ 㹡ÒäǺ¤ØÁ Structure 1.1 Comment ¤×Í¢ŒÍ¤ÇÒÁ·Õèá·Ã¡à¢ŒÒä»ã¹â»Ãá¡ÃÁ ᵋäÁ‹Áռŵ‹Í¡Òà ·íÒ§Ò¹ ¢Í§â»Ãá¡ÃÁ ઋ¹ã¹¡Ã³Õ·ÕàÃÒµŒÍ§¡ÒÃ͸ԺÒ Source code änj㹠â»Ãá¡ÃÁ ÇÔ¸Õ¡Òä×Í - comment ·ÕÅÐ ºÃ÷Ѵ㪌à¤Ã×èͧËÁÒ // µÒÁ´ŒÇ¢ŒÍ¤ÇÒÁ·ÕµŒÍ§¡Òà comment 1.2 Keyword ¤×ͤíÒ·Õ¶Ù¡¡íÒ˹´änj㪌àͧáÅŒÇã¹ÀÒÉÒ Java äÁ‹ÊÒÁÒö ¹íÒÁÒ㪌㹡ÒõÑ駪×èÍÀÒÂã¹â»Ãá¡ÃÁä´Œ µÑÇÍ‹ҧઋ¹ class,boolean,char ໚¹µŒ¹ 1.3 Identifiers ¤×ͪ×èÍ·Õè¼ÙŒà¢Õ¹µÑ駢Öé¹ÁÒ à¾×èÍ㪌᷹ÍÐäáçä´ŒäÁ‹Ç‹Ò¨Ð໚¹ method ,µÑÇá»Ã ËÃ×Í class ª×èÍ·Õè¶Ù¡µŒÍ§¤ÇûÃСͺ´ŒÇ µÑÇÍÑ¡Éà ,µÑÇàÅ¢ ,_,$ áÅШеŒÍ§¢Öé¹: µŒ¹´ŒÇµÑÇÍÑ¡ÉÃà·‹Ò¹Ñé¹
  7. 7. â¤Ã§ÊÌҧ ÀÒÉÒ Java 1.4 Separators ¤×Í ÍÑ¡ÉÃËÃ×Íà¤Ã×èͧËÁÒ·Õè㪌ẋ§á¡¤íÒã¹ÀÒÉÒ ÁÕ ´Ñ§µ‹Í仹Õé! - à¤Ã×èͧËÁÒ () 㪌ÊíÒËÃѺ 1. µ‹Í·ŒÒª×èÍ method äÇŒãËŒãÊ‹ parameter ઋ¹ private void hello( ); 2. ÃкØà§×è͹䢢ͧ if , while , for ,do ઋ¹ if ( i=0 ) 3. Ãкت×èÍ ª¹Ô´¢ŒÍÁÙÅ㹡Òà ·íÒ casting ઋ¹ String a=( String )x;
  8. 8. â¤Ã§ÊÌҧ ÀÒÉÒ Java - à¤Ã×èͧËÁÒÂ{ }㪌ÊíÒËÃѺ ¡íÒ˹´¢Íºà¢µ¢Í§ method áÅÐ class ઋ¹ class A{ } Private void hello(){ } 2. ¡íÒ˹´¤‹ÒàÃÔÁµŒ¹ãËŒ ¡ÑºµÑÇá»Ã Array ઋ¹ String a[]={"A","B","C"};
  9. 9. â¤Ã§ÊÌҧ ÀÒÉÒ Java - à¤Ã×èͧËÁÒ [ ] 㪌ÊíÒËÃѺ 1. ¡íÒ˹´µÑÇ á»ÃẺ Array ઋ¹ String a[ ]; 2. ¡íÒ˹´¤‹Ò index ¢Í§µÑÇ á»Ã array ઋ¹ a[ 0 ]=10; - à¤Ã×èͧËÁÒ ; 㪌à¾×èÍ »´»ÃÐ⤠ઋ¹ String a ; - à¤Ã×èͧËÁÒ , 㪌ÊíÒËÃѺ 1. ᡪ×è͵ÑÇá»Ãã¹»ÃÐ⤠ઋ¹ String a , b , c; - à¤Ã×èͧ ËÁÒ . 㪌ÊíÒËÃѺ 1. ᡪ×èÍ package, sub package áÅЪ×èÍ class ઋ¹ package com.test.Test1; 2. 㪌à¾×èÍ àÃÕ¡㪌 µÑÇ á»Ã ËÃ×Í method ¢Í§ Object ઋ¹ object.hello();
  10. 10. àÁ¸Í´áÊ´§¼Å·Ò§¨ÍÀÒ¾¾×é¹°Ò¹ ¡ÒÃÃѺ¢ŒÍÁÙÅ·Ò§¤ÕºÍÏ´ã¹ÀÒÉÒ¨ÒÇҨеŒÍ§ÊÌҧÍͺà¨ç¡µ¢Í§ ¤ÅÒÊ Scanner ¢Öé¹ÁÒâ´Â¨ÐµŒÍ§»ÃСÒȵÑÇá»ÃÍͺà¨ç¡µ¡‹Í¹ ઋ¹ Scanner keyboard; »ÃСÒȵÑÇá»ÃÍͺà¨ç¡µª×èÍ keyboard ÍÂً㹤ÅÒÊ Scanner ¨Ò¡¹Ñé¹µŒÍÊÌҧÍͺà¨ç¡µ ÁÒâ´Â㪌¤ÕàÇÔÏ´ new ÁÕÃٻẺ´Ñ§¹Õé µÑÇá»ÃÍͺà¨ç¡µ = new ª×èͤÅÒÊ(ÍÒÏ¡ÔÇàÁ¹µ); ´Ñ§¹Ñ鹶ŒÒ¨ÐãËŒµÑÇá»Ã keyboard ÃѺ¤‹Ò·Ò§á»‡¹¾ÔÁ¾¨ÐµŒÍ§ÊÃŒÒÍͺà¨ç¡µ¢Öé¹ÁÒâ´Â ãËŒÁÕÍÒÏ¡ÔÇàÁ¹µà»š¹ System.in ´Ñ§¹Õé keyboard = new Scanner(System.in); 㹤ÅÒÊ Scanner ¹Ñé¹à​Á¸Í´ÊíÒËÃѺ͋ҹ¢ŒÍÁÙÅ»ÃÐàÀ·µ‹Ò§æËÅÒ»ÃÐàÀ· ´Ñ§¹Õé
  11. 11. à​Á¸Í´ÊíÒËÃѺ͋ҹ¢ŒÍÁÙÅ»ÃÐàÀ·µ‹Ò§æ àÁ¸Í´ ¡Ò÷íÒ§Ò¹ nextByte() ÃѺ¢ŒÍÁÙÅàÅ¢¨Ò¹Ç¹àµçÁª¹Ô´ Byte ·Ò§á»‡¹¾ÔÁ¾ nextDouble() ÃѺ¢ŒÍÁÙÅàÅ¢·È¹ÔÂÁª¹Ô´ Double ·Ò§á»‡¹¾ÔÁ¾ nextFloat() ÃѺ¢ŒÍÁÙÅàÅ¢·È¹ÔÂÁª¹Ô´ Float ·Ò§á»‡¹¾ÔÁ¾ nextInt() ÃѺ¢ŒÍÁÙÅàÅ¢¨Ò¹Ç¹àµçÁª¹Ô´ Int ·Ò§á»‡¹¾ÔÁ¾ nextLine() ÃѺ¢ŒÍÁÙÅẺʵÃÔ§·Ò§á»‡¹¾ÔÁ¾ nextLong() ÃѺ¢ŒÍÁÙŵÑÇàÅ¢ª¹Ô´ Long ·Ò§á»‡¹¾ÔÁ¾ nextShort() ÃѺ¢ŒÍÁÙŵÑÇàÅ¢ª¹Ô´ Short ·Ò§á»‡¹¾ÔÁ¾
  12. 12. àÁ¸Í´áÊ´§¼Å·Ò§¨ÍÀÒ¾¾×é¹°Ò¹ ã¹ÀÒÉÒ¨ÒÇÒ¨Ð㪌àÁ¸Í´ print áÅÐ println 㹡ÒÃáÊ´§¼Å·Ò§¨ÍÀÒ¾ â´Â¨ÐÍÂÙ‹ã¹Íͺà¨ç¡µ out «Öè§ÍÂً㹤ÅÒÊ System ÃٻẺ¡ÒÃ㪌§Ò¹àÁ¸Í´ ·Ñé§Êͧ¤×Í System.out.print(data); System.out.println(data); â´Â data ໚¹¢ŒÍÁÙÅ·Õ赌ͧ¡ÒÃáÊ´§¼Å ¡ÒÃ㪌 print ËÅѧ¨ÒáÊ´§¼Å áŌǨÐäÁ‹¢Ö鹺Ã÷ѴãËÁ‹ ʋǹ println ¨Ð¢Ö鹺Ã÷ѴãËÁ‹ 㹡ÒÃáÊ´§¼Å´ŒÇÂàÁ¸Í´ print ËÃ×Í println ¹Ñé¹ÊÒÁÒö㪌 escape sequence ÊíÒËÃѺ¤Çº¤ØÁ¡ÒÃáÊ´§¼Åä´Œ´Ñ§µ‹Í仹Õé
  13. 13. Escape sequence ÊíÒËÃѺàÁ¸Í´áÊ´§¼Å·Ò§¨ÍÀÒ¾¾×é¹°Ò¹ escape sequence ª×èÍ ¤ÇÒÁËÁÒ n Newline ¢Ö鹺Ã÷ѴãËÁ‹ t Horizontal tab á·çºá¹Ç¹Í¹ b Backspace ¶ÍÂËÅѧ 1 ª‹Í§µÑÇÍÑ¡Éà r Return àÅ×è͹à¤ÍÏà«ÍÏ仫ŒÒÂÊØ´ Backslash µÑÇÍÑ¡Éà ’ Single quote µÑÇÍÑ¡Éà ’ ” Double quote µÑÇÍÑ¡Éà “
  14. 14. ª¹Ô´¢Í§¢ŒÍÁÙÅ µÑÇá»ÃáÅФ‹Ò¤§·Õè ª¹Ô´¢Í§¢ŒÍÁÙÅ µÑÇá»ÃáÅФ‹Ò¤§·Õè ã¹ÀÒÉÒ¨ÒÇÒẋ§¢ŒÍÁÙÅÍ͡໚¹Êͧ»ÃÐàÀ·ãËÞ‹æ ¤×Í 1. ¢ŒÍÁÙÅẺ¾×é¹°Ò¹ 2. ¢ŒÍÁÙÅẺ͌ҧÍÔ§ «Ö觨Ðᵡµ‹Ò§¡Ñ¹µÃ§¡ÒÃ͌ҧ¶Ö§µíÒá˹‹§Ë¹‹Ç¤ÇÒÁ¨íÒ «Ö觢ŒÍÁÙÅẺ͌ҧÍÔ§¨ÐÍÂÙ‹ ã¹ËÑÇ¢ŒÍ¢Í§ÊµÃÔ§ËÃ×ÍÍÒÏàÏ ÊÒËÃѺ¢ŒÍÁÙÅẺ¾×é¹°Ò¹ ¨ÐÁÕÊÕè¡ÅØ‹Á¤×Í 1.¢ŒÍÁÙÅ ª¹Ô´µÃáР2.¢ŒÍÁÙŪ¹Ô´ÍÑ¡¢ÃÐ 3.¢ŒÍÁÙŪ¹Ô´¨Ò¹Ç¹àµçÁ 4.¢ŒÍÁÙŪ¹Ô´àÅ¢ ·È¹ÔÂÁ
  15. 15. ª¹Ô´¢Í§¢ŒÍÁÙÅ µÑÇá»ÃáÅФ‹Ò¤§·Õè ¢ŒÍÁÙÅẺµÃáРÁÕ 2 ¤‹Ò ¤×Í true(¨ÃÔ§) ¡Ñº false(à·ç¨) ¢ŒÍÁÙÅẺµÑÇÍÑ¡¢ÃÐ µÑÇÍÑ¡¢ÃÐÁÕ¤ÇÒÁÂÒÇäÁ‹à¡Ô¹ 1 µÑÇÍÑ¡ÉèÐ㪌¤íÒÇ‹Ò char 㹡ÒÃà¡çº¢ŒÍÁÙÅŧ˹‹Ç¤ÇÒÁ ¨íÒ´ŒÇÂÃËÑÊ Unicode ¡ÒáíÒ˹´¢ŒÍÁÙŵŒÍ§ÍÂÙ‹ã¹à¤Ã×èͧËÁÒ ‘ ‘ ËÃ×Í¡íÒ˹´à»š¹¤‹ÒÃËÑÊUnicode â´ÂµÃ§â´Â㪌ÊÑÞÅѡɳ u ¹íÒ˹ŒÒáŌǵÒÁ´ŒÇÂàÅ¢°Ò¹ÊԺˡ¢Í§ÃËÑʹÑ鹡çä´Œ ¢ŒÍÁÙÅẺàÅ¢¨Ò¹Ç¹àµçÁ ÁÕ 4 »ÃÐàÀ· ¤×Í byte, short, int áÅÐ long «Ö觵‹Ò§¡Ñ¹µÃ§¢¹Ò´Ë¹‹Ç¤ÇÒÁ¨Ò·Õè㪌à¡çº àÁ×èÍ»ÃСÒȵÑÇ á»ÃáÅŒÇÊÒÁÒö¡íÒ˹´¤‹ÒãËŒµÑÇá»Ã䴌ઋ¹¡Ñ¹ ᵋ¶ŒÒµÑÇá»Ã໚¹ª¹Ô´ long ¨ÐµŒÍ§ãÊ‹ l ËÃ×Í L µÒÁËÅѧ áÅÐÂѧ ÊÒÁÒö¡íÒ˹´à»š¹àÅ¢°Ò¹ÊԺˡâ´Â㪌 0x ¹Ò˹ŒÒµÑÇàŢ䴌´ŒÇ ¢ŒÍÁÙŪ¹Ô´àÅ¢·È¹ÔÂÁ ÁÕ 2 ª¹Ô´ ¤×Í float ¡Ñº double â´Â float ¨Ð㪌˹‹Ç¤ÇÒÁ¨Ò 32 ºÔµ ʋǹ double ¨Ð㪌 64 ºÔµ¶ŒÒ¨Ð ¡íÒ˹´ãËŒ¢ŒÍÁÙÅ໚¹ float ¨ÐµŒÍ§ÁÕ f ËÃ×Í F µÒÁËÅѧ
  16. 16. ª¹Ô´¢Í§¢ŒÍÁÙÅ µÑÇá»ÃáÅФ‹Ò¤§·Õè »ÃÐàÀ·¢ŒÍÁÙÅ ¢¹Ò´ ª‹Ç§¡ÒÃà¡çº¢ŒÍÁÙÅ boolean 1 ºÔµ à¡çº true ËÃ×Í false char 2 亵 à¡çºÃËÑÊÍÑ¡¢ÃÐẺ Unicode byte 1 亵 -128 ¶Ö§ +127 short 2 亵 -32,768 ¶Ö§ +32,767 int 4 亵 -2,147,483,648 ¶Ö§ +2,147,483,647 long 8 亵 -263 ¶Ö§ +263 - 1 float 4 亵 +-3.4 x 10-38 ¶Ö§ +-3.4 x 10+38 double 8 亵 +- 1.7 x 10-308 ¶Ö§ +- 1.7 x 10+308
  17. 17. ª¹Ô´¢Í§¢ŒÍÁÙÅ µÑÇá»ÃáÅФ‹Ò¤§·Õè ¡ÒáíÒ˹´ª×èÍáÅФՏàÇÔÏ´ ÁÕ¡®´Ñ§¹Õé 1. ¢Öé¹µŒ¹´ŒÇ A – Z , a – z , $ ËÃ×Í _ à·‹Ò¹Ñé¹ 2. µÑǵ‹ÍÁÒ໚¹àÅ¢ËÃ×͵ÑÇÍÑ¡¢ÃеÒÁ¢ŒÍ 1 ¡çä´Œ 3. µÑǾԾÁãËÞ‹áÅÐàÅç¡ÁÕ¤ÇÒÁËÁÒµ‹Ò§¡Ñ¹ 4. µŒÍ§äÁ‹ÁÕàÇŒ¹ÇÃäÃÐËÇ‹Ò§¡ÒõÑ駪×èÍ 5. µŒÍäÁ‹«éíҡѺ¤ÕàÇÔÏ´·Õè¨ÒÇÒÃÙŒ¨Ñ¡ ¤‹Ò¤§·Õè 㪌 final »ÃСÒȤ‹Ò¤§·Õèâ´ÂÁÕÃٻẺ´Ñ§¹Õé final ª¹Ô´¢ŒÍÁÙÅ ª×èͤ‹Ò¤§·Õè = ¤‹Ò¢Í§¢ŒÍÁÙÅ;
  18. 18. ¡ÒôíÒà¹Ô¹¡Ò÷ҧ¤³ÔµÈÒʵÏ µÑÇ´íÒà¹Ô¹¡Ò÷ҧ¤³ÔµÈÒʵÏ µÑÇ´íÒà¹Ô¹¡Òà ¤ÇÒÁËÁÒ µÑÇÍ‹ҧ¹Ô¾¨¹ + ºÇ¡ total = const + tax; - ź cost = total – tax; * ¤Ù³ tax = cost * rate; / ËÒà saleprice = original / 2 % ËÒÃàÍÒàÈÉ ramainder = value % 3;
  19. 19. ¡ÒôíÒà¹Ô¹¡Ò÷ҧ¤³ÔµÈÒʵÏ µÑÇ´íÒà¹Ô¹¡Ò÷ҧ¤³ÔµÈÒÊµÃáººÂ‹Í ÅíҴѺ¤ÇÒÁÊíÒ¤Ñޢͧà¤Ã×èͧËÁÒ 1.() 2.++,-- 3.%,/,* 4.+,- 5.<,>,<=,>= 6.= =,!= 7.&& 8.ll 9.=,+=,-=,*=,/=,%=
  20. 20. ¡ÒôíÒà¹Ô¹¡Ò÷ҧ¤³ÔµÈÒʵÏ ã¹ÀÒÉÒ¨ÒÇÒ »ÃÐ⤠(statement) ¨Ð¨º´ŒÇÂà¤Ã×èͧËÁÒ ; (semicolon) àÊÁÍ ´Ñ§¹Ñé¹â»Ãá¡ÃÁÊÒÁÒöà¢Õ¹ statement ä´Œ ÁÒ¡¡Ç‹Ò˹Öè§Ê൨àÁç¹µã¹Ë¹Ö觺Ã÷Ѵ¢Í§ source code ËÃ×ÍÊÒÁÒö à¢Õ¹ statement â´ÂÁÕ¤ÇÒÁÂÒÇÁÒ¡¡Ç‹Ò˹Ö觺Ã÷Ѵ¡çÊÒÁÒö·íÒä´Œ Expression ËÁÒ¶֧ »ÃÐâ¤ã¹ÀÒÉÒ Java ·Õèä´ŒÃѺ¡ÒÃÂÍÁÃѺ Ç‹ÒÍÂÙ‹ã¹ÃٻẺ·Õèä´Œ¡íÒ˹´äÇŒ ¡ÒÃà¢Õ¹ code ãËŒÁÕÃٻẺ·Õè àËÁÒÐÊÁ ͋ҹ䴌§‹Ò ¨Ð·íÒãËŒ¡ÒþѲ¹Òâ»Ãá¡ÃÁ໚¹ä»ä´Œ´ŒÇ¤ÇÒÁ ÃÇ´àÃçÇáÅР໚¹·ÕèÂÍÁÃѺµÒÁÃкºÊÒ¡Å ÃٻẺ·ÕèàËÁÒÐÊÁ¹Ñ蹤×Í ¡Òà ‹Í˹ŒÒ (indentation) à¾×èÍãËŒ¡ÒÃÍ‹Ò¹·íÒä´Œ§‹Ò áÅÐÁͧ ´ÙÊǧÒÁ
  21. 21. ¡ÒÃà»ÅÕ蹢ͧ¢ŒÍÁÙÅ ¡ÒÃà»ÅÕè¹»ÃÐàÀ·¢Í§¢ŒÍÁÙÅ ¤ÍÁä¾àÅÍÏÀÒÉÒ¨ÒÇÒÊÒÁÒöá»Å§¢ŒÍÁÙÅãËŒÁÕÃٻẺ·ÕèÊÍ´¤ÅŒÍ§¡Ñ¹ä´Œ ÁÕ 2 ÃٻẺ¤×Í - ¡ÒÃá»Å§¢ŒÍÁÙÅãËŒÁÕ¢¹Ò´ãËÞ‹¢Öé¹ - ¡ÒÃá»Å§¢ŒÍÁÙÅãËŒÁÕ¢¹Ò´àÅç¡Å§ â´Â·ÑèÇä»ÁÑ¡¨Ðà»ÅÕè¹¢ŒÍÁÙÅãËŒÁÕ¢¹Ò´ãËÞ‹¢Öé¹ à¾ÃÒжŒÒËÒ¡á»Å§¢ŒÍÁÙÅãËŒÁÕ¢¹Ò´àÅç¡Å§ÍÒ¨·ÒãËŒ ¡ÒûÃÐÁÇżŢŒÍÁÙÅà¡Ô´¤ÇÒÁàÊÕÂËÒÂä´Œ ¡ÒÃá»Å§¢¹Ò´¢ŒÍÁÙÅâ´Â Cast Operator ã¹ÀÒÉÒ¨ÒÇÒÊÒÁÒöá»Å§¢ŒÍÁÙÅ¢¹Ò´ãËÞ‹ãËŒÁÕ¢¹Ò´àÅç¡Å§ä´Œâ´Â㪌 Cast Operator «Ö觨Рà¢Õ¹»ÃÐàÀ·¢ŒÍÁÙÅ·Õ赌ͧ¡ÒÃá»Å§äÇŒã¹Ç§àÅ纴ŒÒ¹Ë¹ŒÒµÑÇá»Ã·Õ赌ͧ¡Òà ઋ¹ x = (int)number; á»Å§¢ŒÍÁÙÅã¹ number ãˌ໚¹»ÃÐàÀ· int ¡‹Í¹áÅŒÇà¡çºänj㹵ÑÇá»Ã x (x µŒÍ§à»š¹ int ´ŒÇÂ)
  22. 22. ¡ÒÃà»ÅÕ蹢ͧ¢ŒÍÁÙÅ ã¹ÀÒÉÒ¨ÒÇÒÁÕ¡ÒÃà»ÅÕè¹á»Å§»ÃÐàÀ·¢ŒÍÁÙŴѧ¹Õé 1. ¶ŒÒµÑǶ١´íÒà¹Ô¹¡ÒõÑÇ˹Öè§à»š¹ double µÑǶ١´íÒà¹Ô¹¡ÒÃÍÕ¡µÑǨÐà»ÅÕè¹໚¹ double 2. ¶ŒÒµÑǶ١´íÒà¹Ô¹¡ÒõÑÇ˹Öè§à»š¹ float µÑǶ١´íÒà¹Ô¹¡ÒÃÍÕ¡µÑÇ·ÕèÁÕ¢¹Ò´àÅ硡NjҨж١ à»ÅÕè¹໚¹ float 3. ¶ŒÒµÑǶ١´íÒà¹Ô¹¡ÒõÑÇ˹Öè§à»š¹àÅ¢¨íҹǹàµçÁ µÑǶ١´íÒà¹Ô¹¡ÒÃÍÕ¡µÑÇ໚¹ long µÑǶ١´Òà¹Ô¹¡ÒÃÍÕ¡µÑǨж١à»ÅÕè¹໚¹ long
  23. 23. ¤ÅÒÊʵÃÔ§ ¡ÒÃÊÌҧ String String ໚¹ Class ˹Öè§ã¹ Package ¢Í§ÀÒÉÒ¨ÒÇÒª×èÍ java.lang ·íÒ Ë¹ŒÒ·Õèã¹ ¡ÒÃà¡çº¢ŒÍÁÙÅ·Õè໚¹ “ªØ´¢Í§µÑÇÍÑ¡ÉÔ «Ö觻¡µÔª¹Ô´¢Í§¢ŒÍÁÙŢͧÀÒÉÒ¨ÒÇÒ¡çÁÕ ª¹Ô´à»š¹ character ᵋà¡çº¢ŒÍÁÙÅä´Œà¾Õ§ 1 µÑÇÍÑ¡ÉÃà·‹Ò¹Ñé¹ ´Ñ§¹Ñé¹ ¨Ö§ÅíҺҡ㹡Òà ¹íÒÁÒ㪌¡Ñº¢ŒÍÁÙÅ·ÕèÁÒ¡¡Ç‹Ò 1 µÑÇÍÑ¡Éà ËÃ×Í·ÕàÃÕÂ¡Ç‹Ò “String” ´Ñ§¹Ñé¹ ÀÒÉÒ¨ÒÇÒ ¨Ö§ä´ŒÊÌҧ Class ÊíÒàÃç¨ÃÙ»ÁÒãËŒÊÒÁÒöàÃÕ¡㪌䴌·Ñ¹·Õ àÃÕÂ¡Ç‹Ò “String” ·Ñé§ËÁ´ ¤×Í·ÕèÁҢͧ¤íÒÇ‹Ò String Class
  24. 24. ¤ÅÒÊʵÃÔ§ àÃÒÊÒÁÒöàÃÕ¡㪌àÁ¸Í´ä´Œâ´ÂàÃÕ¡µÑÇá»Ã͌ҧÍÔ§¢Öé¹µÒÁ´ŒÇ à¤Ã×èͧËÁÒ¨شáÅеÒÁ´ŒÇÂàÁ¸Í´ «Öè§ÁÕÃٻẺ´Ñ§¹Õé µÑÇá»Ã.àÁ¸Í´(ÍÒ¡ÔÇàÁ¹µ)
  25. 25. ¡ÒÃ㪌 import ã¹ÀÒÉÒ¨ÒÇÒ¤ÅÒʵ‹Ò§æ¨Ð¶Ù¡ÃÇÁänj໚¹á¾ç¡à¡¨«Öè§ÊÒÁÒöàÃÕ¡㪌´ŒÇ ¤íÒÊÑè§ import à¾×èͺ͡ãËŒ¤ÍÁä¾àÅÍÏÃٌNjҨйíÒ¤ÅÒÊÁÒ¨Ò¡·Õèã´ â´Âà¢Õ¹¤íÒÊÑè§ import äÇŒ·Õè ʋǹËÑǢͧâ»Ãá¡ÃÁ ઋ¹¡ÒÃ㪌§Ò¹¤ÅÒÊ Scanner ¨ÐµŒÍ§à¢Õ¹´Ñ§¹Õé import java.util.Scanner ໚¹¡ÒÃàÃÕ¡㪌¤ÅÒÊ Scanner ·Õèà¡çºÍÂÙ‹ã¹ util â´Â util ¹Õéà¡çºÍÂÙ‹ã¹ á¾ç¡à¡¨ËÅÑ¡ª×èÍ java

×