This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|| - or | |
&& - and | |
! - not | |
switch - The expression is compared with the values of each case, if none match, then the default is used, if there isn't a default, nothing happens | |
case - Used in a switch-case statement to specify a case | |
default - The default block of code in a switch statement, if it's the last statement, it doesn't need a break | |
Notes on switch-case statements: | |
- The variable used in a switch statement can only be an integer/byte/short/char/strings/enums |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Some of these may have errors as i was too lazy to check if they work or not | |
//Recursion exsists in java but i'm not adding them in these notes | |
public class MethodExamples { | |
//the main method, the entry point of the program | |
//methor name: main | |
//return type: N/A | |
//parameters: String[] args | |
public static void main(String[] args) { | |
System.out.println("Hello World"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ArrayExamples { | |
public static void main(String[] args) { | |
// create an array of integers of length 10 | |
int[] arr = new int[10]; | |
// store the size of the array in a variable | |
int len = arr.length; | |
// use a for-each loop to | |
for (int i: arr) { | |
System.out.println(i); | |
// the output will be 10 lines of 0s since we haven't modified it |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Non-numerical math values in java: | |
n/0.0 = Infinity where n is a positive number | |
n/0.0 = -Infinity where n is a negative number | |
0/0.0 = NaN (can also do 0.0/0.0) | |
note the 0.0 is a decimal and not an integer | |
Operators: | |
+ adds the numbers | |
- subtracts the numbers | |
* multiplies the numbers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Data types (probably useless but since there is a coding portion, I'm including them anyways): | |
boolean - stores true or false | |
byte - stores whole numbers from -128 to 127 | |
char - stores a single character/ASCII values | |
int - stores whole numbers from -2,147,483,648 to 2,147,483,647 | |
long - stores whole numbers from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 | |
short - stores whole numbers from -32,768 to 32,767 | |
float - stores fractional numbers, sufficient for storing 6 to 7 decimal digits | |
double - stores fractional numbers, sufficient for storing 15 decimal digits |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Access Control: | |
private - can only be accessed in the class | |
protected - can only be accessed in the class or a subclass | |
public - can be accessed anywhere | |
Modifiers: | |
abstract - a non-access modifier, used for classes and methods | |
final - a non-access modifier used for classes, attributes and methods (not changeable) | |
finally - executes no matter if the try-except failed or passed | |
native - specifies that a method is not implemented in the same java source file |