Unit | Score |
---|---|
1 | 0.9/1 |
2 | 0.95/1 |
3 | 0.9 /1 |
4 | 0.8/1 |
5 | 0.9/1 |
Total Score | 4.45/5 |
int x = 3/2;
System.out.println(x);
// vs casting with double
double y = 3/(double)2;
System.out.println(y);
double x = 4.0 / 3;
int rounded = (int)(x + 0.5);
System.out.println("4.0/3 = " + x);
System.out.println("4/3 truncated: " + (int)x );
System.out.println("4.0/3 rounded to nearest int: " + rounded);
Integer a = 1;
Double b = 1.5;
System.out.println(a);
System.out.println(b)
Concatenation, explain or illustrate rules on mixed type Concatenation
Concatenation is defined as the joining of data and some examples include string concatenation as well as string and object concatenation with toString() method.
Math class, specifically Random usage
The math class contains static methods from the java.lang package
- Ex: math.random
Unit 3:
Compound Boolean Expression
A boolean expression is a logical statement that can either be evaluated to true or false. A compound boolean expression involves two boolean expression, with the second boolean expression only being evaluated if the first boolean expression evaluates to true.
Truth Tables
A truth table is a breakdown of a logic function by listing all possible values the function can attain. Such a table typically contains several rows and columns, with the top row representing the logical variables and combinations, in increasing complexity leading up to the final function.
De Morgan's Law
DeMorgan's laws tell us how to transform logical expressions (with multiple AND and/or OR statements) using the NOT operator.
Comparing Numbers
The compare() method of Integer class of java.lang package compares two integer values (x, y) given as a parameter and returns the value zero if (x==y), returns a value less than zero if (x < y) and returns a value greater than zero if (x > y).
Comparing Strings
Ff (string1 > string2) it returns a positive value, if (string1 == string2) it returns 0, and if (string1 < string2) it returns a negative value
Comparing Objects
== and != operators
Unit 4:
For loop, enhanced for loop
A for loop will keep running for each time a given condition is true. The enhanced for loop is also known as the for each loop and is used to iterate through elements of arrays and collections.
While loop versus do while loop
While a specific condition is true, the loop will run. A while loop will check the condition first before running whereas a do while loop will run and then check the condition afterwards.
Nested loops
Nested loops are loops within loops.
Unit 5:
Classes
- blueprints for instantiating objects
- model real world objects in code
Anatomy of a Class
- Object
- instance of a class
- Class
- defines an abstract type
- Methods
- behaviors you can get the object to do
- Constructors
- creates the object
- special method for object instantiation
- default constructor has no arguments
- Main method
- test the class
Accessor Methods
- Get of methods or getters
- allows you to get values of variables
- return a copy
- Non-void Methods
- value of specific data type returned
- no parameters
Mutator Methods
- Set of methods or setters
- allows you to change the value of the variable
- Void Methods
- no value returned
- will take parameters
Public, Private, Protected
- Public - can be accessed within and outside of class
- Private - can only be accessed within the class
- Protected - can be accessed by all classes in the package and all subclass outside of the package
Inheritance, extends
- Inheritance is a way for attributes and methods to be inherited from one class to another
- Extends is what allows you to bring those attributes from one class to another
Subclass constructor, super Keyword
- A subclass inherits all the members from the superclass while the constructor of the superclass can be invoked from the subclass
- Super keyword refers to superclass objects; it is used to call superclass methods and to access the superclass constructor
Overloading a method, same name different parameters
- Overloading a method in java is a feature that allows a class to have more than one method with the same name, but with different parameters
- Instead of defining two methods that do the same thing, it is better to overload one
Overriding a method, same signature of a method
- Method overriding occurs when a subclass has the same method as the parent class
- When a subclass provides a particular implementation of a method declared by one of its parent classes
Abstract Class, Abstract Method
- A abstract class cannot be instantiated but they can be subclassed
- An abstract method is a method that has just the method definition but does not contain implementation
Standard methods: toString(), equals(), hashCode()
- Standard methods are blocks of code that can be called from another location in the program or class
- toString(); returns the given value in string format
- equals(); compares two strings and returns true if the strings are equal
- hashCode(); returns an integer value generated by a hashing algorithm
Late binding of object, referencing superclass object, ie Animal a = new Chicken(); Animal b = new Goat();
- Late binding is when the compiler should perform no argument checks, no type checks on a method call and should leave it all to the runtime
Polymorphism: any of overloading, overriding, late binding
- Polymorphism is the ability of a class to provide different implementations of a method depending on the type of object that is passed to the method
- Allows us to perform the same action in many different ways
Big O notation for Hash map, Binary Search, Single loop, Nested Loop
- Big O notation describes the set of all algorithms that run no worse than a certain speed, no better than a certain speed, and at a certain speed
- Shows the number of operations it will perform