AP Computer Science Class: Primitive Type
AP Computer Science Class: Primitive Type
Primitive Type
1. Inline comment
• 2 slashes: //
• Function: Tell someone a secret message. The compiler will not render inline comment
Eg: you write a long project at a school and you have to explain your professors when they
read your code:
// The first step is …
*Your code here *
// The second step is …
• Your code *
// The third step is
…
2. Difference
between println()
and print()
• Write down these code and
tell me the difference
between println() and print()
2. Difference
between println()
and print()
• Write down these code and
tell me the difference
between println() and print()
2. Difference
between
println() and
print()
2. Difference between println() and print()
• Println(): To display some text and move the cursor onto the next line
• Print(): To display some text and NOT move the cursor onto the next line
3. Semicolon
Datatype variableName;
Eg:
int number;
double gpa;
String name;
boolean fact;
4. General Form for declaring a variable and initialize it
in Java
Shortcut:
int score = 0;
score += 100;
9. Modifying
Number Variables
•Increment:
•To increment a variable means to
add to the value stored in the
variable
10. Casting a variable
1. Compile errors:
• Forgetting a semicolon at the end of an instruction
• Forgetting to put a data type for a variable
• Using a keyword as a variable name
• Forgetting to initialize a variable
• Forgetting a curly brace (a curly brace doesn’t have a
partner)
11. Types of errors: