Whitespace:
-
Whitespace contains blanks, tabs, and newline characters
-
Seperates individual words and symbols
-
There will always be whitespace
-
Whitespace makes code cleaner/easier to read
Errors:
-
Syntax are the rules of a coding language that must be followed
-
Semantics represent the meaning of the code
-
Three types of errors:
-
Complier errors:
-
Will stop compiliation
-
Typically are syntax errors
-
-
Runtime errors:
-
Terminates the program when trying to run
-
Stack Trace: error message that contains statements/methods that were active when the error occured
-
Typically a semantics error
-
-
Logical errors:
-
Will continue to run, but incorrectly
-
Caused due to a semantic error
-
Usually no error messages
-
-
-
Debugging is to find and fix errors in a program
Comments:
-
Java contains three types of comments
-
Line comments:
- Is a single line
- Starts with //
//This is a comment
-
Block comments:
- Can span multiple lines
/*
* Line 1
* Line 2
*/
-
Javadoc comments:
- Used by a tool called javadoc
- Auto creates formatted html files with code description
/**
* Line 1
* Line 2
**/
Variables and Constants:
-
Place in memory that stores a value/data
-
Use camel casing when naming
- Ex. itemCost
-
Assign variables using the β=β operator
- Can create and assign variables in the same line
-
Variables have scope, which represents where it can be accesed in a program
- A method canβt see variables delcared inside of another
-
To make a variable a constant, add the keyword final before the variable type:
- This makes the value of the variable unmodifiable
final int myNum = 59;
Primitive Types:
-
List of all primitive types:
- Integer based values:
-
Byte (8-bits): Stores whole numbers from -128 to 127
-
Short (16-bits): Stores whole numbers from -32,768 to 32,767
-
Int (32-bits): Stores whole numbers from -2,147,483,648 to 2,147,483,647
-
Long (64-bits): Stores whole numbers from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
- Real number values (floating point):
-
Float (32-bits): Stores fractional numbers with 6 to 7 decimals
-
Double (64-bits): Stores fractional numbers with 15 to 16 decimals
- Logical values:
-
Boolean: Stores true/false
- individual values:
-
Char: Stores a single character
Default Types (Numerical Types):
-
Values are given default types:
-
Number literal == int
-
Floating point == double
-
-
You can append a special letter to a value to change its default type:
-
Long = 10L or 10l
-
Float = 10.0F or 10.0f
-
Double = 10D or 10d or 10.0
-
-
Multiple type allow more control over the size of the data in a program
Char:
-
Represents an individual character
-
Characters donβt follow a sematically logical order (Ex. 1,2,3)
-
Due to this, character sets have been created
-
Java uses the UNICODE character set which includes:
-
Contains 65,536 characters
-
ACII (numbers, letters, punctuation, space, extra special characters)
-
Symbols and letters from other languages
-
-
-
-
To assign a char, use single quotes β:
char let = 'B';
Escape Sequences:
-
Used to assign values such as β or β
-
Always contains two characters:
-
The first is always the ""
-
The second is the actual character
-
char quote = '\'';
char tab = '\t';
char newLine = '\n';
char carrigeReturn = '\r';
char backslash = '\\';
char doubleQuote = '\"';
Boolean:
- Can only show true/false
boolean yes = true;
boolean no = false;
Arithmetic Expressions and Operators:
-
Math equations
-
Must only return one value
-
Arithmetic operators:
-
All are binary operators (Can be applied to two numbers)
-
Addition == β+β
-
Subtraction == β-β
-
Multiplication == β*β
-
Division == β/β
-
Remainder/Modulus == β%β
-