Java Notes
Java Notes
G VARIABLES
QUICK LIST OF PRIMITIVE TYPES
IN CASE YOU FORGET AGAIN:
- byte [integer but has like no range;
-128 to 127]
- Int [integer, stores values of up to 2
million]
- Double [allows decimals, stores very
very large values]
- Boolean [true or false]
- Char [one character. Pretty useless if
you ask me, but whatever]
STRINGS:
Strings are objects, not primitive types.
You can use them in two ways: using a
string literal (just a sequence of
characters in double quotes) or
summoning the string class to create a
new string object.
String literal way: String greeting =
"Hello World";
OBJECT
ORIENTED
PROGRAMMIN
G
An object oriented programming
language allows programmers to
create their own template for
storing data; their own data type.
In OOP, a class is a blueprint of the
new data type that tells the
language what the data type looks
like/what it's made up of. It is the
set of instructions that describes
how the instances in it can
behave/what info they have.
An object is an example, or
instance, of a class. The class is a
blueprint, while the object is the
actual example of a piece of data
that is part of the class.
if (boolean expression) {
}
else
{
FOR LOOPS
-Used when you know how many times
the loop should run
for () {
}
WHILE LOOPS
Loop keeps running until the condition
is met.
int n = 0;
while(n<9) {
System.out.println(n);
n++;
}
ARRAYS
<Type>[]nameOfArray = new
<Type>[size]
Example:
String[] names = new String[5]
CLASSES
public class YerMom {
//methods, loops, and statements
public static void
main(Strings[] args){
//objects and other code go here
}
}
METHODS
A method is a collection of
statements that perform an
operation. Basically, it is a
function. Here is what a method
looks like:
DECLARING A VARIABLE
public class Car {
//constructor method (built in)
public static void
main(Strings[] args){
Car hondaCrv = new Car();
}
}
INSTANCE
VARIABLES/INSTANCE
FIELDS
Instance variables are the same
thing as instance fields. They are
variables inside of the class that
come before the main method. The
objects created within the class
will have these attributes, along
with the memory address.
LIBRARIES
in java libraries, they have free
stuff, which you can import. they
have classes and methods.
everything is prewritten.