FUNDAMENTALS Classes
- Template for an object
- Core Java Chapter 4.2/4.3
Objects
- State/Instance/Signature
- Core Java Chapter 4.6
Packages
- A package is a namespace that organizes a set of related classes and
interfaces. Conceptually you can think of packages as being similar to
different folders on your computer
- Core Java Chapter 4.7
Operators
- manipulates variables
- https://www.tutorialspoint.com/java/java_basic_operators.htm
- Core Java Chapter 3.5
Variables
- http://www.learnjavaonline.org/en/Variables_and_Types
- Core Java Chapter 3.4
CONTROL FLOW (Core Java Chapter 3.8) If (Core Java Chapter 3.8.2)
If-Else
- EXAMPLE
if(something that is true/false){then do this}
else if(the thing above never happened, maybe this happens??) {then do this}
else {none of that happened so do this....}
While (Core Java Chapter 3.8.3)
-EXAMPLE
while(something is true/false){keep doing this}
** while loops only run if the conditional they are dependent on are a truthy
statement
Do While
-EXAMPLE
do{this thing}while(something is true/false)
** Do While loops always run at least once because they do not access
the truthiness of the condition until it has already done the loop once.
For (Core Java Chapter 3.8.4)
- EXAMPLE
start until do this to the counter
for(int i = 0; i < or > or = or <= or >= something; increment i in someway)
{do this thing until the loop conditions are met}
** for loops will iterate over a code block until the counter is outside
the parameters of the loop
ForEach
-EXAMPLE
for (Element e: c)
{System.out.print(e)}
** for each element "e" in "c" (array, arrayList, some other collection)
do this code block
ForEach With Iterables
-EXAMPLE
for (Iterator i = c.iterator(); i.hasNext();)
{System.out.print(i.next())}
** accesses elements of a collection one by one until there are no more to
be found. On each element in the collection a block of code is executed
Ternary Statements
- https://alvinalexander.com/java/edu/pj/pj010018
- Core Java pages 62/63
-EXAMPLE
condition ? expression1 : expression2
** if some condition is met, do expression1, if the condiditon is not met
do condition2
ARRAYS (Core Java Chapter 3.10 pages 108 to 124) allocate arrays
- https://www.geeksforgeeks.org/arrays-in-java/
copy arrays
- since arrays are objects in java they are "cloneable" and because of this
you can create copies of an array.
There are many ways to copy array in java. Let’s look at them one by one.
1.) Object.clone(): Object class provides clone() method and since array in
java is also an Object, you can use this method to achieve full array copy.
This method will not suit you if you want partial copy of the array.
2.) System.arraycopy(): System class arraycopy() is the best way to do partial
copy of an array. It provides you an easy way to specify the total number of
elements to copy and the source and destination array index positions.
For example System.arraycopy(source, 3, destination, 2, 5) will copy
5 elements from source to destination, beginning from 3rd index of source to
2nd index of destination.
3.) Arrays.copyOf(): If you want to copy first few elements of an array or
full copy of array, you can use this method. Obviously it’s not versatile
like System.arraycopy() but it’s also not confusing and easy to use.
This method internally use System arraycopy() method.
4.) Arrays.copyOfRange(): If you want few elements of an array to be copied,
where starting index is not 0, you can use this method to copy partial array.
Again this method is also using System arraycopy method itself.
COLLECTIONS arrayLists (Core Java Chapter 5.3 pages 244 to 247)
- https://www.geeksforgeeks.org/arraylist-in-java/
hashMaps (Core Java page 504)
-https://beginnersbook.com/2013/12/hashmap-in-java-with-example/
treeMaps (Core Java page 497)
-http://www.baeldung.com/java-treemap
** Whats the difference between a hashMap and a treeMap?!
hashMaps are great if you need to store things with an associated key value,
but don't care how they are sorted (if you know all the keys you can easily get
access to those values). TreeMaps are sorted lists, that means that all of
the key values are sorted in some logical way, are your key values numbers?
Guess what, that tree map has them in numerical order. Are your keys words?
BAM! The treeMap sorts those keys alphabetically. Magic.
INTERFACES VS ABSTRACT CLASSES Abstract Classes (Core Java page 221 to 227)
- https://www.geeksforgeeks.org/abstract-classes-in-java/
Interfaces (Core Java page 297)
- https://www.tutorialspoint.com/java/java_interfaces.htm
Abstract Classes VS Interfaces
-https://www.geeksforgeeks.org/difference-between-abstract-class-and-interface-in-java/
** Abstract classes and Interfaces seemingly do the same thing. So why have multiple
ways to do the same thing? It comes down to flexibility.
When to use what?
Consider using abstract classes if any of these statements apply to your situation:
In java application, there are some related classes that need to share some
lines of code then you can put these lines of code within abstract class and
this abstract class should be extended by all these related classes.
You can define non-static or non-final field(s) in abstract class, so that
via a method you can access and modify the state of Object to which they belong.
You can expect that the classes that extend an abstract class have many common
methods or fields, or require access modifiers other than public (such as protected
and private).
Consider using interfaces if any of these statements apply to your situation:
It is total abstraction, All methods declared within an interface must be implemented
by the class(es) that implements this interface.
A class can implement more than one interface. It is called multiple inheritance.
You want to specify the behavior of a particular data type, but not concerned
about who implements its behavior.
extend vs implements
- classes extend other classes/abstract classes
- classes implement interfaces
override methods -https://www.geeksforgeeks.org/overriding-in-java/ final -https://en.wikipedia.org/wiki/Final_(Java)
methods
- A final method cannot be overridden or hidden by subclasses
classes
- A final class cannot be subclassed
variables
- A final variable can only be initialized once
ENUMS
**In applications, you often need to work with a set of constant values. For example, representing a contract status with the “permanent”, “temp”, and “intern” values, or directions with the “north”, “south”, “east”, and “west” values.
In Java, you use the enum type (short for enumeration), a special datatype created to represent such lists of predefined constants.
GENERICS -https://www.geeksforgeeks.org/generics-in-java/
LAMBDA -Core Java Chapter 6.3 pages 314 to 328 -http://tutorials.jenkov.com/java/lambda-expressions.html -https://www.geeksforgeeks.org/lambda-expressions-java-8/ **Lambda expressions basically express instances of functional interfaces (An interface with single abstract method is called functional interface. An example is java.lang.Runnable). lambda expressions implement the only abstract function and therefore implement functional interfaces
lambda expressions are added in Java 8 and provide below functionalities.
Enable to treat functionality as a method argument, or code as data. A function that can be created without belonging to any class. A lambda expression can be passed around as if it was an object and executed on demand.
MYSQL -Dolio's Slides -https://www.digitalocean.com/community/tutorials/a-basic-mysql-tutorial -https://www.w3schools.com/sql/sql_quickref.asp
ERRORS AND EXCEPTIONS (Core Java Chapter 7) -https://www.tutorialspoint.com/java/java_exceptions.htm Exceptions checked VS unchecked (Core Java Chapter 7.1 pages 358 to 365) TRY/CATCH/FINALLY (Core Java 7.2 pages 367 to 377) Logging (Core Java Chapter 7.5 pages 389 to 399)
Logging Levels (Core Java Chapter 7.5.2 page 390)
PARSING -https://www.quora.com/What-does-parsing-mean-in-Java ** fairly common parse method in Java is the parseInt() method in the Integer class. This method takes a string as a parameter and looks at the string to find anything that can be represented as an integer inside that string.