paramOne.<<
2 |
3 | = #!exl::repl('index.prob.repl.yaml')
4 |
5 | ||The for-each loop must include a colon between the local variable as well as varOne. ||
--------------------------------------------------------------------------------
/07_Object Oriented Programming/01_Inheritance/00_Implementing Inheritance/01_.repl/src/InheritanceExample.java:
--------------------------------------------------------------------------------
1 | package exlcode;
2 |
3 | public class InheritanceExample {
4 |
5 | public static void main(String[] args) {
6 | EnglishGreeting englishGreeting = new EnglishGreeting();
7 | englishGreeting.print();
8 | }
9 | }
--------------------------------------------------------------------------------
/07_Object Oriented Programming/01_Inheritance/01_Super/00_.md:
--------------------------------------------------------------------------------
1 | When implementing inheritance, use the Java reserved word `super` to call a method in the superclass or to invoke the constructor of the superclass. Remember that `private` methods cannot be accessed by the subclass. Take a look below to see how `super` is used.
2 |
3 |
--------------------------------------------------------------------------------
/03_Strings/01_String Methods/02_IndexOf/00_.md:
--------------------------------------------------------------------------------
1 | Let's discuss what the concept of "index" means in Java. Index numbering starts with zero and totals up characters. The method `indexOf()` returns the index of the first occurrence of a `String` or `char` in a targeted `String`. Take a look below to see how this method is used.
2 |
3 |
--------------------------------------------------------------------------------
/07_Object Oriented Programming/00_Objects/01_Object Equality/00_.md:
--------------------------------------------------------------------------------
1 | When we looked at object equality in an earlier section with the `equals()` method for `String`, we discovered how it was different in functionality than the default equals method for other objects. Take a look at the two different equality functions below.
2 |
3 |
--------------------------------------------------------------------------------
/07_Object Oriented Programming/01_Inheritance/00_Implementing Inheritance/01_.repl/src/Greeting.java:
--------------------------------------------------------------------------------
1 | package exlcode;
2 |
3 | public class Greeting {
4 |
5 | public String exampleVariableOne = "Hello World!";
6 |
7 | public void printer() {
8 | System.out.println(exampleVariableOne + " superclass");
9 | }
10 | }
--------------------------------------------------------------------------------
/07_Object Oriented Programming/02_Abstract Classes and Interfaces/00_Implementing Abstract Classes/01_.repl/src/AbstractClassTest.java:
--------------------------------------------------------------------------------
1 | package exlcode;
2 |
3 | public abstract class AbstractClassTest {
4 |
5 | // abstract methods only have to be declared
6 | abstract void print();
7 |
8 | abstract void printGreeting();
9 | }
--------------------------------------------------------------------------------
/02_Variables and Operators/02_Operators/03_Expressions/01_.repl/src/ExpressionsExample.java:
--------------------------------------------------------------------------------
1 | package exlcode;
2 |
3 | public class ExpressionsExample {
4 |
5 | public static int exampleVariableOne = ((7-4) * (-3/-1));
6 |
7 | public static void main(String[] args) {
8 | System.out.println(exampleVariableOne);
9 | }
10 | }
--------------------------------------------------------------------------------
/04_Control Flow Statements/00_Basics/01_The else if Statements/00_.md:
--------------------------------------------------------------------------------
1 | The `else if` statement takes the `if` statement functionality one step further. Instead of having two outcomes, the programmer can create as many outcomes as they like, each one with its own expression. Take a look at the use of the `else if` statement below.
2 |
3 |
--------------------------------------------------------------------------------
/07_Object Oriented Programming/01_Inheritance/02_Overriding Methods/01_.repl/src/OverridingMethodsExample.java:
--------------------------------------------------------------------------------
1 | package exlcode;
2 |
3 | public class OverridingMethodsExample {
4 |
5 | public static void main(String[] args) {
6 | OverrideMethodTestOne objectOne = new OverrideMethodTestTwo();
7 | objectOne.print();
8 | }
9 | }
--------------------------------------------------------------------------------
/01_Java Syntax and Style/00_Basic Syntax/02_Declaring Classes/00_.md:
--------------------------------------------------------------------------------
1 | Everything that a program accomplishes is outlined between the first brace and the final brace of the class. The line `public static void main (String[] args)` show where the program starts running. Please take a look at the code below that shows a class with a main method.
2 |
3 |
--------------------------------------------------------------------------------
/01_Java Syntax and Style/00_Basic Syntax/05_Methods/00_.md:
--------------------------------------------------------------------------------
1 | Methods are another section of the class we will explore. In addition to the main method in the class, more methods that have other functions can exist in the project.
2 |
3 | Methods are constructed out of statements which are placed between brackets like these "{ }" as shown below:
4 |
5 |
--------------------------------------------------------------------------------
/02_Variables and Operators/00_Primitive Data Types/04_Float/00_.md:
--------------------------------------------------------------------------------
1 | Let's explore the next primitive data type, `float`, or single-precision floating point. Floating point literals have a decimal point, but no commas that function as thousand separators. Please take a look at the code below to see how `float` variables are declared and used.
2 |
3 |
--------------------------------------------------------------------------------
/07_Object Oriented Programming/01_Inheritance/02_Overriding Methods/00_.md:
--------------------------------------------------------------------------------
1 | Overriding is an important concept when dealing with inheritance. A subclass' method overrides a superclass' method when it has the same signature, meaning it has the same name and the same parameters. See an example of how you can override a superclass' method below.
2 |
3 |
--------------------------------------------------------------------------------
/02_Variables and Operators/00_Primitive Data Types/09_Scientific Notation/00_.md:
--------------------------------------------------------------------------------
1 | When working with large numbers, scientific notation is exceptionally helpful. In scientific notation, the letter 'e' represents "10 to the power of". For example, "1.51E+1" means the same thing as "1.51x10^1". Let's review some examples of scientific notation below.
2 |
3 |
--------------------------------------------------------------------------------
/07_Object Oriented Programming/00_Objects/01_Object Equality/01_.repl/src/ObjectEqualityTest.java:
--------------------------------------------------------------------------------
1 | package exlcode;
2 |
3 | public class ObjectEqualityTest {
4 |
5 | private String exampleVariableThree;
6 |
7 | public ObjectEqualityTest(String exampleVaraibleThree) {
8 | this.exampleVaraibleThree = exampleVaraibleThree;
9 | }
10 | }
--------------------------------------------------------------------------------
/02_Variables and Operators/02_Operators/06_Logical Complement/00_.md:
--------------------------------------------------------------------------------
1 | The logical complement operator, also known as the NOT operator in Java, is represented by an exclamation mark '!'. This operator changes true values to false and false to true. This operator only works with `boolean`. Please review the example of the NOT operator and its function.
2 |
3 |
--------------------------------------------------------------------------------
/02_Variables and Operators/02_Operators/08_Decrement/00_.md:
--------------------------------------------------------------------------------
1 | The decrement operator functions similarly to the increment operator. The only difference is that the decrement operator decreases a value by one. This means we can write `varOne--;` instead of writing `varOne = varOne - 1;`. Let's take a look at these decrementing variables in the code below.
2 |
3 |
--------------------------------------------------------------------------------
/04_Control Flow Statements/00_Basics/03_The switch Statement/00_.md:
--------------------------------------------------------------------------------
1 | The `switch` statement compares different primitive data types, `String` values and other objects to tests whether or not they are equal to a certain value. Play with the example of a switch statement below by changing the value of `exampleVariableOne` to see the different results.
2 |
3 |
--------------------------------------------------------------------------------
/07_Object Oriented Programming/00_Objects/03_Encapsulation/01_.repl/src/EncapsulationExample.java:
--------------------------------------------------------------------------------
1 | package exlcode;
2 |
3 | public class EncapsulationExample {
4 |
5 | public static void main(String[] args) {
6 | EncapsulationTest encapsulationTest = new EncapsulationTest();
7 | System.out.println(encapsulationTest.getVariableOne());
8 | }
9 | }
--------------------------------------------------------------------------------
/10_Exceptions/01_Examples of Exceptions/03_StringIndexOutOfBoundsException/00_.md:
--------------------------------------------------------------------------------
1 | The "StringIndexOutOfBoundsException" is similar to the "ArrayIndexOutOfBoundsException" we already covered. When the index of the targeted value is less than zero or greater than or equal to the length of the `String`, the exception occurs. Take a look at the example below.
2 |
3 |
--------------------------------------------------------------------------------
/01_Java Syntax and Style/00_Basic Syntax/01_Comments/00_.md:
--------------------------------------------------------------------------------
1 | A "comment" is a message written to a human reader of the program. A comment is denoted by `//` at the beginning of the line. Those two characters (//) and everything that follows on the one line are disregarded by the Java compiler. Please take a look at the example below showing the use of comments.
2 |
3 |
--------------------------------------------------------------------------------
/02_Variables and Operators/03_Math Class/04_Square Root/00_.md:
--------------------------------------------------------------------------------
1 | One of the more popular `Math` class functions is the square root function. Like the `floor()` and `ceil()` methods, the square root method takes and returns the `double` datatype. It can be written as follows, `Math.sqrt(25)`, and returns the rounded positive square root. Review the examples below.
2 |
3 |
--------------------------------------------------------------------------------
/03_Strings/00_Strings/03_Null Value/01_.repl/src/NullValueExample.java:
--------------------------------------------------------------------------------
1 | package exlcode;
2 |
3 | public class NullValueExample {
4 |
5 | // exampleVariableOne is only declared and not initialised
6 | public static String exampleVariableOne;
7 |
8 | public static void main(String[] args) {
9 | System.out.println(exampleVariableOne);
10 | }
11 | }
--------------------------------------------------------------------------------
/06_Arrays/02_ArrayLists/01_ArrayList Methods/00_.md:
--------------------------------------------------------------------------------
1 | The index of an `ArrayList` starts at 0 and it cannot equal the size of the `ArrayList`, just like we mentioned with strings and arrays. `ArrayList` is a class, which means it has its own methods like the `String` class does. Take a look at the commonly used methods in the `ArrayList` class and their functions.
2 |
3 |
--------------------------------------------------------------------------------
/01_Java Syntax and Style/00_Basic Syntax/00_Reserved words/00_.md:
--------------------------------------------------------------------------------
1 | In Java, there are keywords that are reserved for the use of Java functions or other uses that cannot be identifiers like variables, classes and function names. When a reserved word is used as a variable, we will get an error or some other unexpected result. Examples of reserved words are shown below.
2 |
3 |
--------------------------------------------------------------------------------
/01_Java Syntax and Style/00_Basic Syntax/09_Print Output/00_.md:
--------------------------------------------------------------------------------
1 | Let's examine the print method, which is essential when you want to print text on the console. This method sends anything inside the parenthesis to the output stream, which is why the characters appear on the console. Please study the examples below to see two different ways of printing on the console.
2 |
3 |
--------------------------------------------------------------------------------
/03_Strings/01_String Methods/01_Concatenation/00_.md:
--------------------------------------------------------------------------------
1 | The `concat()` method performs `String` concatenation, meaning it takes two strings and forms a new `String` by putting the original two strings together. For example, the program below concatenates the first `String` "Hello " with the second `String` "World!" and makes a new `String` that refers to "Hello World!".
2 |
3 |
--------------------------------------------------------------------------------
/03_Strings/01_String Methods/04_Substring/code_input.prob.repl/src/SubstringPractice_Solution.java:
--------------------------------------------------------------------------------
1 | package exlcode;
2 |
3 | public class SubstringPractice_Solution{
4 | public String removeStartEnd(String varOne) {
5 | // returns the substring between the 1st index (inclusive) and the last index.
6 | return varOne.substring(1, varOne.length() - 1);
7 | }
8 | }
--------------------------------------------------------------------------------
/04_Control Flow Statements/01_Logical Operators/03_De Morgans Law/00_.md:
--------------------------------------------------------------------------------
1 | De Morgan's Law is helpful to remember for the AP exam because it will be useful with questions regarding boolean expressions. De Morgan's Law show how the NOT operator (!) can be distributed when it exists outside a set of parenthesis. Look below for a few examples of how De Morgan's Law works.
2 |
3 |
--------------------------------------------------------------------------------
/10_Exceptions/01_Examples of Exceptions/04_NaN/00_.md:
--------------------------------------------------------------------------------
1 | In Java, "NaN" stands for "not a number" and signifies that a value is not defined. "NaN" is not an exception error, but a value that is assigned. For example, imaginary numbers like the square root of negative numbers or zero divided by zero will both print "NaN" as the result. Take a look at the example below.
2 |
3 |
--------------------------------------------------------------------------------
/07_Object Oriented Programming/00_Objects/05_Static/01_.repl/src/StaticFieldsTest.java:
--------------------------------------------------------------------------------
1 | package exlcode;
2 |
3 | public class StaticFieldsTest {
4 |
5 | public static String exampleVariableOne = "Java";
6 | private static String exampleVariableTwo= "Hello World!";
7 |
8 | public static void print() {
9 | System.out.println(exampleVariableTwo);
10 | }
11 | }
--------------------------------------------------------------------------------
/10_Exceptions/01_Examples of Exceptions/04_NaN/01_.repl/src/NaNExample.java:
--------------------------------------------------------------------------------
1 | package exlcode;
2 |
3 | public class NaNExample {
4 |
5 | public static double exampleVariableOne = -3;
6 |
7 | public static void main(String[] args) {
8 | // this will print NaN because square root of -3 is an imaginary number
9 | System.out.println(Math.sqrt(-3));
10 | }
11 | }
--------------------------------------------------------------------------------
/02_Variables and Operators/00_Primitive Data Types/01_Boolean/00_.md:
--------------------------------------------------------------------------------
1 | Boolean is a primitive data type that is used to represent a single true/false value. A boolean value can only hold one of two values, true or false. Other words such as "yes" or "no" will not compile and will result in a syntax error. The code below illustrates how boolean variables are declared and used.
2 |
3 |
--------------------------------------------------------------------------------
/02_Variables and Operators/00_Primitive Data Types/02_Char/00_.md:
--------------------------------------------------------------------------------
1 | The next datatype we will look at is character, which is represented with `char` in Java. A `char` can almost represent any character in any language. To see a full list of potential characters, look up the Unicode character table. View the code below for an example of how to declare and use the character datatype.
2 |
3 |
--------------------------------------------------------------------------------
/02_Variables and Operators/03_Math Class/05_Power/00_.md:
--------------------------------------------------------------------------------
1 | The `pow()` function of the `Math` class takes in two `double` values and returns the result of the first input raised to the power of the second input. The symbol '^' is not used to represent "to the power of" in Java. We can write this function like this: `Math.pow(inputOne, inputTwo)`. Check out the two examples below.
2 |
3 |
--------------------------------------------------------------------------------
/04_Control Flow Statements/01_Logical Operators/01_Conditional OR/00_.md:
--------------------------------------------------------------------------------
1 | Contrary to the "AND" operator, the "OR" operator is used in a boolean expression to check if at least one of expressions are true.The "OR" operator is also a logical operator because it combines two true/false values into a single true/false value. Let's take a look at the functionality of the "OR" operator.
2 |
3 |
--------------------------------------------------------------------------------
/07_Object Oriented Programming/00_Objects/02_Dot Notation/01_.repl/src/DotNotationTest.java:
--------------------------------------------------------------------------------
1 | package exlcode;
2 |
3 | public class DotNotationTest {
4 |
5 | public String exampleVariableOne = "Objects";
6 | public int exampleVariableTwo = 20;
7 | private int exampleVariableThree = 10;
8 |
9 | public void print() {
10 | System.out.println("Hello World!");
11 | }
12 | }
--------------------------------------------------------------------------------
/07_Object Oriented Programming/00_Objects/03_Encapsulation/01_.repl/src/EncapsulationTest.java:
--------------------------------------------------------------------------------
1 | package exlcode;
2 |
3 | public class EncapsulationTest {
4 |
5 | private String exampleVariableOne = "Hello World!";
6 |
7 | // private variables can be accessible through
8 | // public methods
9 | public String getVariableOne() {
10 | return exampleVariableOne;
11 | }
12 | }
--------------------------------------------------------------------------------
/02_Variables and Operators/02_Operators/00_Arithmetic Operators/00_.md:
--------------------------------------------------------------------------------
1 | An arithmetic operator is a mathematical equation, similar to what we have seen in algebra, that takes integers and calculates them in a certain way. Java contains a set of basic common arithmetic operators that can be used to perform a number of different calculations. Take a look at the five operators we will examine.
2 |
3 |
--------------------------------------------------------------------------------
/02_Variables and Operators/03_Math Class/00_Basic Methods/00_.md:
--------------------------------------------------------------------------------
1 | The Java `Math` class contains all the familiar mathematical functions found on an electronic calculators, such as sine, log, and square root and more. For the most part, the functions use datatype `double` as a parameter and returns a `double` value. Let's take a look at a few of the methods and fields in the `Math` class.
2 |
3 |
--------------------------------------------------------------------------------
/03_Strings/00_Strings/00_Data Type/01_.repl/src/DataTypeStringExample.java:
--------------------------------------------------------------------------------
1 | package exlcode;
2 |
3 | public class DataTypeStringExample {
4 |
5 | // this creates a new String that holds "Hello World!"
6 | public static String exampleVariableOne = new String("Hello World!");
7 |
8 | public static void main(String[] args) {
9 | System.out.println(exampleVariableOne);
10 | }
11 | }
--------------------------------------------------------------------------------
/07_Object Oriented Programming/01_Inheritance/01_Super/01_.repl/src/SuperTestOne.java:
--------------------------------------------------------------------------------
1 | package exlcode;
2 |
3 | public class SuperTestOne {
4 |
5 | public int exampleVariableOne = 10;
6 |
7 | public SuperTestOne(int parameterOne) {
8 | this.exampleVariableOne = parameterOne;
9 | }
10 |
11 | public void print(){
12 | System.out.println(exampleVariableOne);
13 | }
14 | }
--------------------------------------------------------------------------------
/08_Recursion/01_Base Case/00_Identifying the Base Case/00_.md:
--------------------------------------------------------------------------------
1 | Let's examine the function of a "base case". It returns a value and does not make any more recurring calls. The values for which the base case stops recurring calls are particular specific inputs. For base cases that are factorial-based, the base case happens when the parameter becomes equal to one. Take a look at the code below.
2 |
3 |
--------------------------------------------------------------------------------
/08_Recursion/02_Final Exam/00_Question 1/code_input.prob.repl/src/BaseCasePractice_Solution.java:
--------------------------------------------------------------------------------
1 | package exlcode;
2 |
3 | public class BaseCasePractice_Solution{
4 | public int multipleOfTwo(int paramOne) {
5 | // base case
6 | if (paramOne == 0){
7 | return 0;
8 | }
9 | // adds 2 until paramOne is zero
10 | return 2 + multipleOfTwo(paramOne - 1);
11 | }
12 | }
--------------------------------------------------------------------------------
/00_Introduction to Java/00_Introduction/02_Hello World program/00_.md:
--------------------------------------------------------------------------------
1 | If you have studied Java prior to today, you may have encountered the "Hello World!" program, which shows a basic illustration of the program printing words on the console. Let's take a look at this program below and run it to see what happens. Feel free to alter the text enclosed by the quotation marks to change the output.
2 |
3 |
--------------------------------------------------------------------------------
/02_Variables and Operators/00_Primitive Data Types/06_Byte/00_.md:
--------------------------------------------------------------------------------
1 | One of the least used primitive data types is `byte` because `byte` has a limited range of numbers (-128 to 127) compared to `int`. Unless the programmer are a 100% sure that the values will not exceed this limited range, it is best to use `int`. Nevertheless, let's take a look at how `byte` variables are declared and used below.
2 |
3 |
--------------------------------------------------------------------------------
/02_Variables and Operators/03_Math Class/01_Absolute Value/00_.md:
--------------------------------------------------------------------------------
1 | The absolute value method in the `Math` class returns the absolute value of an `int` or `double`. Java offers more than two absolute value methods with different parameters depending on the output necessary. The absolute value methods are written in this manner: `Math.abs(parameter)`. Take a look at the absolute value method below.
2 |
3 |
--------------------------------------------------------------------------------
/02_Variables and Operators/00_Primitive Data Types/02_Char/02_.md:
--------------------------------------------------------------------------------
1 | `char` holds a single character with an apostrophe on each side. Notice that double quotation marks will not work for characters. Keep in mind that upper and lower case characters are represented by a different pattern. Additionally, special characters such as punctuation and spaces can be represented by the `char` data type as well.
2 |
3 |
--------------------------------------------------------------------------------
/03_Strings/01_String Methods/03_CharAt/02_.md:
--------------------------------------------------------------------------------
1 | The index for the first character of a `String` has an index of zero, meaning 'H' is printed when the statement `exampleVariableOne.charAt(0);` is called. If you point at an index where there is a space, the `charAt()` method will return a character containing ' '. This method, along with `indexOf()` method are extremely useful when working with strings.
2 |
3 |
--------------------------------------------------------------------------------
/04_Control Flow Statements/01_Logical Operators/02_Short Circuit Evaluation/code_input.prob.repl/src/ShortCircuitPractice_Solution.java:
--------------------------------------------------------------------------------
1 | package exlcode;
2 |
3 | public class ShortCircuitPractice_Solution{
4 | public boolean isTeenager(int ageOne, int ageTwo, int ageThree) {
5 | return (ageOne >= 13 && ageOne <= 19) || (ageTwo >= 13 && ageTwo <= 19) || (ageThree >= 13 && ageThree <= 19);
6 | }
7 | }
--------------------------------------------------------------------------------
/06_Arrays/00_One Dimensional Arrays/01_1D Array Length/00_.md:
--------------------------------------------------------------------------------
1 | As we stated previously, the way index works with arrays is similar to how index works with `String` values. Arrays also have a way of returning their own length, but in place of a method like with strings, the array's length is a variable, meaning the parenthesis are not needed. Look below to see how we can access the length of an array.
2 |
3 |
--------------------------------------------------------------------------------
/09_Search and Sort/00_Searching/00_Sequential Search/00_.md:
--------------------------------------------------------------------------------
1 | Let's dive into search functionality. Sequential search is a basic form of searching that checks if an element is present in a given list. This method will return a value telling us whether or not the searched value is in the given list. Take a look at the code below, where we have a method that searches through the array for integer '4'.
2 |
3 |
--------------------------------------------------------------------------------
/01_Java Syntax and Style/00_Basic Syntax/00_Reserved words/01_.repl/src/ReservedWordsExample.java:
--------------------------------------------------------------------------------
1 | package exlcode;
2 |
3 | public class ReservedWordsExample {
4 | public static void main(String[] args) {
5 | String exampleVariable = "George";
6 | // This prints Hello World! and exampleVariable
7 | System.out.println("Hello World!");
8 | System.out.println(exampleVariable);
9 | }
10 | }
--------------------------------------------------------------------------------
/02_Variables and Operators/02_Operators/05_Constants/00_.md:
--------------------------------------------------------------------------------
1 | Constants are variables that do not change. Constants include the Java reserved word `final`, stating that the value will not change in the program. Let's remember that constant variables follow a different naming convention than other variables, using capitals and separating words with an underscore. See the following example of two constants.
2 |
3 |
--------------------------------------------------------------------------------
/03_Strings/00_Strings/01_Creating Strings/00_.md:
--------------------------------------------------------------------------------
1 | There are two distinct ways to create a `String`: use double-quotation marks or create a new object. Either put text on the same line in double quotation marks as if it was primitive datatype: `String stringName = "hi";` or initialize them like this: `String stringName = new String("hi");`. Take a look below for examples on how we can initialize a `String`.
2 |
3 |
--------------------------------------------------------------------------------
/03_Strings/01_String Methods/08_Upper and Lower Case/02_.md:
--------------------------------------------------------------------------------
1 | These two methods may be useful when you want to change the `String` so that it will print in a particular way. On the other hand, you can use the method for personal preference or when you want to compare two strings while ignoring the differences in uppercase or lowercase. (Although `compareToIgnoreCase()` and `equalsIgnoreCase()` does exist)
2 |
3 |
--------------------------------------------------------------------------------
/06_Arrays/00_One Dimensional Arrays/03_Enhanced for Statement/00_.md:
--------------------------------------------------------------------------------
1 | Let's examine another type of loop. The "enhanced for" statement, or the "for-each" loop, looks at each element of an array in order, which allows the loop to automatically avoids errors such as going past the last index of an array. Let's revisit the same goal as in the example on previous page, but try it now with the for-each loop.
2 |
3 |
--------------------------------------------------------------------------------
/06_Arrays/00_One Dimensional Arrays/03_Enhanced for Statement/code_input.prob.repl/src/ForEachLoopPractice_Solution.java:
--------------------------------------------------------------------------------
1 | package exlcode;
2 |
3 | class ForEachLoopPractice_Solution{
4 | public int returnArray(int[] paramOne){
5 | int sum = 0;
6 | // loops through all the elements in varOne
7 | for (int index: paramOne){
8 | sum += index;
9 | }
10 | return sum;
11 | }
12 | }
--------------------------------------------------------------------------------
/07_Object Oriented Programming/02_Abstract Classes and Interfaces/01_Implementing Interfaces/01_.repl/src/InterfacesExample.java:
--------------------------------------------------------------------------------
1 | package exlcode;
2 |
3 | public class InterfacesExample {
4 |
5 | public static void main(String[] args) {
6 | InterfaceTestThree interfaceTestThree = new InterfaceTestThree();
7 | interfaceTestThree.print();
8 | interfaceTestThree.printGreeting();
9 | }
10 | }
--------------------------------------------------------------------------------
/02_Variables and Operators/00_Primitive Data Types/08_Long/00_.md:
--------------------------------------------------------------------------------
1 | The next integer-related primitive datatype we will delve into is `long`, which is used more commonly than `byte` and `short` because the range for `long` is even greater than that of `int`. The `long` primitive data type can hold integers such as eight trillion. Please review the code below for an example of declaring and using `long` variables.
2 |
3 |
--------------------------------------------------------------------------------
/03_Strings/02_Conversions/01_ToString/02_.md:
--------------------------------------------------------------------------------
1 | This method is useful when you want to print certain expressions. Although primitive data types that we have covered up to this point would print without needing to be converted into a `String`, there will be other objects we will master, such as arrays, that cannot be print directly, so keep the `toString` method in mind as we move forward and learn about arrays.
2 |
3 |
--------------------------------------------------------------------------------
/04_Control Flow Statements/00_Basics/02_Boolean Expressions/02_.md:
--------------------------------------------------------------------------------
1 | Boolean expressions are used to compare numbers, `boolean` values, `String` values, other objects and data types that you will learn about later in the course. Remember the importance of using double equals signs when you're comparing numbers. Please review the sections on "operators" when you need a refresher on the functionality of each one.
2 |
3 |
--------------------------------------------------------------------------------
/07_Object Oriented Programming/00_Objects/05_Static/01_.repl/src/StaticFieldsExample.java:
--------------------------------------------------------------------------------
1 | package exlcode;
2 |
3 | public class StaticFieldsExample {
4 |
5 | public static void main(String[] args) {
6 | // static variables and methods can be accessed
7 | // without creating an object
8 | System.out.println(StaticFieldsTest.exampleVariableOne);
9 | StaticFieldsTest.print();
10 | }
11 | }
--------------------------------------------------------------------------------
/02_Variables and Operators/02_Operators/03_Expressions/00_.md:
--------------------------------------------------------------------------------
1 | An expression is a mixture of literals, operators, variable names, and parentheses used to calculate a value. Please keep in mind that in Java, the expression on the right side of the assignment statement is evaluated first. The expressions will look similar to regular mathematical expressions from math class. Please take a look at the expressions below.
2 |
3 |
--------------------------------------------------------------------------------
/03_Strings/01_String Methods/08_Upper and Lower Case/00_.md:
--------------------------------------------------------------------------------
1 | The following two methods are similar to the `trim()` method and are built-in procedures used for making style changes to a `String`. Let's take a look at the results of calling one method that makes the `String` all lower case, and another that makes it all uppercase. The syntax for these two methods are as follows : `toLowerCase()` and `toUpperCase()`.
2 |
3 |
--------------------------------------------------------------------------------
/07_Object Oriented Programming/01_Inheritance/00_Implementing Inheritance/01_.repl/src/EnglishGreeting.java:
--------------------------------------------------------------------------------
1 | package exlcode;
2 |
3 | public class EnglishGreeting extends Greeting {
4 |
5 | public void print() {
6 | // the InheritanceTestTwo class inherits variables
7 | // and methods from InheritanceTestOne
8 | System.out.println(exampleVariableOne + " subclass");
9 | printer();
10 | }
11 | }
--------------------------------------------------------------------------------
/10_Exceptions/01_Examples of Exceptions/01_NullPointerException/00_.md:
--------------------------------------------------------------------------------
1 | Let's move on to another common error many programmers have experienced first-hand, the "NullPointerException". Remember that a null value can be assigned to any object reference including strings. The NullPointerException is thrown when the program tries to use an object reference that has the null value. Take a look below to see an example.
2 |
3 |
--------------------------------------------------------------------------------
/03_Strings/01_String Methods/00_String Length/00_.md:
--------------------------------------------------------------------------------
1 | Let's dive into introducing the methods that exist in the `String` class. A fundamental method to start off with is one that finds the length of a `String`, which is also the number of characters, including punctuation and spaces, that make up the string. The syntax for finding the length of a `String` is `stringname.length()`. Look below to see an example of its use.
2 |
3 |
--------------------------------------------------------------------------------
/05_Iterations/01_Branching Statements/00_Break/00_.md:
--------------------------------------------------------------------------------
1 | In Java, there are branching statements, for example the `break` statement, which breaks the loop in the program and continues running the statements after the loop. If you have a `for` or `while` loop and you want it to stop after a certain condition is true, you can have a `break` statement inside the `if` statement. How is it implemented in code? Take a look below.
2 |
3 |
--------------------------------------------------------------------------------
/06_Arrays/00_One Dimensional Arrays/02_Iterating Through 1D Array/00_.md:
--------------------------------------------------------------------------------
1 | Now that we know what an array is and what it contains, let's see how we can apply loops to help us accomplish tasks with arrays. For example, you want to know the sum of all the elements in an array. Instead of summing each element together in your head, you can write a `for` loop to do the work for you. Check out the code below for an example.
2 |
3 |
--------------------------------------------------------------------------------
/01_Java Syntax and Style/00_Basic Syntax/07_Naming Conventions/00_.md:
--------------------------------------------------------------------------------
1 | When you begin writing your own Java programs, there are some naming conventions that are strongly suggested. These naming conventions make it easier to understand what the program does, gives information about the identifiers and helps you understand the code. Please take a look at the code below for some examples of naming conventions for identifiers.
2 |
3 |
--------------------------------------------------------------------------------
/01_Java Syntax and Style/00_Basic Syntax/08_Access Control/00_.md:
--------------------------------------------------------------------------------
1 | In Java, access control tells the program how much access a variable, class or method is given. Access control is important because it affects visibility based on different access control types. You may have noticed in prior topics the use of words such as `public` and `private`, which are examples of access control types. Take a look at the examples below.
2 |
3 |
--------------------------------------------------------------------------------
/02_Variables and Operators/02_Operators/07_Increment/01_.repl/src/IncrementExample.java:
--------------------------------------------------------------------------------
1 | package exlcode;
2 |
3 | public class IncrementExample {
4 |
5 | public static int exampleVariableOne = 10;
6 |
7 | public static void main(String[] args) {
8 | // Both statements adds 1 to exampleVariableOne
9 | exampleVariableOne++;
10 | ++exampleVariableOne;
11 | System.out.println(exampleVariableOne);
12 | }
13 | }
--------------------------------------------------------------------------------
/05_Iterations/00_Loops/02_Loop Variable/00_.md:
--------------------------------------------------------------------------------
1 | Now that we are working with loops, let's explore "loop control variables". Loop control variables are ordinary `int` variables that are used to dictate elements such as how many times a loop will execute. Not all loops will necessarily have loop control variables, but it is important to recognize if one is present. Look at the program below to see what a "loop control variable" is.
2 |
3 |
--------------------------------------------------------------------------------
/06_Arrays/00_One Dimensional Arrays/01_1D Array Length/02_.md:
--------------------------------------------------------------------------------
1 | The length of an array equals the number of elements it can hold. The last index of an array is `array.length-1`. Remember that the `length()` method in the `String` class works differently than `array.length()`.
2 |
3 | The length of an array cannot be altered after it is initialized. Please remember this quality when you loop through arrays with for/while statements.
4 |
5 |
--------------------------------------------------------------------------------
/06_Arrays/03_Final Exam/03_Question 4/code_input.prob.repl/src/OneDArrayLengthPracticeOne_Solution.java:
--------------------------------------------------------------------------------
1 | package exlcode;
2 |
3 | public class OneDArrayLengthPracticeOne_Solution{
4 | public boolean firstOrLastSix(int[] paramOne) {
5 | int varOne = paramOne.length - 1; // varOne now holds the last index of the array
6 | return paramOne[0] == 6 || paramOne[varOne] == 6; // returns true if either one of these are true
7 | }
8 | }
--------------------------------------------------------------------------------
/02_Variables and Operators/02_Operators/02_Assignment Operators/00_.md:
--------------------------------------------------------------------------------
1 | An assignment operator functions to change the value that is stored inside a variable. In order for the operator to change a value, the variable must be declared beforehand. Also remember that we can declare a variable and assign it a value at the same time. Look at the code below for an example of the three assignment operators we will discuss: '=', "+=", and "-=".
2 |
3 |
--------------------------------------------------------------------------------
/02_Variables and Operators/02_Operators/08_Decrement/01_.repl/src/DecrementExample.java:
--------------------------------------------------------------------------------
1 | package exlcode;
2 |
3 | public class DecrementExample {
4 |
5 | public static int exampleVariableOne = 10;
6 |
7 | public static void main(String[] args) {
8 | // Both statements subtract 1 from exampleVariableOne
9 | exampleVariableOne--;
10 | --exampleVariableOne;
11 | System.out.println(exampleVariableOne);
12 | }
13 | }
--------------------------------------------------------------------------------
/04_Control Flow Statements/00_Basics/02_Boolean Expressions/00_.md:
--------------------------------------------------------------------------------
1 | A "boolean expression" refers to the statement contained inside the brackets of the `if` statement or the `else if` statements and only evaluates to either "true" or "false". Remember that an "expression" always consists of literals, operators, variable names, and parentheses used to calculate a value such as true or false. Explore the two boolean expressions below.
2 |
3 |
--------------------------------------------------------------------------------
/06_Arrays/00_One Dimensional Arrays/00_Creating One Dimensional Arrays/00_.md:
--------------------------------------------------------------------------------
1 | In the real world, programmers examine, use, test, and manipulate gigantic amounts of data. Arrays are used to systematically organize and process this data efficiently and effectively. When data is standardized and formulated into arrays, a simple and small Java program can handle an enormous amount of data. Take a look at the three different arrays below.
2 |
3 |
--------------------------------------------------------------------------------
/02_Variables and Operators/00_Primitive Data Types/06_Byte/02_.md:
--------------------------------------------------------------------------------
1 | The byte datatype takes up about four times less space than an `int`, but is not used for calculations and other methods. The byte datatype is useful when dealing with raw binary data for compatibility reasons. Similarly to `float`, `int` and the other integer related data types, the default value for `byte` is 0. The byte datatype can only hold whole, non-decimal numbers.
2 |
3 |
--------------------------------------------------------------------------------
/07_Object Oriented Programming/00_Objects/00_Creating Objects/01_.repl/src/ObjectTest.java:
--------------------------------------------------------------------------------
1 | package exlcode;
2 |
3 | public class ObjectTest {
4 |
5 | private String exampleVariableOne;
6 |
7 | // constructor of the class
8 | public ObjectTest(String exampleVariableOne) {
9 | this.exampleVariableOne = exampleVariableOne;
10 | }
11 |
12 | public void print(){
13 | System.out.println(exampleVariableOne);
14 | }
15 | }
--------------------------------------------------------------------------------
/07_Object Oriented Programming/01_Inheritance/00_Implementing Inheritance/00_.md:
--------------------------------------------------------------------------------
1 | Object oriented languages like Java have a feature called "inheritance" which allow programmers to define new classes based on an existing class. Instead of starting from nothing, we can build upon a previously existing class, or a "superclass", and add more variables and methods to the superclass. The program below shows a simple implementation of inheritance.
2 |
3 |
--------------------------------------------------------------------------------
/10_Exceptions/01_Examples of Exceptions/00_ArrayIndexOutOfBoundsException/02_.md:
--------------------------------------------------------------------------------
1 | The program above tries to access the element in the eleventh index of an array that only has a length of ten and a max index of nine. As expected, the exception is thrown and the program stops executing due to the error. Let's change the number in the program to a number that should not trigger the error to check if our exception statement works as intended.
2 |
3 |
--------------------------------------------------------------------------------
/02_Variables and Operators/03_Math Class/05_Power/01_.repl/src/PowerMethodExample.java:
--------------------------------------------------------------------------------
1 | package exlcode;
2 |
3 | public class PowerMethodExample {
4 |
5 | public static double exampleVariableOne = Math.pow(10, 2);
6 | public static double exampleVariableTwo = Math.pow(-10, 2);
7 |
8 | public static void main(String[] args) {
9 | System.out.println(exampleVariableOne);
10 | System.out.println(exampleVariableTwo);
11 | }
12 | }
--------------------------------------------------------------------------------
/05_Iterations/01_Branching Statements/01_Return/00_.md:
--------------------------------------------------------------------------------
1 | Another important branching statement in Java is the `return` statement, which we have already seen before when we covered methods. At any time in a method, the `return` statement is used to cause the whole method to return a certain value and ignore all the statements underneath it. The program belows shows an example of the `count()` method and a `return` statement inside a `while` loop.
2 |
3 |
--------------------------------------------------------------------------------
/05_Iterations/01_Branching Statements/02_Infinite Loops/00_.md:
--------------------------------------------------------------------------------
1 | As discussed previously, it is essential to make sure each loop you write has a distinct end. For example, if the condition inside the `for` or `while` loop is always true, the loop will run forever, creating an infinite loop. It is possible to accidentally create a loop that never ends. Look below to see how the `if` statement prevents the infinite loop from executing over 10 times.
2 |
3 |
--------------------------------------------------------------------------------
/02_Variables and Operators/04_Final Exam/00_Question 1/code_input.prob.repl/src/RelationalOperatorPracticeTwo_Solution.java:
--------------------------------------------------------------------------------
1 | package exlcode;
2 |
3 | public class RelationalOperatorPracticeTwo_Solution{
4 | public boolean multipleOfThree(int paramOne) {
5 | // modulus operator returns remainder between paramOne and 3
6 | // if the remainder is 0, paramOne is a multiple 3 and the method returns true
7 | return (paramOne % 3 == 0);
8 | }
9 | }
--------------------------------------------------------------------------------
/03_Strings/02_Conversions/01_ToString/code_input.prob.repl/src/ToStringPractice_Solution.java:
--------------------------------------------------------------------------------
1 | package exlcode;
2 |
3 | public class ToStringPractice_Solution{
4 | public boolean detectOne(int paramOne) {
5 | // converts paramOne to a String and assigns it to varOne
6 | String varOne = Integer.toString(paramOne);
7 | // returns whether or not the character '1' exists in the String
8 | return varOne.indexOf('1') != -1;
9 | }
10 | }
--------------------------------------------------------------------------------
/07_Object Oriented Programming/00_Objects/04_Type Casts/01_.repl/src/TypeCastExample.java:
--------------------------------------------------------------------------------
1 | package exlcode;
2 |
3 | public class TypeCastExample {
4 |
5 | public static void main(String[] args) {
6 | Object exampleVariableOne = new TypeCastTest();
7 | // exampleVariableOne has to be casted to a TypeCastTest object
8 | // before accessing language
9 | System.out.println(((TypeCastTest)exampleVariableOne).language);
10 | }
11 | }
--------------------------------------------------------------------------------
/01_Java Syntax and Style/00_Basic Syntax/09_Print Output/01_.repl/src/PrintOutputExample.java:
--------------------------------------------------------------------------------
1 | package exlcode;
2 |
3 | public class PrintOutputExample {
4 |
5 | public static void main(String[] args) {
6 | // this prints Hello!, Hello World! on the same line
7 | // and Hello Friends! on a different line
8 | System.out.print("Hello!");
9 | System.out.println("Hello World!");
10 | System.out.println("Hello Friends!");
11 | }
12 | }
--------------------------------------------------------------------------------
/02_Variables and Operators/03_Math Class/01_Absolute Value/01_.repl/src/AbsoluteValueMethodExample.java:
--------------------------------------------------------------------------------
1 | package exlcode;
2 |
3 | public class AbsoluteValueMethodExample {
4 |
5 | public static int exampleVariableOne = Math.abs(10);
6 | public static int exampleVariableTwo = Math.abs(-10);
7 |
8 | public static void main(String[] args) {
9 | System.out.println(exampleVariableOne);
10 | System.out.println(exampleVariableTwo);
11 | }
12 | }
--------------------------------------------------------------------------------
/02_Variables and Operators/03_Math Class/06_Random/02_.md:
--------------------------------------------------------------------------------
1 | In order to increase our range from 0.0 to 100.0, we have to multiply the whole expression by 101 since the function's range is only 0.0 to 1.0. We then use casting to change the `double` to an `int` datatype value, which in turn truncates the decimal and gives us a whole number. There are different methods within the `Random` class which may be useful to you for various projects in the future.
2 |
3 |
--------------------------------------------------------------------------------
/08_Recursion/00_Methods/00_Creating Recursive Methods/code_input.prob.repl/src/RecursionPractice_Solution.java:
--------------------------------------------------------------------------------
1 | package exlcode;
2 |
3 | public class RecursionPractice_Solution{
4 | public int powerOfNum(int paramOne, int paramTwo) {
5 | // base case
6 | if (paramTwo == 0){
7 | return 1;
8 | }
9 | // multiplies paramOne until paramTwo is equal to zero
10 | return paramOne * powerOfNum(paramOne, paramTwo - 1);
11 | }
12 | }
--------------------------------------------------------------------------------
/01_Java Syntax and Style/01_Errors/00_Runtime Errors/01_.repl/src/RunTimeErrorExample.java:
--------------------------------------------------------------------------------
1 | package exlcode;
2 |
3 | public class RunTimeErrorExample {
4 |
5 | public static int exampleVariableOne = 5;
6 | public static int exampleVariableTwo = exampleVariableOne/0;
7 |
8 | public static void main(String[] args) {
9 | // this creates an error because numbers cannot be divided by zero
10 | System.out.println(exampleVariableTwo);
11 | }
12 | }
--------------------------------------------------------------------------------
/04_Control Flow Statements/01_Logical Operators/00_Conditional AND/00_.md:
--------------------------------------------------------------------------------
1 | Let's explore the conditional "AND" operator, which allows you to check whether or not two values are both true or both false before executing a statement. If you have experience with a truth table, you will see similarities here. The "AND" operator is a logical operator that turns two true/false values into a single true or false value. Look below to see how this operator functions.
2 |
3 |
--------------------------------------------------------------------------------
/02_Variables and Operators/03_Math Class/06_Random/00_.md:
--------------------------------------------------------------------------------
1 | The `random()` method in the `Math` class returns a random number between 0.0 and 1.0, including 0.0 and not including 1.0, at random with uniform distribution from this range. This method is written like `Math.random()` and does not take in any parameters. The returns a `double` value. Run the program below to see the function. As you may suspect, you will get different numbers every time you run the program.
2 |
3 |
--------------------------------------------------------------------------------
/03_Strings/01_String Methods/06_CompareTo/02_.md:
--------------------------------------------------------------------------------
1 | The `compareTo()` method returns 0 if the two strings are equal, a number less than 0 if the first `String` is larger, and a number greater than 0 if the second `String` is larger. Uppercase letters come before lowercase letters when the method compares strings. As you work through learning this method's function, test our example program and use the ascii table to see how far apart the characters are from each other.
2 |
3 |
--------------------------------------------------------------------------------
/03_Strings/01_String Methods/06_CompareTo/00_.md:
--------------------------------------------------------------------------------
1 | The `compareTo()` method compares the first letter of one `String` object to the first letter of another `String` object and returns a number that states which `String` comes first in lexicographic order (A,B,C etc.). If the first two letters of the strings are the same, the method will go on to compare the next letters, and the next until it finds the first instance of a difference. Let's take a look at how this method works.
2 |
3 |
--------------------------------------------------------------------------------
/05_Iterations/00_Loops/00_The for Statement/00_.md:
--------------------------------------------------------------------------------
1 | Let's dive into the function of loops as time-savers that will immediately take your coding to the next level. The `for` statement is a loop control statement that allows you to run one or many statements several times in succession. For example, let's say we wanted to print out numbers 1-50. Instead of writing fifty `System.out.println();` statements, we use a loop. Start exploring loops by looking through the code below.
2 |
3 |
--------------------------------------------------------------------------------
/02_Variables and Operators/02_Operators/01_Relational Operators/code_input.prob.repl/src/RelationalOperatorPracticeOne_Solution.java:
--------------------------------------------------------------------------------
1 | package exlcode;
2 |
3 | public class RelationalOperatorPracticeOne_Solution{
4 | public boolean exampleMethod(boolean paramOne, boolean paramTwo) {
5 | // returns true when paramOne and paramTwo and equal to each other
6 | // returns false if paramOne and paramTwo hold different boolean values
7 | return (paramOne == paramTwo);
8 | }
9 | }
--------------------------------------------------------------------------------
/03_Strings/00_Strings/00_Data Type/00_.md:
--------------------------------------------------------------------------------
1 | We covered primitive data types and the operators that work with those data types. As we begin to discuss `String`, it may seem like a primitive data type. However, `String` is its own class in the `java.lang` package. The `String` class contains objects which are commonly used in Java programming. You will see how useful `String` is as we explore further. Take a look at the example below of a `String` that holds the value "Hello World!"
2 |
3 |
--------------------------------------------------------------------------------
/09_Search and Sort/01_Sorting/01_Insertion Sort/02_.md:
--------------------------------------------------------------------------------
1 | Check out the `java.util.Array` class when you are ready to start using the pre-written searches and sort methods to save yourself time. Just make sure you always know the correct parameters and syntax. Although you are not writing your own sort methods in the future, you will need to know how one works and be able to decipher the code. In fact, you should be familiar with all four search and sort methods covered in the course.
2 |
3 |
--------------------------------------------------------------------------------
/10_Exceptions/00_Handling Exceptions/00_Catching Exceptions/00_.md:
--------------------------------------------------------------------------------
1 | From the start of our course we have pointed out scenarios in coding that may cause runtime errors, which are almost always caused by "exceptions". An exception is something that happens while the program is executing. Whatever this exception may be, it interrupts or breaks the normal flow of the program's executable directions. Let's dive deeper into what exception errors are and how we can detect and resolve them!
2 |
3 |
--------------------------------------------------------------------------------
/01_Java Syntax and Style/00_Basic Syntax/06_Indentation/00_.md:
--------------------------------------------------------------------------------
1 | A new Java programmer must master the concept of "indentation" in Java. Indentation is used to make our code readable to other users, easier to edit, display how the braces match up and show the logic of the program in an organized fashion. Please look at the example below to see how indentation of the if-else statement makes it easy to see what is happening. Keep in mind, we will cover if-else statements later in the course.
2 |
3 |
--------------------------------------------------------------------------------
/02_Variables and Operators/00_Primitive Data Types/10_Casting/01_.repl/src/CastingExample.java:
--------------------------------------------------------------------------------
1 | package exlcode;
2 |
3 | public class CastingExample {
4 |
5 | // this converts 15.23 into an integer
6 | public static int exampleVariableOne = (int) 15.23;
7 | public static double exampleVariableTwo = exampleVariableOne;
8 |
9 | public static void main(String[] args) {
10 | System.out.println(exampleVariableOne);
11 | System.out.println(exampleVariableTwo);
12 | }
13 | }
--------------------------------------------------------------------------------
/04_Control Flow Statements/01_Logical Operators/00_Conditional AND/code_input.prob.repl/src/ConditionalAndPracticeOne_Solution.java:
--------------------------------------------------------------------------------
1 | package exlcode;
2 |
3 | public class ConditionalAndPracticeOne_Solution{
4 | public int weirdSum(int paramOne, int paramTwo) {
5 | int varOne = paramOne + paramTwo;
6 | if (10 <= varOne && varOne <= 19){
7 | return 20; // returns 20 if the sum is between 10 and 19 inclusive
8 | } else{
9 | return varOne;
10 | }
11 | }
12 | }
--------------------------------------------------------------------------------
/02_Variables and Operators/03_Math Class/04_Square Root/02_.md:
--------------------------------------------------------------------------------
1 | This method will return a `double` number even if the result is a perfect square. The error that will occur if we use a number less than zero is a result of "NaN", which stands for "Not a Number". Therefore, if we were to write `Math.sqrt(-4)`, the return will be "NaN". Imaginary numbers cannot be represented or returned using this method. And lastly, keep in mind that this function will only return one positive square root value.
2 |
3 |
--------------------------------------------------------------------------------
/06_Arrays/02_ArrayLists/02_Autoboxing/02_.md:
--------------------------------------------------------------------------------
1 | Autoboxing automatically converts `int` values to type `Integer` when the program is run. Therefore, regardless of what primitive data type we want to use, as long as we initialize the `ArrayList` with the right object, we can add primitive data types without creating new objects.
2 |
3 | Use autoboxing when creating an `ArrayList` of objects that have corresponding primitive data types. It makes coding a lot more simple when debugging the code.
4 |
5 |
--------------------------------------------------------------------------------
/03_Strings/00_Strings/03_Null Value/02_.md:
--------------------------------------------------------------------------------
1 | In Java, variables created from the `String` class are like containers, they hold a reference to an object. Therefore, creating 10 strings will create 10 objects and 10 different variables that refer to the different objects. If variables that hold objects exist, we need a way to describe those variables that are not holding or referencing anything - this is where the null value comes in. It tells us that nothing is being held or referenced by the `String`.
2 |
3 |
--------------------------------------------------------------------------------
/03_Strings/02_Conversions/00_ParseInt/00_.md:
--------------------------------------------------------------------------------
1 | In Java, the `Integer` class is part of the `java.lang` package and is automatically imported just like the `String` class. The `parseInt()` method is part of the `Integer` class. This method converts a `String` that only consists of numbers into an integer value while simultaneously assigning it to the primitive data type `int`. The syntax for this method is as follows, `Integer.parseInt(stringname)`. Let's see how this method works in the code below.
2 |
3 |
--------------------------------------------------------------------------------
/07_Object Oriented Programming/00_Objects/00_Creating Objects/01_.repl/src/ObjectsExample.java:
--------------------------------------------------------------------------------
1 | package exlcode;
2 |
3 | public class ObjectsExample {
4 |
5 | public static void main(String[] args) {
6 | // creates a new object of the test class
7 | // since the constructor of the ObjectTest class takes in
8 | // one String parameter, "Hello World!" is inside the parentheses
9 | ObjectTest objectTest = new ObjectTest("Hello World!");
10 | objectTest.print();
11 | }
12 | }
--------------------------------------------------------------------------------
/07_Object Oriented Programming/01_Inheritance/02_Overriding Methods/01_.repl/src/OverrideMethodTestTwo.java:
--------------------------------------------------------------------------------
1 | package exlcode;
2 |
3 | public class OverrideMethodTestTwo extends OverrideMethodTestOne {
4 |
5 | public String exampleVariableTwo = "World";
6 |
7 | // overrides the print method from OverrideMethodTestOne
8 | public void print() {
9 | // calls the print method from the OverrideMethodTestOne
10 | super.print();
11 | System.out.println(exampleVariableTwo);
12 | }
13 | }
--------------------------------------------------------------------------------
/01_Java Syntax and Style/00_Basic Syntax/01_Comments/01_.repl/src/CommentsExample.java:
--------------------------------------------------------------------------------
1 | package exlcode;
2 |
3 | public class CommentsExample {
4 | /* Comment Block
5 |
6 | You can write as much as you want inside the comment block
7 |
8 | */
9 | // this is another example of a comment
10 |
11 | public static void main (String[] args){
12 | // this will not print because it is a comment
13 | // System.out.println("Hello!");
14 | System.out.println("Hello World!");
15 | }
16 | }
--------------------------------------------------------------------------------
/02_Variables and Operators/00_Primitive Data Types/05_Double/00_.md:
--------------------------------------------------------------------------------
1 | Like the `int` primitive data type, `double` is also very commonly used. Most of the time, you will use `int` for whole numbers and `double` for numbers with decimal points (rational or irrational). Double is also known as double-precision floating point. This means it has twice as many bits as `float`, meaning a `double` is more accurate than a `float`. Let's review the code below to see how `double` variables are declared and used.
2 |
3 |
--------------------------------------------------------------------------------
/03_Strings/01_String Methods/05_Trim/02_.md:
--------------------------------------------------------------------------------
1 | The original text has extra spaces before and after, making it inefficient and odd-looking when printed. This method creates a new `String` without added spaces at the beginning or the end while leaving the space in between.
2 |
3 | The trim method is extremely useful when the programmer deals with user input data within the application. Extraneous spaces on either end of user input is a common problem, and those issues are easily solved using the trim method.
4 |
5 |
--------------------------------------------------------------------------------
/06_Arrays/02_ArrayLists/02_Autoboxing/00_.md:
--------------------------------------------------------------------------------
1 | "Autoboxing" is a way to work with primitive data types within `ArrayLists` to make your coding easier. If we wanted to create an `ArrayList` of integers, we use `ArrayListMath.pow(2, 3) returns <<
2 |
3 | ( ) 9 {{Incorrect because the statement above returns 2^3, not 3^2.}}
4 | ( ) 8 {{Incorrect because the output of this method is always a double value.}}
5 | ( ) 9.0 {{Incorrect because the statement above returns 2^3, not 3^2.}}
6 | (x) 8.0 {{Correct because the double value of 2^3 is 8.0.}}
7 |
8 | ||Math.pow(2,3) is the same as “2^3”. ||
9 |
--------------------------------------------------------------------------------
/06_Arrays/00_One Dimensional Arrays/02_Iterating Through 1D Array/code_input.prob.repl/src/IterationOneDArrayPractice_Solution.java:
--------------------------------------------------------------------------------
1 | package exlcode;
2 |
3 | class IterationOneDArrayPractice_Solution{
4 | public int countNine(int[] paramOne) {
5 | int counter = 0; // stores the number of times '9' appears in the array
6 | for (int index = 0; index < paramOne.length; index++){
7 | if (paramOne[index] == 9){
8 | counter++;
9 | }
10 | }
11 | return counter;
12 | }
13 | }
--------------------------------------------------------------------------------
/03_Strings/00_Strings/02_Escape Sequences/01_.repl/src/EscapeSequenceExample.java:
--------------------------------------------------------------------------------
1 | package exlcode;
2 |
3 | public class EscapeSequenceExample {
4 |
5 | public static void main(String[] args) {
6 | // without the second backslash, a syntax error will occur
7 | System.out.println("\\");
8 | // without the backslash, a syntax error will occur
9 | System.out.println("\"Hello World!\"");
10 | // \n prints "Java" on a new line
11 | System.out.println("Hello World!" + "\nJava");
12 | }
13 | }
--------------------------------------------------------------------------------
/02_Variables and Operators/03_Math Class/01_Absolute Value/02_.md:
--------------------------------------------------------------------------------
1 | The absolute value method works the same way as it does in a regular algebra class. The input for this method could be an `int`, `float`, `double` or a `byte` value and will return the same data type as the input. Keep in mind that none of the outputs are rounded when producing the result of the method. Inputting a positive value would simply return the same value while inputting a negative value would return the negative value without the minus sign.
2 |
3 |
--------------------------------------------------------------------------------
/03_Strings/00_Strings/04_Immutability/01_.repl/src/ImmutabilityExample.java:
--------------------------------------------------------------------------------
1 | package exlcode;
2 |
3 | public class ImmutabilityExample {
4 |
5 | // exampleVariableOne holds the reference to the String "Hello World!"
6 | public static String exampleVariableOne = "Hello World!";
7 |
8 | public static void main(String[] args) {
9 | // the String reference for exampleVariableOne changes to the String "Java"
10 | exampleVariableOne = "Java";
11 | System.out.println(exampleVariableOne);
12 | }
13 | }
--------------------------------------------------------------------------------
/07_Object Oriented Programming/02_Abstract Classes and Interfaces/00_Implementing Abstract Classes/00_.md:
--------------------------------------------------------------------------------
1 | In Java an "abstract" class is a class that cannot be instanced but is a superclass for several other related subclasses. The abstract class contains abstract and non-abstract methods, variables, and even constructors that the subclass inherits. The Java reserved word `abstract` can only be used in an abstract class and will cause an error if used in a regular class. This is how an abstract class can be utilized.
2 |
3 |
--------------------------------------------------------------------------------
/02_Variables and Operators/03_Math Class/02_Floor/01_.repl/src/FloorMethodExample.java:
--------------------------------------------------------------------------------
1 | package exlcode;
2 |
3 | public class FloorMethodExample {
4 |
5 | // Returns largest integer that is less than or equal to the argument
6 | public static double exampleVariableOne = Math.floor(10.4);
7 | public static double exampleVariableTwo = Math.floor(-20.4);
8 |
9 | public static void main(String[] args) {
10 | System.out.println(exampleVariableOne);
11 | System.out.println(exampleVariableTwo);
12 | }
13 | }
--------------------------------------------------------------------------------
/02_Variables and Operators/02_Operators/06_Logical Complement/02_.md:
--------------------------------------------------------------------------------
1 | The value of the two boolean variables are different because one is the inverse of the other. The NOT operator changes the value of `exampleVariableOne` from true to false and assigns false to `exampleVariableTwo`.
2 |
3 | Please remember to use brackets to section off the NOT operator so it works as intended. As we keep working in Java, especially with if statements, we will see uses for this operator surface as an alternative for writing long lines of code.
4 |
5 |
--------------------------------------------------------------------------------
/02_Variables and Operators/03_Math Class/03_Ceiling/01_.repl/src/CeilingMethodExample.java:
--------------------------------------------------------------------------------
1 | package exlcode;
2 |
3 | public class CeilingMethodExample {
4 |
5 | // Returns smallest integer that is greater than or equal to the argument
6 | public static double exampleVariableOne = Math.ceil(10.4);
7 | public static double exampleVariableTwo = Math.ceil(-20.4);
8 |
9 | public static void main(String[] args) {
10 | System.out.println(exampleVariableOne);
11 | System.out.println(exampleVariableTwo);
12 | }
13 | }
--------------------------------------------------------------------------------
/03_Strings/01_String Methods/03_CharAt/00_.md:
--------------------------------------------------------------------------------
1 | Now that we have explored the concept of index in Java, let's see the index related functions that exist in the `String` class. The `charAt` method returns a single character from a specified index. The syntax is as follows, `stringname.charAt(any integer)` and the return value is a single character `char`, not a `String`. In a case where the index is negative or greater than `stringname.length()-1`, you will receive a runtime error. Let's see a few examples of the `charAt` method.
2 |
3 |
--------------------------------------------------------------------------------
/04_Control Flow Statements/02_Final Exam/05_Question 6/code_input.prob.repl/src/IfElsePractice_Solution.java:
--------------------------------------------------------------------------------
1 | package exlcode;
2 |
3 | public class IfElsePractice_Solution{
4 | public int numberSum(int paramOne, int paramTwo) {
5 | // Store the sum in a local variable
6 | int varOne = paramOne + paramTwo;
7 |
8 | // Double varOne if paramOne and paramTwo are the same
9 | if (paramOne == paramTwo) {
10 | varOne *= 2;
11 | }
12 |
13 | // return the sum
14 | return varOne;
15 | }
16 | }
--------------------------------------------------------------------------------
/06_Arrays/02_ArrayLists/02_Autoboxing/01_.repl/src/AutoBoxingExample.java:
--------------------------------------------------------------------------------
1 | package exlcode;
2 |
3 | import java.util.ArrayList;
4 |
5 | public class AutoBoxingExample {
6 |
7 | public static ArrayListMath.floor(-5.5) returns <<
2 |
3 | ( ) -5.0 {{Incorrect because -5.0 is greater than -5.5.}}
4 | ( ) -5 {{Incorrect because -5 is greater than -5.5.}}
5 | ( ) -6 {{Incorrect because the output of this method has to be a double.}}
6 | (x) -6.0 {{Correct because the floor method returns the closest whole number that is smaller than or equal to the input.}}
7 |
8 | ||Does the word "floor" make you think of lower or higher number? ||
9 |
--------------------------------------------------------------------------------
/02_Variables and Operators/04_Final Exam/13_Question 14/00_Multiple Choice.prob.md:
--------------------------------------------------------------------------------
1 | >>Math.floor(5.5) returns <<
2 |
3 | (x) 5.0 {{Correct because the floor method returns the closest whole number that is smaller than or equal to the input.}}
4 | ( ) 5 {{Incorrect because the output of the method is always a double value.}}
5 | ( ) 6 {{Incorrect because 6 is greater than 5.5.}}
6 | ( ) 6.0 {{Incorrect because 6.0 is greater than 5.5.}}
7 |
8 | ||Does the word "floor" make you think of lower or higher number? ||
9 |
--------------------------------------------------------------------------------
/07_Object Oriented Programming/02_Abstract Classes and Interfaces/02_Polymorphism/00_.md:
--------------------------------------------------------------------------------
1 | All Java objects are polymorphic. "Polymorphism" is the ability of an object to take on different forms. The most common use of polymorphism occurs when the superclass reference is used to refer to a subclass object. We touched on this concept in the chapter on inheritance. Superclasses can be used to create objects such as `Superclass objectName = new SubClass();`. The program below is an example of using both an abstract class and an interface.
2 |
3 |
--------------------------------------------------------------------------------
/08_Recursion/00_Methods/00_Creating Recursive Methods/01_.repl/src/RecursiveMethodsExample.java:
--------------------------------------------------------------------------------
1 | package exlcode;
2 |
3 | public class RecursiveMethodsExample {
4 |
5 | public static void main(String[] args) {
6 | // prints 1-10 in descending order
7 | print(10);
8 | }
9 |
10 | public static void print(int parameterOne) {
11 | if (parameterOne > 0) {
12 | System.out.print(parameterOne + " ");
13 | parameterOne--;
14 | // recursive call
15 | print(parameterOne);
16 | }
17 | }
18 | }
--------------------------------------------------------------------------------
/09_Search and Sort/01_Sorting/00_Selection Sort/02_.md:
--------------------------------------------------------------------------------
1 | There are two loops in a selection sort. The inner loop finds the next smallest or largest value while the outer loop places that value into its proper location. Although selection sort is one of the easier sorts to code, it is also fairly inefficient as there is no way you can end the sort early, even if the list is already sorted. No matter what the state of the list is, the selection sort will go through each index, starting with zero, and sort each element through to the end.
2 |
3 |
--------------------------------------------------------------------------------
/02_Variables and Operators/02_Operators/06_Logical Complement/01_.repl/src/LogicalComplementExample.java:
--------------------------------------------------------------------------------
1 | package exlcode;
2 |
3 | public class LogicalComplementExample {
4 |
5 | public static boolean exampleVariableOne = true;
6 | // The character '!' inverts the boolean value of exampleVariableOne
7 | public static boolean exampleVariableTwo = !exampleVariableOne;
8 |
9 | public static void main(String[] args) {
10 | System.out.println(exampleVariableOne);
11 | System.out.println(exampleVariableTwo);
12 | }
13 | }
--------------------------------------------------------------------------------
/02_Variables and Operators/04_Final Exam/04_Question 5/00_Multiple Choice.prob.md:
--------------------------------------------------------------------------------
1 | >>Math.ceil(5.5) returns <<
2 |
3 | ( ) 5.0 {{Incorrect because 5.0 is smaller than 5.5.}}
4 | ( ) 5 {{Incorrect because 5 is smaller than 5.5.}}
5 | ( ) 6 {{Incorrect because the output of this method is always a double value.}}
6 | (x) 6.0 {{Correct because the ceiling method returns the closest whole number that is greater than or equal to the input.}}
7 |
8 | ||Does the word “ceiling” make you think of lower or higher number? ||
9 |
--------------------------------------------------------------------------------
/00_Introduction to Java/02_Java class and source file/00_Imports/01_.repl/src/ImportExample.java:
--------------------------------------------------------------------------------
1 | package exlcode;
2 |
3 | // imports
4 | import java.util.ArrayList;
5 |
6 | public class ImportExample {
7 |
8 | public static void main(String[] args) {
9 | // This will be explained in Unit 7
10 | ArrayListMath.ceil(-5.5) returns <<
2 |
3 | ( ) -5 {{Incorrect because the output of this method is always a double value.}}
4 | ( ) -6 {{Incorrect because -6 is smaller than -5.5.}}
5 | (x) -5.0 {{Correct because the ceiling method returns the closest whole number that is greater than or equal to the input.}}
6 | ( ) -6.0 {{Incorrect because -6.0 is smaller than -5.5.}}
7 |
8 | ||Does the word “ceiling” make you think of lower or higher number? ||
9 |
--------------------------------------------------------------------------------
/10_Exceptions/01_Examples of Exceptions/04_NaN/02_.md:
--------------------------------------------------------------------------------
1 | When we attempt to find the square root of a negative number, the program returns "NaN". Contrary to exceptions, a "NaN" result will not cause your program to stop, but may still become an issue if you try to the use the "NaN" result in any other calculations in the program. For example, you will likely throw an error when "NaN", which is not a number, ends up in an expression with an `int`. Java will throw an error because arithmetic operators cannot be used on two different data types.
2 |
3 |
--------------------------------------------------------------------------------
/03_Strings/01_String Methods/07_Equals/02_.md:
--------------------------------------------------------------------------------
1 | When using the "==" operator to compare the strings, we receive a result of "false" because the strings reference two different objects that are held in different memory spaces. However, if a statement like `String varTwo = varOne;` is called after `String varOne = "Java";`, the reference for the variable `varTwo` is the same as the reference of `varOne`, meaning that the "==" operator has a result of "true". This only works if the first `String` is directly assigned to the value of the second `String`.
2 |
3 |
--------------------------------------------------------------------------------
/05_Iterations/01_Branching Statements/00_Break/02_.md:
--------------------------------------------------------------------------------
1 | The `if` statement has the expression "count == 5", so when `count` has a value of 5 the statements inside the `if` statement will be executed, including the `break;` statement, which will terminate the `for` loop so any number after 5 will not be printed. `break;` does not affect the `if` statement, it terminates the whole loop. When the `break;` statement is used appropriately, it saves time when running the program because you wouldn't have to loop through the same statements over and over again.
2 |
3 |
--------------------------------------------------------------------------------
/06_Arrays/00_One Dimensional Arrays/00_Creating One Dimensional Arrays/code_input.prob.repl/src/CreateOneDArrayPractice_Solution.java:
--------------------------------------------------------------------------------
1 | package exlcode;
2 |
3 | public class CreateOneDArrayPractice_Solution{
4 | public int[] compareArr(int[] paramOne, int[] paramTwo) {
5 | // checks to see if paramTwo has a larger sum
6 | if (paramOne[0] + paramOne[1] < paramTwo[0] + paramTwo[1]){
7 | return paramTwo;
8 | }
9 | return paramOne; // returns paramOne if paramOne has a larger sum or if the sum for both arrays are equal
10 | }
11 | }
--------------------------------------------------------------------------------
/06_Arrays/00_One Dimensional Arrays/03_Enhanced for Statement/01_.repl/src/EnhancedForLoopExample.java:
--------------------------------------------------------------------------------
1 | package exlcode;
2 |
3 | public class EnhancedForLoopExample {
4 |
5 | public static int[] exampleVariableOne = {0, 1, 2, 3, 4, 5, 6, 7, 8};
6 | public static int sum = 0;
7 | public static void main(String[] args) {
8 | // simplifies the for loop and creates simple code
9 | // 1D array
10 | for (int count : exampleVariableOne) {
11 | sum += exampleVariableOne[count];
12 | }
13 | System.out.println(sum);
14 | }
15 | }
--------------------------------------------------------------------------------
/06_Arrays/01_Two Dimensional Arrays/01_2D Array Length/00_.md:
--------------------------------------------------------------------------------
1 | Now we will take a look at the properties of the rows and columns that make up 2D arrays. Most of the time, each row in a 2D array will have the same number of columns, but that may not always be the case. If you were to initialize a 2D array by listing out the elements individually, it may lead to a row with a different number of columns. In situations like this, and others, you will need to know how to access the length of the row or the column of a 2D array. Let's see how it's done below.
2 |
3 |
--------------------------------------------------------------------------------
/07_Object Oriented Programming/00_Objects/02_Dot Notation/01_.repl/src/DotNotationExample.java:
--------------------------------------------------------------------------------
1 | package exlcode;
2 |
3 | public class DotNotationExample {
4 |
5 | public static void main(String[] args) {
6 | DotNotationTest dotNotationTest = new DotNotationTest();
7 | // any public variable or method in DotNotationTest can be
8 | // accessed through dot notation
9 | System.out.println(dotNotationTest.exampleVariableOne);
10 | System.out.println(dotNotationTest.exampleVariableTwo);
11 | dotNotationTest.print();
12 | }
13 | }
--------------------------------------------------------------------------------
/02_Variables and Operators/03_Math Class/04_Square Root/01_.repl/src/SquareRootExample.java:
--------------------------------------------------------------------------------
1 | package exlcode;
2 |
3 | public class SquareRootExample {
4 |
5 | public static double exampleVariableOne = Math.sqrt(100);
6 | public static double exampleVariableTwo = Math.sqrt(6.25);
7 | public static double exampleVariableThree = Math.sqrt(3);
8 |
9 | public static void main(String[] args) {
10 | System.out.println(exampleVariableOne);
11 | System.out.println(exampleVariableTwo);
12 | System.out.println(exampleVariableThree);
13 | }
14 | }
--------------------------------------------------------------------------------
/07_Object Oriented Programming/02_Abstract Classes and Interfaces/01_Implementing Interfaces/01_.repl/src/InterfaceTestThree.java:
--------------------------------------------------------------------------------
1 | package exlcode;
2 |
3 | public class InterfaceTestThree implements InterfaceTestOne, InterfaceTestTwo {
4 |
5 | // implements the method print() from InterfaceTestOne
6 | public void print() {
7 | System.out.println(exampleVariableOne);
8 | }
9 |
10 | // implements the method printGreeting() from InterfaceTestOne
11 | public void printGreeting() {
12 | System.out.println(exampleVariableTwo);
13 | }
14 | }
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | The content of this project itself, including, but not limited to the content of all .md (Markdown) and .yaml (YAML) files included in this project, is licensed under the [Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License](https://creativecommons.org/licenses/by-nc-sa/4.0/), and all of the source code provided alongside the content, including, but not limited to to the .java (Java) files, is licensed under the source code license provided in the SOURCE_CODE_LICENSE.md file included in the same directory as this notice.
2 |
--------------------------------------------------------------------------------
/02_Variables and Operators/03_Math Class/02_Floor/02_.md:
--------------------------------------------------------------------------------
1 | As the nearest whole number that is less than or equal to 10.4 is 10, 10.0 is printed. Similarly, since the closest whole number that is less than or equal to -20.4 is -21, -21.0 is printed. Notice that even if we input a non-decimal number into the floor function, a `double` is returned. Since data precision is not hindered when you convert from an `int` data type to a `double`, Java will do it without throwing any errors. The floor function's primary use is rounding, all ready for you to use while coding.
2 |
3 |
--------------------------------------------------------------------------------
/01_Java Syntax and Style/01_Errors/01_Logic Errors/01_.repl/src/LogicErrorExample.java:
--------------------------------------------------------------------------------
1 | package exlcode;
2 |
3 | public class LogicErrorExample {
4 | public static int exampleVariableOne = 5;
5 | public static int exampleVariableTwo = 10;
6 | public static int exampleVariableThree = exampleVariableTwo * exampleVariableOne;
7 |
8 | public static void main(String[] args) {
9 | // this prints the wrong number because the symbol '*' is used instead of the
10 | // '/'
11 | System.out.println("10 divided by 5 is " + exampleVariableThree);
12 | }
13 | }
--------------------------------------------------------------------------------
/02_Variables and Operators/00_Primitive Data Types/09_Scientific Notation/01_.repl/src/ScientificNotationExample.java:
--------------------------------------------------------------------------------
1 | package exlcode;
2 |
3 | public class ScientificNotationExample {
4 |
5 | public static double exampleVariableOne = 1E+3;
6 | public static double exampleVariableTwo = 1E+12;
7 | public static double exampleVariableThree = 1E-4;
8 |
9 | public static void main(String[] args) {
10 | System.out.println(exampleVariableOne);
11 | System.out.println(exampleVariableTwo);
12 | System.out.println(exampleVariableThree);
13 | }
14 | }
--------------------------------------------------------------------------------
/03_Strings/01_String Methods/02_IndexOf/02_.md:
--------------------------------------------------------------------------------
1 | Indexing starts with zero, which is why the program above will print 6, not 7. Therefore, if you had a `String` "Java":multipleOfThree so that it satisfies the following condition:For example:
4 | multipleOfThree(3) should return true
5 | multipleOfThree(15) should return true
6 | multipleOfThree(20) should return false
Math.abs(-3) returns <<
2 |
3 | (x) 3 {{Correct because the absolute value of the integer -3 is 3}}
4 | ( ) -3{{Incorrect because the absolute value of a number cannot be a negative integer.}}
5 | ( ) 3.0{{Incorrect because the absolute value method will return an int value if the input is also an int.}}
6 | ( ) -3.0{{Incorrect because the absolute value of a number cannot be a negative integer.}}
7 |
8 | ||Can the absolute value of a number be negative? ||
9 |
--------------------------------------------------------------------------------
/02_Variables and Operators/03_Math Class/06_Random/01_.repl/src/RandomMethodExample.java:
--------------------------------------------------------------------------------
1 | package exlcode;
2 |
3 | public class RandomMethodExample {
4 |
5 | // Returns double value greater than or equal to 0.0 and less than 1.0
6 | public static double exampleVariableOne = Math.random();
7 | // Returns an integer value between 1 and 100
8 | public static int exampleVariableTwo = (int) (Math.random() * 101);
9 |
10 | public static void main(String[] args) {
11 | System.out.println(exampleVariableOne);
12 | System.out.println(exampleVariableTwo);
13 | }
14 | }
--------------------------------------------------------------------------------
/03_Strings/00_Strings/01_Creating Strings/02_.md:
--------------------------------------------------------------------------------
1 | To create a new object, we use the Java reserved word `new` because `String` is a class within the `java.lang` package. However, Java has made the process of importing easier for programmers. As you see above, you can initialize the `String` without having to type out `new`. Ultimately, it is up to you to decide which method of creating a `String` works best for you.
2 |
3 | Remember, it is possible to create an empty `String` by either leaving the parenthesis blank or omitting characters on the inside of the double-quotation marks.
4 |
5 |
--------------------------------------------------------------------------------
/08_Recursion/02_Final Exam/00_Question 1/00_Code Input.prob.md:
--------------------------------------------------------------------------------
1 | >>Complete the method multipleOfTwo so that it satisfies the following condition:paramOne
3 | Use recursion when writing your response.
4 | For example:
5 | multipleOfTwo(1) should return 2
6 | multipleOfTwo(2) should return 4
7 | multipleOfTwo(3) should return 6
paramOne is equal to 0 or not. ||
12 |
--------------------------------------------------------------------------------
/02_Variables and Operators/00_Primitive Data Types/01_Boolean/02_.md:
--------------------------------------------------------------------------------
1 | We see in the code above that boolean values don't necessarily have to come out "true". For example "7>9" will be false, while "7<9" will be true. Boolean is extremely useful because it allows particular statements and methods to be executed only in certain situations based on whether the boolean statement is true or false. For this reason, it is one of the most important primitive data types.
2 |
3 | Later on, we will examine comparing boolean values to each other and the role that plays with control flow statements.
4 |
5 |
--------------------------------------------------------------------------------
/02_Variables and Operators/04_Final Exam/08_Question 9/00_Multiple Choice.prob.md:
--------------------------------------------------------------------------------
1 | >>Which option below express 0.01 in scientific notation? <<
2 |
3 | (x) 10E-3 {{Correct because the decimal value 0.01 is equivalent to 10E-3.}}
4 | ( ) 1/10/10 {{Incorrect because it does not use scientific notation.}}
5 | ( ) 1E-3 {{Incorrect because 1E-3 results in 0.001.}}
6 | ( ) 10e-4 {{Incorrect because 10e-4 results in 0.001.}}
7 | ( ) 10^-2 {{Incorrect because it does not use scientific notation.}}
8 |
9 | ||Look closely at the answer choices above and if they use scientific notation. ||
10 |
--------------------------------------------------------------------------------
/07_Object Oriented Programming/02_Abstract Classes and Interfaces/01_Implementing Interfaces/00_.md:
--------------------------------------------------------------------------------
1 | Java functions with "single inheritance", meaning that a subclass can only inherit from one superclass. The reserved word `extends` can only be used to extend from one class. However, Java has interfaces, a class that allows multiple inheritance. An interface is a set of requirements that a class must implement. An interface is a list of constants and method headers with no method bodies. All methods and constants must be implemented by the class. Let's see how an interface can be used.
2 |
3 |
--------------------------------------------------------------------------------