Key points:
1. // - single line comment, source codes that starts with this is not executed.
2. /* */ - multi-line comments, source codes that are in-between this block comments are not executed.
3. Java is case-sensitive. HarryPotter is not the same as harrypotter.
4. The class name always starts with a letter, preferably in caps and meaningful in nature, e.g. public class MyFirstProgram
5. The class name must be the same as the filename.
6. There are many keywords that may not be used, refer to textbook figure 2.1 for a list.
7. A method is a section of a class that performs a task. e.g.
public static void main (String[] args) --> main method of a class, all classes must have a main method.
8. System.out.println("Hello") is different from System.out.print("Hello"). println prints a newline character, bringing the cursor to the next line.
9. Whatever that is encapsulated in " " denotes a string.
10. You can manipulate numbers using
- addition +
- subtraction -
- multiplication *
- division /
- modulus (remainder) %
- more than >
- less than <
- comparing equals ==
- and operator &&
- or operator ||
- not equals !=
11. Data types to remember
- integer : int : stores numbers
- double : double : stores decimals
- char : char : (see 2.3.3 of textbook for detailed information)
- boolean : boolean : true or false
12. comparing boolean expression
true && true = true
true || true = true
true && false = false
true || false = true
false && false = false
false || false = false
!true = false
!false = true
13. Joining strings or numbers
- "Hello " + "World" --> "Hello World"
- "Hello " + 21 --> "Hello 21"
No comments:
Post a Comment