ตั้งค่าการอ่าน

ค่าเริ่มต้น

  • เลื่อนอัตโนมัติ
    Java

    ลำดับตอนที่ #1 : Java I - Getting started with Java

    • เนื้อหาตอนนี้เปิดให้อ่าน
    • 44
      0
      27 ธ.ค. 61

    Getting Started

    What is Java?

              Java is a popular language that's used all around the world. You can develop all kinds of things using Java, like large scale systems, web applications, and mobile applications.

    ( Java has nothing to do with JavaScript, so don't get confused.)


    Let's Run Java

              Let's run your first Java code. You'll be doing this in a file called Main.java. The first step is printing characters. By writing characters inside the () of System.out.println(), you can print them on the Console.


     

    Strings

    In the last lesson, we printed characters in the Console. A sequence of characters, like "Hello Java", is called a string. A string needs to be enclosed in double quotes ("), or there will be an error.


     

    System.out.println

              System.out.println() is a command to print what's inside (). With Java, you can give various commands like this to a computer. Be familiar with System.out.println(), as you'll use it again and again in this lesson!

    ( The l in "println" is the lowercase letter of L).


     

    The Structure of Java

              Every Java file has a class. Inside the class, there are methods. In our example below, we have a Main class, and a main method. For now, the only thing you have to remember is that you'll be writing your code inside the main method.


    Semicolon

              Java requires a semicolon (;) at the end of every line. You'll get an error without it, so be careful!


     

    Comments

              Adding // at the beginning of a line will make the line a comment. Comments will be ignored when running the code, so you can use them to leave notes.


     

    Integers

    You can use numbers like integers in programming. Unlike strings, they don't need to be enclosed in quotes. You can add and subtract integers just like you do in math. Putting spaces before and after integers is not required, but it makes the code easier to read. 

     

    Difference between Strings and Integers

              Strings and integers are interpreted differently in programming. 5 + 2 will print 7, the result of the addition. However, if you make it a string by adding quotes, like "5 + 2", the output will be the literal string: 5 + 2.

     

    Calculations

    More Calculations

              In Java, you can do other calculations like multiplication and division, but with different symbols from what you would use in math. * is for multiplication and / is for division. You can also calculate the remainder after division using %.


    String Concatenation

              The + that we used for calculations also lets us combine strings. Combining strings is called string concatenation. Like in the image below, "5" + "3" will concatenate the two strings to become "53", instead of adding them as numbers.





    ติดตามเรื่องนี้
    เก็บเข้าคอลเล็กชัน

    นิยายที่ผู้อ่านนิยมอ่านต่อ ดูทั้งหมด

    loading
    กำลังโหลด...

    อีบุ๊ก ดูทั้งหมด

    loading
    กำลังโหลด...

    ความคิดเห็น

    ×