SlideShare a Scribd company logo
1 of 200
Download to read offline
Java 8 for Complete Beginners
Master the basics of programming
Learn programming the easy way, by
using the world’s most popular language
to:
• Discover anyone can code in Java
• Write your own programs
• Be in demand world-wide
2 Marius Claassen, 2017
About me
Marius Claassen, Java Developer and Teacher
I am a self-taught java developer. Having been a teacher for many
years, I am now working full-time as an independent software
instructor, making video tutorials. At the time of making these Java
tutorials, I am living in South Africa.
3 Marius Claassen, 2017
Email me mariusclaassen@gmail.com for details
on how to buy this course.
4 Marius Claassen, 2017
Benefits
• Read Java code
• Develop basic Java applications
• Structure high quality, working code
• Devise solutions when given a
problem statement
5 Marius Claassen, 2017
Major components
1. Introduction
2. Java basics
3. Arrays
4. Exceptions
5. Java classes
6. Conclusion
6 Marius Claassen, 2017
Ideal student
Complete beginner who wants to learn
programming by:
• watching live coding
• doing coding exercises
• checking answers against solutions
7 Marius Claassen, 2017
Enrolment
This course is now open for enrolment
8 Marius Claassen, 2017
TOPICS:
1. Introduction
2. Java basics
3. Arrays
4. Exceptions
5. Java classes
6. Conclusion
9 Marius Claassen, 2017
Lecture 2: Java overview
General-purpose programming language
10 Marius Claassen, 2017
Lecture 2: Java overview
• Object-oriented
11 Marius Claassen, 2017
• Object-oriented
Person Dog Internet website
12 Marius Claassen, 2017
• Architecture neutral
13 Marius Claassen, 2017
• Architecture neutral
Windows Apple Linux
14 Marius Claassen, 2017
• Secure
15 Marius Claassen, 2017
Program development process
Compiler Java VM
HelloWorld.java HelloWorld.class Hello, world
object 13
16 Marius Claassen, 2017
Java’s popularity
object 13
17 Marius Claassen, 2017
Lecture 3: Development tools
• JDK (SE 8)
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
• IDE (IntelliJ IDEA)
https://www.jetbrains.com/idea/download/#section=windows
• Internet browser (Google Chrome)
21 Marius Claassen, 2017
22 Marius Claassen, 2017
22
23 Marius Claassen, 2017
24 Marius Claassen, 2017
25 Marius Claassen, 2017
26 Marius Claassen, 2017
27 Marius Claassen, 2017
28 Marius Claassen, 2017
29 Marius Claassen, 2017
30 Marius Claassen, 2017
31 Marius Claassen, 2017
32 Marius Claassen, 2017
33 Marius Claassen, 2017
34 Marius Claassen, 2017
35 Marius Claassen, 2017
36 Marius Claassen, 2017
37 Marius Claassen, 2017
38 Marius Claassen, 2017
39 Marius Claassen, 2017
40 Marius Claassen, 2017
41 Marius Claassen, 2017
42 Marius Claassen, 2017
TOPICS:
1. Introduction
2. Java basics
3. Arrays
4. Exceptions
5. Java classes
6. Conclusion
43 Marius Claassen, 2017
Lecture 4: Hello world example
Hello world problem statement:
Print ‘hello world’
44 Marius Claassen, 2017
Lecture 4: Hello world example
public class Lecture4 {
public static void main(String[] args) {
System.out.print(“hello world”);
}
}
// hello world
45 Marius Claassen, 2017
Lecture 4: First coding exercise
Replace the comment with a statement to
print the name, ‘Adam’.
46 Marius Claassen, 2017
Lecture 5: First exercise solution
public class Lecture5 {
public void printAdam() {
System.out.print(“Adam”);
}
}
47 Marius Claassen, 2017
Lecture 6: Primitives declaration
dataType storageName; Declaration
48 Marius Claassen, 2017
Lecture 6: Primitives declaration
int intValue;
double doubleValue;
char charValue;
boolean booleanValue;
00.0
F
‘0’
49 Marius Claassen, 2017
00
Lecture 6: Primitives
• byte, short, int, long
• float, double
• boolean
• char
50 Marius Claassen, 2017
Lecture 6: Declaration example
Declaration problem statement:
Declare Java’s 8 primitive data types
51 Marius Claassen, 2017
Lecture 6: Declaration example
public class Lecture6 {
public static void main(String[] args) {
int intValue; // Declaration
}
}
52 Marius Claassen, 2017
Lecture 6: Declaration exercise
Replace the comment with a statement to
declare a ‘char’ data type, named ‘letterY’.
53 Marius Claassen, 2017
Lecture 7: Primitives solution
public class Lecture7 {
public void declareLetterY() {
char letterY; // Declaration
}
}
54 Marius Claassen, 2017
Lecture 8: Primitives initialization
dataType storageName; // Declaration
storageName = value; // Initialization
dataType storageName = value; // Declaration/Initialization
55 Marius Claassen, 2017
int intValue = 900; // Initialization
char charValue = ‘a’; // Initialization
56 Marius Claassen, 2017
900
‘a’
Lecture 8: Initialization example
Initialization problem statement:
Initialize an int data type named ‘intValue’
with the number 900.
57 Marius Claassen, 2017
Lecture 8: Initialization example
public class Lecture8 {
public static void main(String[] args) {
int intValue = 900; // Declare and Initialize
}
}
58 Marius Claassen, 2017
Lecture 8: Initialization exercise
Initialize a char data type, named ‘letterY’
with the value, ‘Y’.
59 Marius Claassen, 2017
Lecture 9: Initialization solution
public class Lecture9 {
public void setLetterY() {
char letterY = ‘Y’; // Declare and Initialize
}
}
60 Marius Claassen, 2017
Lecture 10: Operators example
Operators problem statement:
Assign ‘11 * 18’ to a ‘short’ data type named
‘answer1’.
61 Marius Claassen, 2017
Lecture 10: Operators example
public class Lecture10 {
public static void main(String[] args) {
short answer1 = 11 * 18;
}
}
62 Marius Claassen, 2017
Lecture 10: Java operators
• short answer1 = 11 * 18; // Multiply
• int answer2 = 15 % 4; // Remainder
• double answer3 = 12.0 + 9.0; // Add
• boolean answer4 = 36 < 35; // Less than
63 Marius Claassen, 2017
Lecture 10: Operators exercise
Assign ‘40 – 13’ to a ‘byte’ data type named
‘answer5’
64 Marius Claassen, 2017
Lecture 11: Java operators solution
public class Lecture11 {
public void setAnswer5() {
byte answer5 = 40 - 13;
}
}
65 Marius Claassen, 2017
Lecture 12: Reference data types
700
66 Marius Claassen, 2017
mySignOff “Keep coding”
String mySignOff = “Keep coding”;
int myNumber = 700;
Lecture 12: References example
References problem statement:
Declare a String named, ‘mySignOff’
initialized as ‘Keep coding’
67 Marius Claassen, 2017
Lecture 12: References example
public class Lecture12 {
public static void main(String[] args) {
String mySignOff = “Keep coding”;
}
}
68 Marius Claassen, 2017
Lecture 12: References exercise
Declare a String named, ‘words’ initialized
as, ‘In the beginning’.
69 Marius Claassen, 2017
Lecture 13: References solution
public class Lecture13 {
public void setWords() {
String words = “In the beginning”;
}
}
70 Marius Claassen, 2017
Lecture 14: Scanner class example
Scanner class problem statement:
Write code to have Java ask for your name
71 Marius Claassen, 2017
Lecture 14: Scanner class example
public class Lecture14 {
public static void main(String[] args) {
System.out.print(“What is your name? ”);
Scanner scanner1 = new Scanner(System.in);
String name = scanner1.next();
System.out.print(“Your name is ” + name);
}
}
72 Marius Claassen, 2017
Lecture 14: Scanner class exercise
Declare and initialize a String named
‘language’ as ‘scanner1.next()’
73 Marius Claassen, 2017
Lecture 15: Scanner class solution
public class Lecture15 {
public String getLanguage() {
System.out.print(“Which programming language is the
most widely used? ”);
Scanner scanner1 = new Scanner(System.in);
String language = scanner1.next();
return language;
}
}
74 Marius Claassen, 2017
Lecture 16: Conditionals &&, ||
‘J’
75 Marius Claassen, 2017
char charJ = ‘J’;
char charK = ‘K’;
// Declare, initialize
// Declare, initialize‘K’
Lecture 16: Conditionals &&, ||
‘J’
76 Marius Claassen, 2017
char charJ = ‘J’;
char charK = ‘K’
if ( (charJ == ‘J’) && (charK == ‘K’) ) {
‘K’
System.out.print( “charJ is J and charK is K”);
}
Lecture 16: Conditionals &&, ||
Conditional operators problem statement:
Implement the ‘&&’ operator where charJ =
‘J’ and charK = ‘K’ and print ‘charJ is J AND
charK is K’.
77 Marius Claassen, 2017
Lecture 16: Conditionals &&, ||
public class Lecture16 {
public static void main(String[] args) {
char charJ = ‘J’; char charK = ‘K’;
if ( (charJ == ‘J’ ) && (charK == ‘K’) ) {
System.out.print(“ charJ is ‘J’ AND charK is ‘K’ ” );
}
}
}
78 Marius Claassen, 2017
Lecture 16: Conditionals exercise
Implement the ‘||’ operator with
‘evenNumber’ as 8 or ‘oddNumber’ as 12
79 Marius Claassen, 2017
Lecture 17: Conditionals solution
public class Lecture17 {
public static void main(String[] args) {
int evenNumber = 8; int oddNumber = 9;
if ( (evenNumber == 8) || (oddNumber == 12) )
{
System.out.print(“evenNumber is 8 OR oddNumber is 12”);
}
}
}80 Marius Claassen, 2017
Lecture 18: If-then example
81 Marius Claassen, 2017
21 and 21 “Equal”
if num6 is equal to num7 then print they are equal
Lecture 18: If-then-else example
82 Marius Claassen, 2017
“Not equal”
56 and 65
“Equal”
Lecture 18: If-then-else example
83 Marius Claassen, 2017
“Not equal”
56 and 65
if num1 is equal to num2 then print they are equal,
else print they are not equal
Lecture 18: If-then-else example
If-then-else problem statement:
Implement ‘if-then-else’ where num1 = 56 and
num2 = 65, and print whether they are equal
or not
84 Marius Claassen, 2017
Lecture 18: If-then-else example
public class Lecture18 {
public static void main(String[] args) {
int num1 = 56; int num2 = 65;
if (num1 == num2)
{ System.out.print(“56 is equal to 65”); }
else { System.out.print(“56 is not equal to 65”); }
}
} // 56 is not equal to 65
85 Marius Claassen, 2017
Lecture 18: If-then-else exercise
Implement ‘if-then-else’ with testScore >= 60
86 Marius Claassen, 2017
Lecture 19: If-then-else solution
public class Lecture19 {
public void printIfThenElse() {
int testScore = 74; String result = “undefined”;
if (testScore >= 60)
{ result = “pass”; }
else { result = “fail”; }
System.out.print(result);
}
}
87 Marius Claassen, 2017
Lecture 20: Switch example
Switch problem statement:
Implement a ‘switch’ statement to print
weekday 6 as ‘Friday’.
88 Marius Claassen, 2017
Lecture 20: Switch example
89 Marius Claassen, 2017
1
2
3
4
5
6
7
“Friday”
“Saturday”
“Thursday”
“Wednesday”
“Tuesday”
“Monday”
“Sunday”
Lecture 20: Switch example
90 Marius Claassen, 2017
1
2
3
4
5
6
7
“Friday”
Lecture 20: Switch example
String day = “6”;
switch (day) {
case “1” : System.out.print(“Sunday”); break;
case “2” : System.out.print(“Monday”); break;
case “3” : System.out.print(“Tuesday”); break;
case “4” : System.out.print(“Wednesday”); break;
case “5” : System.out.print(“Thursday”); break;
case “6” : System.out.print(“Friday”); break;
case “7” : System.out.print(“Saturday”); break;
default: System.out.print(“Invalid weekday”); break;
} // Friday
91 Marius Claassen, 2017
Lecture 20: Switch exercise
Implement a ‘switch’ statement to print
calendar month 3 as ‘March’
92 Marius Claassen, 2017
Lecture 21: Switch solution
String month = “3”;
switch (month) {
case “1” : System.out.print(“January”); break;
case “2” : System.out.print(“February”); break;
case “3” : System.out.print(“March”); break;
case “4” : System.out.print(“April”); break;
.
.
default: System.out.print(“Invalid month”); break;
}
93 Marius Claassen, 2017
Lecture 22: For loop example
94 Marius Claassen, 2017
Repeated action
Lecture 22: For loop example
95 Marius Claassen, 2017
Stop condition
Lecture 22: For loop example
For loop problem statement:
Implement a ‘for’ loop to print the five values
24 to 28.
96 Marius Claassen, 2017
Lecture 22: For loop example
public class Lecture22 {
public static void main(String[] args) {
for (int j = 24; j < 29; j++) {
System.out.print( j + “ ”);
}
}
} // 24 25 26 27 28
97 Marius Claassen, 2017
Lecture 22: For loop exercise
Implement a ‘for’ loop to print the three
values 87 to 89
98 Marius Claassen, 2017
Lecture 23: For loop solution
public class Lecture23 {
public void printForLoop() {
for (int j = 87; j < 89; j++) {
System.out.print( j + “ ”);
}
}
}
99 Marius Claassen, 2017
Lecture 24: While loop example
While loop problem statement:
Implement a ‘while’ loop to print the four
values, divisible by 5, from 40 to 55.
100 Marius Claassen, 2017
Lecture 24: While loop example
public class Lecture24 {
public static void main(String[] args) {
int j = 40;
while ( j <= 55) {
System.out.print( j + “ ”);
j = j + 5;
}
}
} // 40 45 50 55
101 Marius Claassen, 2017
Lecture 24: While loop exercise
Implement a ‘while’ loop with the control
condition <= 18
102 Marius Claassen, 2017
Lecture 25: While loop solution
public class Lecture25 {
public void printWhileLoop() {
int j = 9;
while ( j <= 18) {
System.out.print( j + “ ”);
j = j + 3;
}
}
}
103 Marius Claassen, 2017
Lecture 26: Do-while loop example
Do-while loop problem statement:
Implement a ‘do-while’ loop to print the 3
uppercase letters ‘Q’ to ‘S’
104 Marius Claassen, 2017
Lecture 26: Do-while loop example
public class Lecture26 {
public static void main(String[] args) {
char letter = ‘Q’;
do {
System.out.print(letter + “ ”);
letter++; // Increment
} while (letter <= ‘S’);
}
} // Q R S
105 Marius Claassen, 2017
Lecture 26: Do-while exercise
Implement a ‘do-while’ loop to print the 5
letters ‘a’ to ‘e’ in reverse order
106 Marius Claassen, 2017
Lecture 27: Do-while loop solution
public class Lecture27 {
public void printDoWhileLoop() {
char letter = ‘e’;
do {
System.out.print(letter + “ ”);
letter--; // Decrement
} while (letter >= ‘a’);
}
}
107 Marius Claassen, 2017
TOPICS:
1. Introduction
2. Java basics
3. Arrays
4. Exceptions
5. Java classes
6. Conclusion
108 Marius Claassen, 2017
Lecture 28: One-dimensional array
109 Marius Claassen, 2017
Lecture 28: One-dimensional array
110 Marius Claassen, 2017
Lecture 28: One-dimensional array
0 1 2 3 4
13.0 17.0 21.0 25.0 29.0
111 Marius Claassen, 2017
indices
array length of 5
elements
Lecture 28: One-dimensional array
One-dimensional array problem statement:
Implement a one-dimensional double array
and print all the values using a ‘for’ loop
112 Marius Claassen, 2017
Lecture 28: One-dimensional array
public class Lecture28 {
public static void main(String[] args) {
double[ ] numbers = {13.0, 17.0, 21.0, 25.0, 29.0};
for (double number : numbers) {
System.out.print(number + “ ”);
}
}
} // 13.0, 17.0, 21.0, 25.0, 29.0113 Marius Claassen, 2017
Lecture 28: One-D array exercise
Implement a one-dimensional integer array
named ‘values’, initialized with the elements
30, 31, 32 and 33
114 Marius Claassen, 2017
Lecture 29: One-D array solution
public class Lecture29 {
public void printOneDArray() {
int[ ] values = {30, 31, 32, 33};
for (int value : values) {
System.out.print(value + “ ”);
}
}
}115 Marius Claassen, 2017
Lecture 30: Two-dimensional array
116 Marius Claassen, 2017
Lecture 30: Two-D array example
0 1 2 3 4
alpha bravo charlie delta echo 0
foxtrot golf hotel india juliet 1
kilo lima mike november oscar 2
papa quebec romeo sierra tango 3
117 Marius Claassen, 2017
4 Rows
5 Columns
Lecture 30: Two-D array example
Two-dimensional array problem statement:
Implement a two-dimensional String array to
print the element at row 1 column 3
118 Marius Claassen, 2017
Lecture 30: Two-D array example
public class Lecture30 {
public static void main(String[] args) {
String[][] phoneticAlphabet = {
{“alpha”, “bravo”, “charlie”, “delta”, “echo” },
{“foxtrot”, “golf”, “hotel”, “india”, “juliet” },
{“kilo”, “lima”, “mike”, “november”, “oscar” },
{“papa”, “quebec”, “romeo”, “sierra”, “tango” } };
System.out.print(phoneticAlphabet[1][3]);
}
} // india
119 Marius Claassen, 2017
Lecture 30: Two-D array exercise
Implement a two-dimensional String array to
print the element at row 0 column 4
120 Marius Claassen, 2017
Lecture 31: Two-D array solution
public class Lecture31 {
public void printTwoDArray() {
String[][] countries = {
{“Argentina”, “Armenia”, “Aruba”, “Australia”, “Austria” },
{“Azerbaijan”, “Bahamas”, “Bahrain”, “Bangladesh”, “Barbados” },
{“Belarus”, “Belgium”, “Belize”, “Benin”, “Bhutan” } };
System.out.print(countries[0][4]);
}
}
121 Marius Claassen, 2017
TOPICS:
1. Introduction
2. Java basics
3. Arrays
4. Exceptions
5. Java classes
6. Conclusion
122 Marius Claassen, 2017
Lecture 32: Exceptions example
123 Marius Claassen, 2017
Lecture 32: Exceptions example
124 Marius Claassen, 2017
Exception
Lecture 32: Exceptions example
125 Marius Claassen, 2017
throw Exception
Lecture 32: Exceptions example
Exceptions problem statement:
Implement an IllegalArgumentException to be
thrown when a String named 'theDate' is not
10 characters
126 Marius Claassen, 2017
Lecture 32: Exceptions example
public class Lecture32 {
public static void main(String[] args) {
String theDate = “2017-04-0”;
if (theDate.length() != 10) {
throw new IllegalArgumentException(
“Date must be 10 characters long”);
}
}
} // Date must be 10 characters long
127 Marius Claassen, 2017
Lecture 32: Exceptions exercise
Implement an IllegalArgumentException to be
thrown when an int named ‘age’ is not a
positive number
128 Marius Claassen, 2017
Lecture 33: Exceptions solution
public class Lecture33 {
public static void main(String[] args) {
int age = -5;
if (age < 0) {
throw new IllegalArgumentException(
“Age must be a positive number”);
}
}
} // Age must be a positive number
129 Marius Claassen, 2017
TOPICS:
1. Introduction
2. Java basics
3. Arrays
4. Exceptions
5. Java classes
6. Conclusion
130 Marius Claassen, 2017
Lecture 34: Java classes example
Java class problem statement:
Create a Java class for this lecture
131 Marius Claassen, 2017
Lecture 34: Java classes example
public class Lecture34 {
}
132 Marius Claassen, 2017
Lecture 34: Java classes exercise
Create a Java class named ‘course’
133 Marius Claassen, 2017
Lecture 35: Java classes solution
public class Course {
}
134 Marius Claassen, 2017
Lecture 36: Java classes example
Java fields problem statement:
Declare a Java ‘field’ named
‘lectureNumber’, initialize it as 36 and print it
out
135 Marius Claassen, 2017
Lecture 36: Java fields example
public class Lecture36 {
public static void main(String[] args) {
int lectureNumber = 36; // field
System.out.print(lectureNumber);
}
} // 36
136 Marius Claassen, 2017
Lecture 36: Java fields exercise
Declare a Java boolean ‘field’ named
‘isLectureCompleted’, initialized as ‘true’
137 Marius Claassen, 2017
Lecture 37: Java fields solution
public class Lecture37 {
public static void main(String[] args) {
boolean isLectureCompleted = true; // field
System.out.print(isLectureCompleted);
}
} // true
138 Marius Claassen, 2017
Lecture 38: Java objects example
public class Course {
}
139 Marius Claassen, 2017
Course course1 = new Course(); // object
140 Marius Claassen, 2017
Lecture 38: Java objects example
Java objects problem statement:
Create an ‘object’ named ‘course1’ of
dataType ‘Course’ and print its datatype
141 Marius Claassen, 2017
Lecture 38: Java objects example
public class Lecture38 {
public static void main(String[] args) {
Course course1 = new Course(); // object
System.out.print(course1.getClass() );
}
} // class Course
142 Marius Claassen, 2017
public class Course {
}
143 Marius Claassen, 2017
Lecture 38: Java objects exercise
Create an object named ‘program1’ of
dataType ‘Program’
144 Marius Claassen, 2017
Lecture 39: Java objects solution
public class Lecture39 {
public static void main(String[] args) {
Program program1 = new Program(); // object
System.out.print(program1.getClass() );
}
} // class Program
145 Marius Claassen, 2017
public class Program {
}
146 Marius Claassen, 2017
Lecture 40: Java methods example
Java methods problem statement:
Declare a method named ‘printSkillLevel’
147 Marius Claassen, 2017
Lecture 40: Java methods example
public class Lecture40 {
public static void main(String[] args) {
Course course1 = new Course();
course1.printSkillLevel();
}
} // This course is for Java beginners
148 Marius Claassen, 2017
Lecture 40: Java methods example
public class Course {
public void printSkillLevel() { // method
System.out.print(“This course is for Java beginners”);
}
}
149 Marius Claassen, 2017
Lecture 40: Java methods exercise
Declare a method named
‘printNumberOfCodingExercises’
150 Marius Claassen, 2017
Lecture 41: Java methods solution
public class Lecture41 {
public static void main(String[] args) {
Course course1 = new Course();
course1.printNumberOfCodingExercises();
}
} // This course has 24 coding exercises
151 Marius Claassen, 2017
public class Course {
void printNumberOfCodingExercises() { // method
System.out.print(“This course has 24 coding exercises”);
}
}
152 Marius Claassen, 2017
Lecture 42: Parameters example
153 Marius Claassen, 2017
public void setJavaVersion(String version) {
}
Lecture 42: Parameters example
Parameters problem statement:
Implement a method, ‘setJavaVersion’ that
receives one parameter, a String named
‘version’
154 Marius Claassen, 2017
Lecture 42: Parameters example
public class Lecture42 {
public static void main(String[] args) {
Course course1 = new Course(); // object
course1.setJavaVersion(“Java 8”);
}
} // Java 8
155 Marius Claassen, 2017
public class Course {
public void setJavaVersion(String version) { // parameter
System.out.print(version);
}
}
156 Marius Claassen, 2017
Lecture 42: Parameters exercise
Implement a method, ‘setStudentLocations’
that receives one parameter, a String named
‘locations’
157 Marius Claassen, 2017
Lecture 43: Parameters solution
public class Lecture43 {
public static void main(String[] args) {
Course course1 = new Course(); // object
course1.setStudentLocations(“worldwide”);
}
} // worldwide
158 Marius Claassen, 2017
public class Course {
public void setStudentLocations(String locations) {
System.out.print(locations);
}
}
159 Marius Claassen, 2017
Lecture 44: Method overloading
public void printCoursePrice (String value) {
}
public void printCoursePrice(int number) {
}
160 Marius Claassen, 2017
Lecture 44: Method overloading
Method overloading problem statement:
Implement method overloading, with 2
methods named ‘printCoursePrice’. The one
method receives a String parameter and the
other an int parameter.
161 Marius Claassen, 2017
Lecture 44: Method overloading
public class Lecture44 {
public static void main(String[] args) {
Course course1 = new Course();
course1.printCoursePrice(“two hundred ”);
course1.printCoursePrice(200);
}
} // two hundred 200
162 Marius Claassen, 2017
public class Course {
public void printCoursePrice(String value) {
System.out.print(value); }
public void printCoursePrice( int number) {
System.out.print(number); }
}
163 Marius Claassen, 2017
Lecture 44: Overloading exercise
Implement method overloading, with 2
methods named ‘printNumberOfLectures’.
The one method receives an int parameter
and the other a String parameter.
164 Marius Claassen, 2017
Lecture 45: Overloading solution
public class Lecture45 {
public static void main(String[] args) {
Course course1 = new Course();
course1.printNumberOfLectures(54);
course1.printNumberOfLectures(“ fifty four”);
}
} // 54 fifty four
165 Marius Claassen, 2017
public class Course {
public void printNumberOfLectures(int number) {
System.out.print(number); }
public void printNumberOfLectures(String value) {
System.out.print(value); }
}
166 Marius Claassen, 2017
Lecture 46: Static modifier example
Static modifier problem statement:
Implement the ‘static’ modifier to declare a
String named ‘languageOfInstruction’.
Initialize and print it as ‘English’.
167 Marius Claassen, 2017
Lecture 46: Static modifier example
public class Lecture46 {
public static void main(String[] args) {
Course.languageOfInstruction = “English”; // Initialization
System.out.print(Course.languageOfInstruction );
}
} // English
168 Marius Claassen, 2017
class Course {
static String languageOfInstruction; // Declaration
}
169 Marius Claassen, 2017
Lecture 46: Static modifier exercise
Implement the ‘static’ modifier to declare an
int named ‘coursePrice’.
170 Marius Claassen, 2017
Lecture 47: Static modifier solution
public class Lecture47 {
public static void main(String[] args) {
Course.coursePrice = 200; // Initialization
System.out.print(Course.coursePrice);
}
} // 200
171 Marius Claassen, 2017
Lecture 47: Static modifier solution
class Course {
static int coursePrice; // Declaration
}
172 Marius Claassen, 2017
Lecture 48: Anonymous classes
Anonymous classes problem statement:
Implement an ‘anonymous’ class by
overriding the method named
‘getCourseName’
173 Marius Claassen, 2017
Lecture 48: Anonymous classes
public class Lecture48 {
public static void main(String[] args) {
Course course1 = new Course() {
@Override public void getCourseName() {
System.out.print(“Java 8 for Complete Beginners”); }
} ;
course1.getCourseName();
}
} // Java 8 for Complete Beginners
174 Marius Claassen, 2017
Lecture 48: Anonymous classes
public class Course {
public void getCourseName() {
System.out.print(“Java for all”);
}
}
175 Marius Claassen, 2017
Lecture 48: Anonymous classes
Implement an ‘anonymous’ class by
overriding the method named ‘isLive’
176 Marius Claassen, 2017
Lecture 49: Anonymous classes
public class Lecture49 {
public static void main(String[] args) {
Course course1 = new Course() {
@Override public void isLive() {
System.out.print(“Java 8 for Complete Beginners is live”); }
} ;
course1.isLive();
}
} // Java 8 for Complete Beginners is live
177 Marius Claassen, 2017
Lecture 49: Anonymous classes
public class Course {
public void isLive() {
System.out.print(“The course is live”);
}
}
178 Marius Claassen, 2017
Lecture 50: Inheritance example
Inheritance problem statement:
Implement ‘inheritance’ with the child class
named ‘JavaCourse’.
179 Marius Claassen, 2017
Lecture 50: Inheritance example
public class Lecture50 {
public static void main(String[] args) {
Course course1 = new Course(); // parent object
course1.learn();
JavaCourse javaCourse1 = new JavaCourse(); // child object
javaCourse1.learn();
}
} // Learning in general
// Studying Java
180 Marius Claassen, 2017
public class Course {
public void learn() {
System.out.print(“Learning in generaln”);
}
}
181 Marius Claassen, 2017
public class JavaCourse extends Course { // Inheritance
@Override public void learn() {
System.out.print(“Studying Java”);
}
}
182 Marius Claassen, 2017
Lecture 50: Inheritance exercise
Implement ‘inheritance’ with the child class
named ‘Programming’
183 Marius Claassen, 2017
Lecture 51: Inheritance solution
public class Lecture51 {
public static void main(String[] args) {
Software software1 = new Software(); // parent object
software1.solveProblems();
Programming programming1 = new Programming(); // child object
programming1.solveProblems();
}
} // General software solutions Programming solutions
184 Marius Claassen, 2017
public class Software {
public void solveProblems() {
System.out.print(“Software solutions ”);
}
}
185 Marius Claassen, 2017
public class Programming extends Software {
@Override public void solveProblems() {
System.out.print(“Programming solutions”);
}
}
186 Marius Claassen, 2017
Lecture 52: Polymorphism example
Polymorphism problem statement:
Implement ‘polymorphism’ by creating a child
object with a parent class as dataType
187 Marius Claassen, 2017
Lecture 52: Polymorphism example
public class Lecture52 {
public static void main(String[] args) {
Programming programming1 = new Programming(); // parent object
programming1.printDesription();
Programming programming2 = new Java(); // child object
programming2.printDescription();
}
} // Programming is writing software
// Java is object-oriented
188 Marius Claassen, 2017
public class Programming {
public void printDescription() {
System.out.print(“Programming is writing softwaren”);
}
}
189 Marius Claassen, 2017
public class Java extends Programming {
@Override public void printDescription() {
System.out.print(“Java is object-oriented”);
}
}
190 Marius Claassen, 2017
Lecture 52: Polymorphism exercise
Implement ‘polymorphism’ by creating a child
object, ‘coding2’ with a parent class,
‘Coding’ as dataType
191 Marius Claassen, 2017
Lecture 53: Polymorphism solution
public class Lecture53 {
public static void main(String[] args) {
Coding coding2 = new Java8(); // child object
coding2.printDesription();
}
} // Java 8 codes functional style
192 Marius Claassen, 2017
public class Coding {
public void printDescription() {
}
}
193 Marius Claassen, 2017
public class Java8 extends Coding {
@Override public void printDescription() {
System.out.print(“Java 8 codes functional style”);
}
}
194 Marius Claassen, 2017
TOPICS:
1. Introduction
2. Java basics
3. Arrays
4. Exceptions
5. Java classes
6. Conclusion
195 Marius Claassen, 2017
Lecture 54: Project 1
MathIQ.java
Write a program that asks the user to enter
the numbers, 8 and 2. The program must
then perform three calculations and print out
as answer the three values as follows:
‘16106’.
Example: 8 + 2 = 16106
196 Marius Claassen, 2017
Lecture 54: Project 2
BMI.java
Write a program that asks the user for their
‘weight’ and ‘height’. The program must then
calculate the user’s body mass index (BMI).
Based on this BMI the program must print out
if the user is ‘underweight’, ‘normal weight’,
or ‘obese’.
197 Marius Claassen, 2017
Lecture 54: Project 3
CompanyX.java
Write a program for CompanyX to calculate how
much to pay the company's hourly workers. The
national Department of Labour requires that
workers be paid 1.5 times for any hours more than
40 that they work in a week. Furthermore, it is a
legal requirement that hourly workers be paid a
minimum of $10.00 per hour. CompanyX requires
that workers should work for a maximum of 50
hours in a week.
198 Marius Claassen, 2017
Lecture 54: Project 4
FizzBuzz.java
Write a method that prints all numbers between 1
and n, replacing multiples of 3 with the String
‘Fizz’, multiples of 5 with ‘Buzz’, and multiples of
15 with ‘FizzBuzz’.
199 Marius Claassen, 2017
Email me mariusclaassen@gmail.com for details
on how to buy this course.
200 Marius Claassen, 2017

More Related Content

Recently uploaded

Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZTE
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and usesDevarapalliHaritha
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2RajaP95
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 

Recently uploaded (20)

★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and uses
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Java 8 for complete beginners programming course

  • 1. Java 8 for Complete Beginners Master the basics of programming
  • 2. Learn programming the easy way, by using the world’s most popular language to: • Discover anyone can code in Java • Write your own programs • Be in demand world-wide 2 Marius Claassen, 2017
  • 3. About me Marius Claassen, Java Developer and Teacher I am a self-taught java developer. Having been a teacher for many years, I am now working full-time as an independent software instructor, making video tutorials. At the time of making these Java tutorials, I am living in South Africa. 3 Marius Claassen, 2017
  • 4. Email me mariusclaassen@gmail.com for details on how to buy this course. 4 Marius Claassen, 2017
  • 5. Benefits • Read Java code • Develop basic Java applications • Structure high quality, working code • Devise solutions when given a problem statement 5 Marius Claassen, 2017
  • 6. Major components 1. Introduction 2. Java basics 3. Arrays 4. Exceptions 5. Java classes 6. Conclusion 6 Marius Claassen, 2017
  • 7. Ideal student Complete beginner who wants to learn programming by: • watching live coding • doing coding exercises • checking answers against solutions 7 Marius Claassen, 2017
  • 8. Enrolment This course is now open for enrolment 8 Marius Claassen, 2017
  • 9. TOPICS: 1. Introduction 2. Java basics 3. Arrays 4. Exceptions 5. Java classes 6. Conclusion 9 Marius Claassen, 2017
  • 10. Lecture 2: Java overview General-purpose programming language 10 Marius Claassen, 2017
  • 11. Lecture 2: Java overview • Object-oriented 11 Marius Claassen, 2017
  • 12. • Object-oriented Person Dog Internet website 12 Marius Claassen, 2017
  • 13. • Architecture neutral 13 Marius Claassen, 2017
  • 14. • Architecture neutral Windows Apple Linux 14 Marius Claassen, 2017
  • 15. • Secure 15 Marius Claassen, 2017
  • 16. Program development process Compiler Java VM HelloWorld.java HelloWorld.class Hello, world object 13 16 Marius Claassen, 2017
  • 17. Java’s popularity object 13 17 Marius Claassen, 2017
  • 18.
  • 19.
  • 20.
  • 21. Lecture 3: Development tools • JDK (SE 8) http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html • IDE (IntelliJ IDEA) https://www.jetbrains.com/idea/download/#section=windows • Internet browser (Google Chrome) 21 Marius Claassen, 2017
  • 43. TOPICS: 1. Introduction 2. Java basics 3. Arrays 4. Exceptions 5. Java classes 6. Conclusion 43 Marius Claassen, 2017
  • 44. Lecture 4: Hello world example Hello world problem statement: Print ‘hello world’ 44 Marius Claassen, 2017
  • 45. Lecture 4: Hello world example public class Lecture4 { public static void main(String[] args) { System.out.print(“hello world”); } } // hello world 45 Marius Claassen, 2017
  • 46. Lecture 4: First coding exercise Replace the comment with a statement to print the name, ‘Adam’. 46 Marius Claassen, 2017
  • 47. Lecture 5: First exercise solution public class Lecture5 { public void printAdam() { System.out.print(“Adam”); } } 47 Marius Claassen, 2017
  • 48. Lecture 6: Primitives declaration dataType storageName; Declaration 48 Marius Claassen, 2017
  • 49. Lecture 6: Primitives declaration int intValue; double doubleValue; char charValue; boolean booleanValue; 00.0 F ‘0’ 49 Marius Claassen, 2017 00
  • 50. Lecture 6: Primitives • byte, short, int, long • float, double • boolean • char 50 Marius Claassen, 2017
  • 51. Lecture 6: Declaration example Declaration problem statement: Declare Java’s 8 primitive data types 51 Marius Claassen, 2017
  • 52. Lecture 6: Declaration example public class Lecture6 { public static void main(String[] args) { int intValue; // Declaration } } 52 Marius Claassen, 2017
  • 53. Lecture 6: Declaration exercise Replace the comment with a statement to declare a ‘char’ data type, named ‘letterY’. 53 Marius Claassen, 2017
  • 54. Lecture 7: Primitives solution public class Lecture7 { public void declareLetterY() { char letterY; // Declaration } } 54 Marius Claassen, 2017
  • 55. Lecture 8: Primitives initialization dataType storageName; // Declaration storageName = value; // Initialization dataType storageName = value; // Declaration/Initialization 55 Marius Claassen, 2017
  • 56. int intValue = 900; // Initialization char charValue = ‘a’; // Initialization 56 Marius Claassen, 2017 900 ‘a’
  • 57. Lecture 8: Initialization example Initialization problem statement: Initialize an int data type named ‘intValue’ with the number 900. 57 Marius Claassen, 2017
  • 58. Lecture 8: Initialization example public class Lecture8 { public static void main(String[] args) { int intValue = 900; // Declare and Initialize } } 58 Marius Claassen, 2017
  • 59. Lecture 8: Initialization exercise Initialize a char data type, named ‘letterY’ with the value, ‘Y’. 59 Marius Claassen, 2017
  • 60. Lecture 9: Initialization solution public class Lecture9 { public void setLetterY() { char letterY = ‘Y’; // Declare and Initialize } } 60 Marius Claassen, 2017
  • 61. Lecture 10: Operators example Operators problem statement: Assign ‘11 * 18’ to a ‘short’ data type named ‘answer1’. 61 Marius Claassen, 2017
  • 62. Lecture 10: Operators example public class Lecture10 { public static void main(String[] args) { short answer1 = 11 * 18; } } 62 Marius Claassen, 2017
  • 63. Lecture 10: Java operators • short answer1 = 11 * 18; // Multiply • int answer2 = 15 % 4; // Remainder • double answer3 = 12.0 + 9.0; // Add • boolean answer4 = 36 < 35; // Less than 63 Marius Claassen, 2017
  • 64. Lecture 10: Operators exercise Assign ‘40 – 13’ to a ‘byte’ data type named ‘answer5’ 64 Marius Claassen, 2017
  • 65. Lecture 11: Java operators solution public class Lecture11 { public void setAnswer5() { byte answer5 = 40 - 13; } } 65 Marius Claassen, 2017
  • 66. Lecture 12: Reference data types 700 66 Marius Claassen, 2017 mySignOff “Keep coding” String mySignOff = “Keep coding”; int myNumber = 700;
  • 67. Lecture 12: References example References problem statement: Declare a String named, ‘mySignOff’ initialized as ‘Keep coding’ 67 Marius Claassen, 2017
  • 68. Lecture 12: References example public class Lecture12 { public static void main(String[] args) { String mySignOff = “Keep coding”; } } 68 Marius Claassen, 2017
  • 69. Lecture 12: References exercise Declare a String named, ‘words’ initialized as, ‘In the beginning’. 69 Marius Claassen, 2017
  • 70. Lecture 13: References solution public class Lecture13 { public void setWords() { String words = “In the beginning”; } } 70 Marius Claassen, 2017
  • 71. Lecture 14: Scanner class example Scanner class problem statement: Write code to have Java ask for your name 71 Marius Claassen, 2017
  • 72. Lecture 14: Scanner class example public class Lecture14 { public static void main(String[] args) { System.out.print(“What is your name? ”); Scanner scanner1 = new Scanner(System.in); String name = scanner1.next(); System.out.print(“Your name is ” + name); } } 72 Marius Claassen, 2017
  • 73. Lecture 14: Scanner class exercise Declare and initialize a String named ‘language’ as ‘scanner1.next()’ 73 Marius Claassen, 2017
  • 74. Lecture 15: Scanner class solution public class Lecture15 { public String getLanguage() { System.out.print(“Which programming language is the most widely used? ”); Scanner scanner1 = new Scanner(System.in); String language = scanner1.next(); return language; } } 74 Marius Claassen, 2017
  • 75. Lecture 16: Conditionals &&, || ‘J’ 75 Marius Claassen, 2017 char charJ = ‘J’; char charK = ‘K’; // Declare, initialize // Declare, initialize‘K’
  • 76. Lecture 16: Conditionals &&, || ‘J’ 76 Marius Claassen, 2017 char charJ = ‘J’; char charK = ‘K’ if ( (charJ == ‘J’) && (charK == ‘K’) ) { ‘K’ System.out.print( “charJ is J and charK is K”); }
  • 77. Lecture 16: Conditionals &&, || Conditional operators problem statement: Implement the ‘&&’ operator where charJ = ‘J’ and charK = ‘K’ and print ‘charJ is J AND charK is K’. 77 Marius Claassen, 2017
  • 78. Lecture 16: Conditionals &&, || public class Lecture16 { public static void main(String[] args) { char charJ = ‘J’; char charK = ‘K’; if ( (charJ == ‘J’ ) && (charK == ‘K’) ) { System.out.print(“ charJ is ‘J’ AND charK is ‘K’ ” ); } } } 78 Marius Claassen, 2017
  • 79. Lecture 16: Conditionals exercise Implement the ‘||’ operator with ‘evenNumber’ as 8 or ‘oddNumber’ as 12 79 Marius Claassen, 2017
  • 80. Lecture 17: Conditionals solution public class Lecture17 { public static void main(String[] args) { int evenNumber = 8; int oddNumber = 9; if ( (evenNumber == 8) || (oddNumber == 12) ) { System.out.print(“evenNumber is 8 OR oddNumber is 12”); } } }80 Marius Claassen, 2017
  • 81. Lecture 18: If-then example 81 Marius Claassen, 2017 21 and 21 “Equal” if num6 is equal to num7 then print they are equal
  • 82. Lecture 18: If-then-else example 82 Marius Claassen, 2017 “Not equal” 56 and 65 “Equal”
  • 83. Lecture 18: If-then-else example 83 Marius Claassen, 2017 “Not equal” 56 and 65 if num1 is equal to num2 then print they are equal, else print they are not equal
  • 84. Lecture 18: If-then-else example If-then-else problem statement: Implement ‘if-then-else’ where num1 = 56 and num2 = 65, and print whether they are equal or not 84 Marius Claassen, 2017
  • 85. Lecture 18: If-then-else example public class Lecture18 { public static void main(String[] args) { int num1 = 56; int num2 = 65; if (num1 == num2) { System.out.print(“56 is equal to 65”); } else { System.out.print(“56 is not equal to 65”); } } } // 56 is not equal to 65 85 Marius Claassen, 2017
  • 86. Lecture 18: If-then-else exercise Implement ‘if-then-else’ with testScore >= 60 86 Marius Claassen, 2017
  • 87. Lecture 19: If-then-else solution public class Lecture19 { public void printIfThenElse() { int testScore = 74; String result = “undefined”; if (testScore >= 60) { result = “pass”; } else { result = “fail”; } System.out.print(result); } } 87 Marius Claassen, 2017
  • 88. Lecture 20: Switch example Switch problem statement: Implement a ‘switch’ statement to print weekday 6 as ‘Friday’. 88 Marius Claassen, 2017
  • 89. Lecture 20: Switch example 89 Marius Claassen, 2017 1 2 3 4 5 6 7 “Friday” “Saturday” “Thursday” “Wednesday” “Tuesday” “Monday” “Sunday”
  • 90. Lecture 20: Switch example 90 Marius Claassen, 2017 1 2 3 4 5 6 7 “Friday”
  • 91. Lecture 20: Switch example String day = “6”; switch (day) { case “1” : System.out.print(“Sunday”); break; case “2” : System.out.print(“Monday”); break; case “3” : System.out.print(“Tuesday”); break; case “4” : System.out.print(“Wednesday”); break; case “5” : System.out.print(“Thursday”); break; case “6” : System.out.print(“Friday”); break; case “7” : System.out.print(“Saturday”); break; default: System.out.print(“Invalid weekday”); break; } // Friday 91 Marius Claassen, 2017
  • 92. Lecture 20: Switch exercise Implement a ‘switch’ statement to print calendar month 3 as ‘March’ 92 Marius Claassen, 2017
  • 93. Lecture 21: Switch solution String month = “3”; switch (month) { case “1” : System.out.print(“January”); break; case “2” : System.out.print(“February”); break; case “3” : System.out.print(“March”); break; case “4” : System.out.print(“April”); break; . . default: System.out.print(“Invalid month”); break; } 93 Marius Claassen, 2017
  • 94. Lecture 22: For loop example 94 Marius Claassen, 2017 Repeated action
  • 95. Lecture 22: For loop example 95 Marius Claassen, 2017 Stop condition
  • 96. Lecture 22: For loop example For loop problem statement: Implement a ‘for’ loop to print the five values 24 to 28. 96 Marius Claassen, 2017
  • 97. Lecture 22: For loop example public class Lecture22 { public static void main(String[] args) { for (int j = 24; j < 29; j++) { System.out.print( j + “ ”); } } } // 24 25 26 27 28 97 Marius Claassen, 2017
  • 98. Lecture 22: For loop exercise Implement a ‘for’ loop to print the three values 87 to 89 98 Marius Claassen, 2017
  • 99. Lecture 23: For loop solution public class Lecture23 { public void printForLoop() { for (int j = 87; j < 89; j++) { System.out.print( j + “ ”); } } } 99 Marius Claassen, 2017
  • 100. Lecture 24: While loop example While loop problem statement: Implement a ‘while’ loop to print the four values, divisible by 5, from 40 to 55. 100 Marius Claassen, 2017
  • 101. Lecture 24: While loop example public class Lecture24 { public static void main(String[] args) { int j = 40; while ( j <= 55) { System.out.print( j + “ ”); j = j + 5; } } } // 40 45 50 55 101 Marius Claassen, 2017
  • 102. Lecture 24: While loop exercise Implement a ‘while’ loop with the control condition <= 18 102 Marius Claassen, 2017
  • 103. Lecture 25: While loop solution public class Lecture25 { public void printWhileLoop() { int j = 9; while ( j <= 18) { System.out.print( j + “ ”); j = j + 3; } } } 103 Marius Claassen, 2017
  • 104. Lecture 26: Do-while loop example Do-while loop problem statement: Implement a ‘do-while’ loop to print the 3 uppercase letters ‘Q’ to ‘S’ 104 Marius Claassen, 2017
  • 105. Lecture 26: Do-while loop example public class Lecture26 { public static void main(String[] args) { char letter = ‘Q’; do { System.out.print(letter + “ ”); letter++; // Increment } while (letter <= ‘S’); } } // Q R S 105 Marius Claassen, 2017
  • 106. Lecture 26: Do-while exercise Implement a ‘do-while’ loop to print the 5 letters ‘a’ to ‘e’ in reverse order 106 Marius Claassen, 2017
  • 107. Lecture 27: Do-while loop solution public class Lecture27 { public void printDoWhileLoop() { char letter = ‘e’; do { System.out.print(letter + “ ”); letter--; // Decrement } while (letter >= ‘a’); } } 107 Marius Claassen, 2017
  • 108. TOPICS: 1. Introduction 2. Java basics 3. Arrays 4. Exceptions 5. Java classes 6. Conclusion 108 Marius Claassen, 2017
  • 109. Lecture 28: One-dimensional array 109 Marius Claassen, 2017
  • 110. Lecture 28: One-dimensional array 110 Marius Claassen, 2017
  • 111. Lecture 28: One-dimensional array 0 1 2 3 4 13.0 17.0 21.0 25.0 29.0 111 Marius Claassen, 2017 indices array length of 5 elements
  • 112. Lecture 28: One-dimensional array One-dimensional array problem statement: Implement a one-dimensional double array and print all the values using a ‘for’ loop 112 Marius Claassen, 2017
  • 113. Lecture 28: One-dimensional array public class Lecture28 { public static void main(String[] args) { double[ ] numbers = {13.0, 17.0, 21.0, 25.0, 29.0}; for (double number : numbers) { System.out.print(number + “ ”); } } } // 13.0, 17.0, 21.0, 25.0, 29.0113 Marius Claassen, 2017
  • 114. Lecture 28: One-D array exercise Implement a one-dimensional integer array named ‘values’, initialized with the elements 30, 31, 32 and 33 114 Marius Claassen, 2017
  • 115. Lecture 29: One-D array solution public class Lecture29 { public void printOneDArray() { int[ ] values = {30, 31, 32, 33}; for (int value : values) { System.out.print(value + “ ”); } } }115 Marius Claassen, 2017
  • 116. Lecture 30: Two-dimensional array 116 Marius Claassen, 2017
  • 117. Lecture 30: Two-D array example 0 1 2 3 4 alpha bravo charlie delta echo 0 foxtrot golf hotel india juliet 1 kilo lima mike november oscar 2 papa quebec romeo sierra tango 3 117 Marius Claassen, 2017 4 Rows 5 Columns
  • 118. Lecture 30: Two-D array example Two-dimensional array problem statement: Implement a two-dimensional String array to print the element at row 1 column 3 118 Marius Claassen, 2017
  • 119. Lecture 30: Two-D array example public class Lecture30 { public static void main(String[] args) { String[][] phoneticAlphabet = { {“alpha”, “bravo”, “charlie”, “delta”, “echo” }, {“foxtrot”, “golf”, “hotel”, “india”, “juliet” }, {“kilo”, “lima”, “mike”, “november”, “oscar” }, {“papa”, “quebec”, “romeo”, “sierra”, “tango” } }; System.out.print(phoneticAlphabet[1][3]); } } // india 119 Marius Claassen, 2017
  • 120. Lecture 30: Two-D array exercise Implement a two-dimensional String array to print the element at row 0 column 4 120 Marius Claassen, 2017
  • 121. Lecture 31: Two-D array solution public class Lecture31 { public void printTwoDArray() { String[][] countries = { {“Argentina”, “Armenia”, “Aruba”, “Australia”, “Austria” }, {“Azerbaijan”, “Bahamas”, “Bahrain”, “Bangladesh”, “Barbados” }, {“Belarus”, “Belgium”, “Belize”, “Benin”, “Bhutan” } }; System.out.print(countries[0][4]); } } 121 Marius Claassen, 2017
  • 122. TOPICS: 1. Introduction 2. Java basics 3. Arrays 4. Exceptions 5. Java classes 6. Conclusion 122 Marius Claassen, 2017
  • 123. Lecture 32: Exceptions example 123 Marius Claassen, 2017
  • 124. Lecture 32: Exceptions example 124 Marius Claassen, 2017 Exception
  • 125. Lecture 32: Exceptions example 125 Marius Claassen, 2017 throw Exception
  • 126. Lecture 32: Exceptions example Exceptions problem statement: Implement an IllegalArgumentException to be thrown when a String named 'theDate' is not 10 characters 126 Marius Claassen, 2017
  • 127. Lecture 32: Exceptions example public class Lecture32 { public static void main(String[] args) { String theDate = “2017-04-0”; if (theDate.length() != 10) { throw new IllegalArgumentException( “Date must be 10 characters long”); } } } // Date must be 10 characters long 127 Marius Claassen, 2017
  • 128. Lecture 32: Exceptions exercise Implement an IllegalArgumentException to be thrown when an int named ‘age’ is not a positive number 128 Marius Claassen, 2017
  • 129. Lecture 33: Exceptions solution public class Lecture33 { public static void main(String[] args) { int age = -5; if (age < 0) { throw new IllegalArgumentException( “Age must be a positive number”); } } } // Age must be a positive number 129 Marius Claassen, 2017
  • 130. TOPICS: 1. Introduction 2. Java basics 3. Arrays 4. Exceptions 5. Java classes 6. Conclusion 130 Marius Claassen, 2017
  • 131. Lecture 34: Java classes example Java class problem statement: Create a Java class for this lecture 131 Marius Claassen, 2017
  • 132. Lecture 34: Java classes example public class Lecture34 { } 132 Marius Claassen, 2017
  • 133. Lecture 34: Java classes exercise Create a Java class named ‘course’ 133 Marius Claassen, 2017
  • 134. Lecture 35: Java classes solution public class Course { } 134 Marius Claassen, 2017
  • 135. Lecture 36: Java classes example Java fields problem statement: Declare a Java ‘field’ named ‘lectureNumber’, initialize it as 36 and print it out 135 Marius Claassen, 2017
  • 136. Lecture 36: Java fields example public class Lecture36 { public static void main(String[] args) { int lectureNumber = 36; // field System.out.print(lectureNumber); } } // 36 136 Marius Claassen, 2017
  • 137. Lecture 36: Java fields exercise Declare a Java boolean ‘field’ named ‘isLectureCompleted’, initialized as ‘true’ 137 Marius Claassen, 2017
  • 138. Lecture 37: Java fields solution public class Lecture37 { public static void main(String[] args) { boolean isLectureCompleted = true; // field System.out.print(isLectureCompleted); } } // true 138 Marius Claassen, 2017
  • 139. Lecture 38: Java objects example public class Course { } 139 Marius Claassen, 2017
  • 140. Course course1 = new Course(); // object 140 Marius Claassen, 2017
  • 141. Lecture 38: Java objects example Java objects problem statement: Create an ‘object’ named ‘course1’ of dataType ‘Course’ and print its datatype 141 Marius Claassen, 2017
  • 142. Lecture 38: Java objects example public class Lecture38 { public static void main(String[] args) { Course course1 = new Course(); // object System.out.print(course1.getClass() ); } } // class Course 142 Marius Claassen, 2017
  • 143. public class Course { } 143 Marius Claassen, 2017
  • 144. Lecture 38: Java objects exercise Create an object named ‘program1’ of dataType ‘Program’ 144 Marius Claassen, 2017
  • 145. Lecture 39: Java objects solution public class Lecture39 { public static void main(String[] args) { Program program1 = new Program(); // object System.out.print(program1.getClass() ); } } // class Program 145 Marius Claassen, 2017
  • 146. public class Program { } 146 Marius Claassen, 2017
  • 147. Lecture 40: Java methods example Java methods problem statement: Declare a method named ‘printSkillLevel’ 147 Marius Claassen, 2017
  • 148. Lecture 40: Java methods example public class Lecture40 { public static void main(String[] args) { Course course1 = new Course(); course1.printSkillLevel(); } } // This course is for Java beginners 148 Marius Claassen, 2017
  • 149. Lecture 40: Java methods example public class Course { public void printSkillLevel() { // method System.out.print(“This course is for Java beginners”); } } 149 Marius Claassen, 2017
  • 150. Lecture 40: Java methods exercise Declare a method named ‘printNumberOfCodingExercises’ 150 Marius Claassen, 2017
  • 151. Lecture 41: Java methods solution public class Lecture41 { public static void main(String[] args) { Course course1 = new Course(); course1.printNumberOfCodingExercises(); } } // This course has 24 coding exercises 151 Marius Claassen, 2017
  • 152. public class Course { void printNumberOfCodingExercises() { // method System.out.print(“This course has 24 coding exercises”); } } 152 Marius Claassen, 2017
  • 153. Lecture 42: Parameters example 153 Marius Claassen, 2017 public void setJavaVersion(String version) { }
  • 154. Lecture 42: Parameters example Parameters problem statement: Implement a method, ‘setJavaVersion’ that receives one parameter, a String named ‘version’ 154 Marius Claassen, 2017
  • 155. Lecture 42: Parameters example public class Lecture42 { public static void main(String[] args) { Course course1 = new Course(); // object course1.setJavaVersion(“Java 8”); } } // Java 8 155 Marius Claassen, 2017
  • 156. public class Course { public void setJavaVersion(String version) { // parameter System.out.print(version); } } 156 Marius Claassen, 2017
  • 157. Lecture 42: Parameters exercise Implement a method, ‘setStudentLocations’ that receives one parameter, a String named ‘locations’ 157 Marius Claassen, 2017
  • 158. Lecture 43: Parameters solution public class Lecture43 { public static void main(String[] args) { Course course1 = new Course(); // object course1.setStudentLocations(“worldwide”); } } // worldwide 158 Marius Claassen, 2017
  • 159. public class Course { public void setStudentLocations(String locations) { System.out.print(locations); } } 159 Marius Claassen, 2017
  • 160. Lecture 44: Method overloading public void printCoursePrice (String value) { } public void printCoursePrice(int number) { } 160 Marius Claassen, 2017
  • 161. Lecture 44: Method overloading Method overloading problem statement: Implement method overloading, with 2 methods named ‘printCoursePrice’. The one method receives a String parameter and the other an int parameter. 161 Marius Claassen, 2017
  • 162. Lecture 44: Method overloading public class Lecture44 { public static void main(String[] args) { Course course1 = new Course(); course1.printCoursePrice(“two hundred ”); course1.printCoursePrice(200); } } // two hundred 200 162 Marius Claassen, 2017
  • 163. public class Course { public void printCoursePrice(String value) { System.out.print(value); } public void printCoursePrice( int number) { System.out.print(number); } } 163 Marius Claassen, 2017
  • 164. Lecture 44: Overloading exercise Implement method overloading, with 2 methods named ‘printNumberOfLectures’. The one method receives an int parameter and the other a String parameter. 164 Marius Claassen, 2017
  • 165. Lecture 45: Overloading solution public class Lecture45 { public static void main(String[] args) { Course course1 = new Course(); course1.printNumberOfLectures(54); course1.printNumberOfLectures(“ fifty four”); } } // 54 fifty four 165 Marius Claassen, 2017
  • 166. public class Course { public void printNumberOfLectures(int number) { System.out.print(number); } public void printNumberOfLectures(String value) { System.out.print(value); } } 166 Marius Claassen, 2017
  • 167. Lecture 46: Static modifier example Static modifier problem statement: Implement the ‘static’ modifier to declare a String named ‘languageOfInstruction’. Initialize and print it as ‘English’. 167 Marius Claassen, 2017
  • 168. Lecture 46: Static modifier example public class Lecture46 { public static void main(String[] args) { Course.languageOfInstruction = “English”; // Initialization System.out.print(Course.languageOfInstruction ); } } // English 168 Marius Claassen, 2017
  • 169. class Course { static String languageOfInstruction; // Declaration } 169 Marius Claassen, 2017
  • 170. Lecture 46: Static modifier exercise Implement the ‘static’ modifier to declare an int named ‘coursePrice’. 170 Marius Claassen, 2017
  • 171. Lecture 47: Static modifier solution public class Lecture47 { public static void main(String[] args) { Course.coursePrice = 200; // Initialization System.out.print(Course.coursePrice); } } // 200 171 Marius Claassen, 2017
  • 172. Lecture 47: Static modifier solution class Course { static int coursePrice; // Declaration } 172 Marius Claassen, 2017
  • 173. Lecture 48: Anonymous classes Anonymous classes problem statement: Implement an ‘anonymous’ class by overriding the method named ‘getCourseName’ 173 Marius Claassen, 2017
  • 174. Lecture 48: Anonymous classes public class Lecture48 { public static void main(String[] args) { Course course1 = new Course() { @Override public void getCourseName() { System.out.print(“Java 8 for Complete Beginners”); } } ; course1.getCourseName(); } } // Java 8 for Complete Beginners 174 Marius Claassen, 2017
  • 175. Lecture 48: Anonymous classes public class Course { public void getCourseName() { System.out.print(“Java for all”); } } 175 Marius Claassen, 2017
  • 176. Lecture 48: Anonymous classes Implement an ‘anonymous’ class by overriding the method named ‘isLive’ 176 Marius Claassen, 2017
  • 177. Lecture 49: Anonymous classes public class Lecture49 { public static void main(String[] args) { Course course1 = new Course() { @Override public void isLive() { System.out.print(“Java 8 for Complete Beginners is live”); } } ; course1.isLive(); } } // Java 8 for Complete Beginners is live 177 Marius Claassen, 2017
  • 178. Lecture 49: Anonymous classes public class Course { public void isLive() { System.out.print(“The course is live”); } } 178 Marius Claassen, 2017
  • 179. Lecture 50: Inheritance example Inheritance problem statement: Implement ‘inheritance’ with the child class named ‘JavaCourse’. 179 Marius Claassen, 2017
  • 180. Lecture 50: Inheritance example public class Lecture50 { public static void main(String[] args) { Course course1 = new Course(); // parent object course1.learn(); JavaCourse javaCourse1 = new JavaCourse(); // child object javaCourse1.learn(); } } // Learning in general // Studying Java 180 Marius Claassen, 2017
  • 181. public class Course { public void learn() { System.out.print(“Learning in generaln”); } } 181 Marius Claassen, 2017
  • 182. public class JavaCourse extends Course { // Inheritance @Override public void learn() { System.out.print(“Studying Java”); } } 182 Marius Claassen, 2017
  • 183. Lecture 50: Inheritance exercise Implement ‘inheritance’ with the child class named ‘Programming’ 183 Marius Claassen, 2017
  • 184. Lecture 51: Inheritance solution public class Lecture51 { public static void main(String[] args) { Software software1 = new Software(); // parent object software1.solveProblems(); Programming programming1 = new Programming(); // child object programming1.solveProblems(); } } // General software solutions Programming solutions 184 Marius Claassen, 2017
  • 185. public class Software { public void solveProblems() { System.out.print(“Software solutions ”); } } 185 Marius Claassen, 2017
  • 186. public class Programming extends Software { @Override public void solveProblems() { System.out.print(“Programming solutions”); } } 186 Marius Claassen, 2017
  • 187. Lecture 52: Polymorphism example Polymorphism problem statement: Implement ‘polymorphism’ by creating a child object with a parent class as dataType 187 Marius Claassen, 2017
  • 188. Lecture 52: Polymorphism example public class Lecture52 { public static void main(String[] args) { Programming programming1 = new Programming(); // parent object programming1.printDesription(); Programming programming2 = new Java(); // child object programming2.printDescription(); } } // Programming is writing software // Java is object-oriented 188 Marius Claassen, 2017
  • 189. public class Programming { public void printDescription() { System.out.print(“Programming is writing softwaren”); } } 189 Marius Claassen, 2017
  • 190. public class Java extends Programming { @Override public void printDescription() { System.out.print(“Java is object-oriented”); } } 190 Marius Claassen, 2017
  • 191. Lecture 52: Polymorphism exercise Implement ‘polymorphism’ by creating a child object, ‘coding2’ with a parent class, ‘Coding’ as dataType 191 Marius Claassen, 2017
  • 192. Lecture 53: Polymorphism solution public class Lecture53 { public static void main(String[] args) { Coding coding2 = new Java8(); // child object coding2.printDesription(); } } // Java 8 codes functional style 192 Marius Claassen, 2017
  • 193. public class Coding { public void printDescription() { } } 193 Marius Claassen, 2017
  • 194. public class Java8 extends Coding { @Override public void printDescription() { System.out.print(“Java 8 codes functional style”); } } 194 Marius Claassen, 2017
  • 195. TOPICS: 1. Introduction 2. Java basics 3. Arrays 4. Exceptions 5. Java classes 6. Conclusion 195 Marius Claassen, 2017
  • 196. Lecture 54: Project 1 MathIQ.java Write a program that asks the user to enter the numbers, 8 and 2. The program must then perform three calculations and print out as answer the three values as follows: ‘16106’. Example: 8 + 2 = 16106 196 Marius Claassen, 2017
  • 197. Lecture 54: Project 2 BMI.java Write a program that asks the user for their ‘weight’ and ‘height’. The program must then calculate the user’s body mass index (BMI). Based on this BMI the program must print out if the user is ‘underweight’, ‘normal weight’, or ‘obese’. 197 Marius Claassen, 2017
  • 198. Lecture 54: Project 3 CompanyX.java Write a program for CompanyX to calculate how much to pay the company's hourly workers. The national Department of Labour requires that workers be paid 1.5 times for any hours more than 40 that they work in a week. Furthermore, it is a legal requirement that hourly workers be paid a minimum of $10.00 per hour. CompanyX requires that workers should work for a maximum of 50 hours in a week. 198 Marius Claassen, 2017
  • 199. Lecture 54: Project 4 FizzBuzz.java Write a method that prints all numbers between 1 and n, replacing multiples of 3 with the String ‘Fizz’, multiples of 5 with ‘Buzz’, and multiples of 15 with ‘FizzBuzz’. 199 Marius Claassen, 2017
  • 200. Email me mariusclaassen@gmail.com for details on how to buy this course. 200 Marius Claassen, 2017