คำสงวน เครื่องหมายคำนวณ เปรียบเทียบ และ ตัวอักษร
Home  Contents KMArticlesMembersSponsorsAbout us

ปรับปรุง : 2556-06-20 (ปรับ template)
ขอบซ้ายขอบบน
คำสงวน เครื่องหมายคำนวณ เปรียบเทียบ และ ตัวอักษร
    สารบัญ (Content)
  1. แนวการตั้งชื่อ class
  2. เรียก method จาก .java อื่น
  3. เครื่องหมายคำนวณ หรือเปรียบเทียบ
  4. หมายเหตุ (Comments)
  5. คำสงวน (Reserved Word)
  6. Escape Sequence
  7. ระดับการเข้าถึง (Access Level) (private, protected, public, package)
  8. ศัพท์เทคนิก (Technical Term)
    Format of class
      class declaration {
        variable constructor method nested class
      }

    1. แนวการตั้งชื่อ class
    1. ถ้าโปรแกรมใดมี class เดียว ชื่อ class ควรเหมือนชื่อโปรแกรม
      c:\test.java
      class test {
        public static void main(String args[]) {
          System.out.println("a");
        }
      }
    2. ถ้ามีหลาย class จะต้องมี class หนึ่ง ที่มี main( ) เป็นโปรแกรมเริ่มต้น และชื่อ class ก็ควรเหมือนชื่อโปรแกรม
      c:\test.java
      class test {
        public static void main(String args[]) {
          new burin().ok();
        }
      }
      class burin {
        void ok() {
          System.out.println("b");   
        }
      }
      
    3. ถ้ามีหลาย class และมี class หนึ่งที่เป็น public ชื่อโปรแกรมก็ควรเหมือนชื่อ class ที่เป็น public

    2. เรียก method จาก .java อื่น
    เมื่อท่านมีโปรแกรม .java 2 โปรแกรม หากต้องการเรียนก .java โปรแกรมอื่นมาทำงาน จะต้องกำหนด ใน DOS ว่า c:\> set classpath=c:\ เป็นต้น เพื่อแจ้งให้ javac ทราบว่าต้องเรียน class จากห้องใดมีแปลด้วย หลากการแปลด้วยการพิมพ์ javac test.java ตัวแปรจะไปเรียก testsub.java มาแปล และได้แฟ้ม testsub.class ขึ้นมาโดยท่านไม่ต้องไปแปลโปรแกรมเหล่านั้นด้วยตนเอง
      c:\test.java
      class test {
        public static void main(String args[]) {
          new testsub().wow();
        }
      }
      c:\testsub.java
      class testsub {
        void wow() {
          System.out.println("a");
        }
      }
      

    3. เครื่องหมายคำนวณ หรือเปรียบเทียบ
    ClassificationOperators
    Arithmetic + - * / %
    Relational Operators < > >= <= == != && || !
    Bitwise Operators & | ^ << >> >>> - &= |= ^=
    Assignments = += -= /= %=
    Bitwise Assignments &= |= <<= >>= >>>= ^=
    Ternary Operator
    (if...else shorthand)
    ?:
    Increment ++
    Decrement --
      ตัวอย่าง
      เนื่องจากหาเครื่องหมายสำหรับหาผลหารที่ไม่มีเศษไม่เจอ เช่น ไม่มี \ หรือ div เหมือนใน VB จึงเขียนโปรแกรมทดสอบว่าทำอย่างไร จึงจะได้ผลของการหารโดยไม่มีเศษ เช่น 8 หารด้วย 3 ต้องการเลข 2 ตัวเดียว int x; x = 8/3; System.out.println(x); // 2 float a = 5/(float)3; // 1.6666666 float b = (float)5/3; // 1.6666666 double c = 5/(double)3; // 1.6666666666666667 float d = (float)(5/3); // 1.0 float e = 5/3; // 1.0

      The following 37 tokens are the operators, formed from ASCII characters:
    1. = ::
    2. > ::
    3. < ::
    4. ! ::
    5. ~ ::
    6. ? ::
    7. : ::
    8. == ::
    9. <= ::
    10. >= ::
    11. != ::
    12. && ::
    13. || ::
    14. ++ ::
    15. -- ::
    16. + ::
    17. - ::
    18. * ::
    19. / ::
    20. & ::
    21. | ::
    22. ^ ::
    23. % ::
    24. << ::
    25. >> ::
    26. >>> ::
    27. += ::
    28. -= ::
    29. *= ::
    30. /= ::
    31. &= ::
    32. |= ::
    33. ^= ::
    34. %= ::
    35. <<= ::
    36. >>= ::
    37. >>>= ::

    4. หมายเหตุ (Comments)
      มีอยู่ 2 วิธีดังนี้
      1. /* text */
      A traditional comment: all the text from the ASCII characters /* to the ASCII characters */ is ignored (as in C and C++).
      2. // text
      A end-of-line comment: all the text from the ASCII characters // to the end of the line is ignored (as in C++).

    5. คำสงวน (Reserved Word or Java Keywords)
    The following character sequences, formed from ASCII letters, are reserved for use as keywords and cannot be used as identifiers.
    1. แบบเรียงอักษร : 49 Java Keywords
    abstract boolean   break   byte         case     catch
    char     class     const   continue     default  do
    double   else      extends final        finally  float
    for      goto      if      implements   import   instanceof
    int      interface long    native       new      package
    private  protected public  return       short    static
    strictfp super     switch  synchronized this     throw
    throws   transient try     void         volatile while
    assert
    
2. แบบแยกกลุ่มใหญ่

DATA
    1. boolean 2. byte 3. char 4. double 5. final 6. float 7. int 8. long 9. short 10. static 11. strictfp 12. transient 13. void

CONTROL
    1. assert 2. break 3. case 4. catch 5. continue 6. default 7. do 8. else 9. finally 10. for 11. if 12. return 13. switch 14. synchronized 15. throw 16. throws 17. try 18. while

OBJECTS
    1. abstract 2. class 3. extends 4. implements 5. import 6. instanceof 7. interface 8. native 9. new 10. package 11. private 12. protected 13. public 14. super 15. this 16. volatile

Unused
    1. const 2. goto
    3. แบบแยกกลุ่มย่อย (9 กลุ่ม = 49 keywords)
    1. Access Modifiers
    private : Makes a method or a variable accessible only from within its own class.
    protected : Makes a method or a variable accessible only to classes in the same package or subclasses of the class.
    public : Makes a class, method, or variable accessible from any other class.
    2. Class, Method, and Variable Modifiers
    abstract : Used to declare a class that cannot be instantiated, or a method that must be implemented by a nonabstract subclass.
    class : Keyword used to specify a class.
    extends : Used to indicate the superclass that a subclass is extending.
    final : Makes it impossible to extend a class, override a method, or reinitialize a variable.
    implements : Used to indicate the interfaces that a class will implement.
    interface : Keyword used to specify an interface.
    native : Indicates a method is written in a platform-dependent language, such as C.
    new : Used to instantiate an object by invoking the constructor.
    static : Makes a method or a variable belong to a class as opposed to an instance.
    strictfp : Used in front of a method or class to indicate that floating-point numbers will follow FP-strict rules in all expressions.
    synchronized : Indicates that a method can be accessed by only one thread at a time.
    transient : Prevents fields from ever being serialized. Transient fields are always skipped when objects are serialized.
    volatile : Indicates a variable may change out of sync because it is used in threads.
    3. Flow Control
    break : Exits from the block of code in which it resides.
    case : Executes a block of code, dependent on what the switch tests for.
    continue : Stops the rest of the code following this statement from executing in a loop and then begins the next iteration of the loop.
    default : Executes this block of code if none of the switch-case statements match.
    do : Executes a block of code one time, then, in conjunction with the while statement, it performs a test to determine whether the block should be executed again.
    else : Executes an alternate block of code if an if test is false.
    for : Used to perform a conditional loop for a block of code.
    if : Used to perform a logical test for true or false.
    instanceof : Determines whether an object is an instance of a class, superclass, or interface.
    return : Returns from a method without executing any code that follows the statement (can optionally return a variable).
    switch : Indicates the variable to be compared with the case statements.
    while : Executes a block of code repeatedly while a certain condition is true.
    4. Error Handling
    catch : Declares the block of code used to handle an exception.
    finally : Block of code, usually following a try-catch statement, which is executed no matter what program flow occurs when dealing with an exception.
    throw : Used to pass an exception up to the method that called this method.
    throws : Indicates the method will pass an exception to the method that called it.
    try : Block of code that will be tried, but which may cause an exception.
    assert : Evaluates a conditional expression to verify the programmer’s assumption.
    5. Package Control
    import : Statement to import packages or classes into code.
    package : Specifies to which package all classes in a source file belong.
    6. Primitives
    boolean : A value indicating true or false.
    byte : An 8-bit integer (signed).
    char : A single Unicode character (16-bit unsigned)
    double : A 64-bit floating-point number (signed).
    float : A 32-bit floating-point number (signed).
    int : A 32-bit integer (signed).
    long : A 64-bit integer (signed).
    short : A 16-bit integer (signed).
    7. Variable Keywords
    super : Reference variable referring to the immediate superclass.
    this : Reference variable referring to the current instance of an object.
    8. Void Return Type Keyword
    void : Indicates no return type for a method.
    9. Unused Reserved Words
    const : Do not use to declare a constant; use public static final.
    goto : Not implemented in the Java language. It’s considered harmful.

    6. Escape Sequence
    \b		\u0008: backspace BS 
    \t		\u0009: horizontal tab HT 
    \n		\u000a: linefeed LF 
    \f		\u000c: form feed FF 
    \r		\u000d: carriage return CR 
    \"		\u0022: double quote " 
    \'		\u0027: single quote ' 
    \\		\u005c: backslash \ 
    OctalEscape	 \u0000 to \u00ff: from octal value 
    ตัวอย่างการใช้
    class test {
      public static void main(String args[]) {
        System.out.println("a" + "\n" + "b" + "\n");
      }
    }
    
    

7. ระดับการเข้าถึง (Access Level)
Access Level ?
SpecifierClassPackageSubclassWorld
public////
protected///.
no modifier//..
private/...

8. ศัพท์เทคนิก (Technical Term)
- UML (Unified Modeling Language) : ภาษาใช้แสดงแบบจำลองการทำงานของระบบ หรือโปรแกรม
- JAVA Applet : โปรแกรมที่ถูกนำไปใช้ทำงานใน web browser
- JAVA Application : โปรแกรมที่ทำงานด้วยตนเองเหมือนภาษาระดับสูง เช่น C++ หรือ VB
- Servlets : โปรแกรมที่นำไปใช้ทำงานบนเว็บเซิร์ฟเวอร์ เพื่อเป็นแม่ข่ายของแต่ละเว็บไซต์
- JRE (Java Runtime Environment) : ส่วนสนับสนุนให้ Java สามารถทำงานได้
- public : คำใช้ประกาศ method ให้ class หรือ method อื่น เรียกไปใช้ได้
- static : คำใช้ประกาศตัวแปร หรือ object ถ้าประกาศตัวแปรต้องประกาศในระดับ class ถ้าไม่กำหนด static ให้ตัวแปร จะไม่สามารถใช้ตัวแปรใน object ที่ประกาศแบบ static ได้ ส่วนการประกาศ static ให้ object จะหมายถึงการไม่ยอมให้สร้าง object ลูกอีก
- void : คำใช้ประกาศ method โดยไม่มีการส่งค่าใด ๆ คืน
- JBuilder : editor for JAVA ( Tutorial by Michael J. Donahoo )
- Reserve Words หรือ Keywords : คำนำไปสร้างเป็นตัวแปร หรือชื่อ class ไม่ได้
"Imagination is more important than knowledge" - Albert Einstein
Home
Thaiabc.com
Thainame.net
Lampang.net
Nation university
PHP
MySQL
Visual basic.NET
TabletPC
Linux
Online quiz
Download
Search engine
Web ranking
Add website
Blog : Education
Blog : ACLA
Blog : Lampang
Facebook.com
Twitter.com
About us
My dream
Site map
Sponsor
http://goo.gl/72BPC