Java Programming Guide: 250 Steps
Java Programming Guide: 250 Steps
Learn Java
ra mm i n g i n
Prog
250 Steps
[Link] 1/203
9/17/2018 in28Minutes | (0/25)
Table of Contents
1. Congratulations
2. About in28Minutes
3. Getting Started
11. Loops
[Link] 2/203
9/17/2018 in28Minutes | (0/25)
12. Reference Types
15. Collections
16. Generics
17. FunctionalProgramming
20. Files
[Link] 3/203
9/17/2018 in28Minutes | (0/25)
Congratulations
You have made a great choice in learning with in28Minutes. You
are joining 100,000+ Learners learning everyday with us.
on APIs, Web Services and Microservices with Spring, Spring Boot and
Spring Cloud.
[Link] 4/203
9/17/2018 in28Minutes | (0/25)
About in28Minutes
You need to get insight into the in28Minutes world to answer that.
What do we love?
[Link] 5/203
9/17/2018 in28Minutes | (0/25)
Getting Started
Recommended Versions
Installation
Github : [Link]
PDF : [Link]
Troubleshooting
A 50 page troubleshooting guide with more than 200 Errors and Questions
answered
[Link] 6/203
9/17/2018 in28Minutes | (0/25)
Introduction To Java
Programming With JShell
Steps
Step 00 - Getting Started with Programming
Step 01 - Introduction to Multiplication Table challenge
Step 02 - Launch JShell
Step 03 - Break Down Multiplication Table Challenge
Step 04 - Java Expression - An Introduction
Step 05 - Java Expression - Exercises
Step 06 - Java Expression - Puzzles
Step 07 - Printing output to console with Java
Step 08 - Printing output to console with Java - Exercise Statements
Step 09 - Printing output to console with Java - Exercise Solutions
Step 10 - Printing output to console with Java - Puzzles
Step 11 - Advanced Printing output to console with Java
Step 12 - Advanced Printing output to console with Java - Exercises and Puzzles
Step 13 - Introduction to Variables in Java
Step 14 - Introduction to Variables in Java - Exercises and Puzzles
Step 15 - 4 Important Things to Know about Variables in Java
Step 16 - How are variables stored in memory?
Step 17 - How to name a variable?
Step 18 - Understanding Primitive Variable Types in Java
Step 19 - Understanding Primitive Variable Types in Java - Choosing a Type
Step 20 - Java Assignment Operator
Step 21 - Java Assignment Operator - Puzzles on Increment, Decrement and
Compound Assignment
[Link] 7/203
9/17/2018 in28Minutes | (0/25)
Step 24 - Java Conditionals and If Statement - Exercise Statements
Step 25 - Java Conditionals and If Statement - Exercise Solutions
Step 26 - Java Conditionals and If Statement - Puzzles
Step 27 - Java For Loop to Print Multiplication Table - Introduction
Step 28 - Java For Loop to Print Multiplication Table - Exercise Statements
Step 29 - Java For Loop to Print Multiplication Table - Exercise Solutions
Step 30 - Java For Loop to Print Multiplication Table - Puzzles
Step 31 - Programming Tips : JShell - Shortcuts, Multiple Lines and Variables TODO
Move up
Step 32 - Getting Started with Programming - Revise all Terminology
Exercises
Expressions
Print the following output by passing 4 values 5, ,6, 7 and sum of the numbers: 5
[Link] 8/203
9/17/2018 in28Minutes | (0/25)
+ 6 + 7 = 18
Variables
If Statement
For Loop
Repeat the entire process at arriving at the Multiplication Table Print problem, now
for the number 7 . Start with fresh JShell session, if you're still using an existing
one for quite some time (Rinse, and repeat!).
Use the final solution to print Multiplication Tables for 6 and 10 .
Print the integers from 1 to 10 .
Print the integers from 10 to 1 .
Print the squares of the integers from 1 to 10 .
Print the squares of the first 10 even integers.
Print the squares of the first 10 odd integers.
Code Snippets
3*4
[Link](3*4)
[Link] 9/203
9/17/2018 in28Minutes | (0/25)
[Link]("5 * 2 = 10")
3.0/2
[Link]("5 * 2")
[Link](5 * 2)
[Link]("Hello World")
[Link](5*3)
[Link]("5 * 3")
[Link](5*3) [Link]("5 * 1 = 5")
[Link]("5 * 2 = 5")
[Link]("5 * 3 = 5")
[Link]("24 * 60 * 60")
[Link](24 * 60 * 60)
[Link]("Hello World")
[Link]("Hello World")
[Link](24 * 60 * 60)
[Link]("Hello World")
[Link]("HelloWorld")
[Link]("hello world")
[Link]("hello \"world")
[Link]("hello \"world")
[Link]("hello n world")
[Link]("hello \n world")
[Link]("hello \nworld")
[Link]("hello\nworld")
[Link]("hello\tworld")
[Link]("hello \\ world")
[Link]("hello \\\\ world")
[Link]()
[Link]("hello \n world")
[Link](23,45)
[Link](23,4)
[Link](23,4)
[Link]("5 * 2 = 5")
[Link]("5 * 2 = 10")
5*2
[Link] 10/203
9/17/2018 in28Minutes | (0/25)
[Link]("5 * 2 = 10")
[Link]("5 * 2 = 10").println()
[Link]("5 * 2 = 10 %d", 5*2).println()
[Link]("5 * 2 = %d", 5*2).println()
[Link]("%d %d %d", 5, 7, 5 * 7).println()
[Link]("%d * %d = %d", 5, 7, 5 * 7).println()
[Link]("%d + %d + %d = %d", 5, 6, 7, 5 + 6 +
7).println()
[Link]("%d + %d + %d = %d", 5, 6, 7).println()
[Link]("%d + %d + %d", 5, 6, 7).println()
[Link]("%d + %d + %d", 5, 6).println()
[Link]("%d + %d + %d", 5, 6, 7, 8).println()
[Link]("Print %s", "Testing").println()
[Link]("%d + %d + %d", 5.5, 6.5, 7.5).println()
[Link]("%f + %f + %f", 5.5, 6.5, 7.5).println()
[Link]("5 * 2 = 10")
[Link]("%d * %d = %d", 5, 2, 5 * 2).println()
[Link]("5 * 2 = 10")
[Link]("%d * %d = %d", 5, 2, 5 * 2).println()
[Link]("%d * %d = %d", 5, 1, 5 * 1).println()
[Link]("%d * %d = %d", 5, 2, 5 * 2).println()
[Link]("%d * %d = %d", 5, 3, 5 * 3).println()
[Link]("%d * %d = %d", 5, 4, 5 * 4).println()
number = 11
number
number = 12
number
number2 = 100
[Link]("%d * %d = %d", 5, 4, 5 * 4).println()
[Link]("%d * %d = %d", 5, i, 5 * i).println()
i
5 * i
i = 2
[Link]("%d * %d = %d", 5, i, 5 * i).println()
i = 3
[Link]("%d * %d = %d", 5, i, 5 * i).println()
[Link] 11/203
9/17/2018 in28Minutes | (0/25)
i = 10
[Link]("%d * %d = %d", 5, i, 5 * i).println()
[Link]("a + b + c = a+b+c").println()
[Link]("%d + %d + %d = %d", a, b, c
,a+b+c).println()
a = 50 [Link]("%d + %d + %d = %d", a, b, c
,a+b+c).println()
b = 60
[Link]("%d + %d + %d = %d", a, b, c
,a+b+c).println()
int newVariable;
newVariable
int undeclaredVariable;
undeclaredVariable
5 * undeclaredVariable
a = 100
a = c
int noOfGoals;
int NoOfGoals;
int score;
short s;
float f = 4.0f;
float f2 = 4.5f;
double dbl = 4.5;
i = j
i
j
i = j
i = j * 2
i = i * 2
i = i + i
i = i - i
i = i - 1
i++
i
[Link] 12/203
9/17/2018 in28Minutes | (0/25)
i++
i
i--
number = number + 1
number++ number--
++number
--number
number--
number
i = i + 2
i += 2
i -= 1
i *= 5
i
i /= 4
i %= 2
;
long l = 6_000_000_000l;
short numberOfGoals;
numberOfGoals++
numberOfGoals
numberOfGoals++
numberOfGoals
long populationOfTheWorld;
double average;
char ch = 'A';
ch = 'B'
char grade = 'C';
grade = 'A'
grade
boolean isEven;
isEven = true
boolean isPrime;
boolean isItRainingToday;
boolean areYouEnjoyingTheCourse;
[Link] 13/203
9/17/2018 in28Minutes | (0/25)
areYouEnjoyingTheCourse = true
[Link]("%d * %d = %d", 5, i, 5*i);
[Link]("%d * %d = %d", 5, i, 5*i).println()
[Link]("%d * %d = %d", 5, i, 5*i).println()
[Link]("%d * %d = %d", 5, i, 5*i).println()
i = 7
[Link]("%d * %d = %d", 5, i, 5*i).println()
i = 10
i < 5
i > 5
i <= 5
i <= 10
i >= 10
[Link]("i is less than 5");
i
if (i<5)
[Link]("i is less than 5");
i
i = 4
if (i<5)
[Link]("i is less than 5");
int number1 = 5;
int number2 = 7;
if (number2>number1)
[Link]("number2 is greater than number1");
number2 = 3
if (number2>number1)
[Link]("number2 is greater than number1");
int a = 1;
int b = 2;
int c = 3;
int d = 1;
if(a+b > c +d)
[Link]("a+b is greater than c+d");
a = 6
if(a+b > c +d)
[Link] 14/203
9/17/2018 in28Minutes | (0/25)
if(i==5)
[Link]("i is odd");
[Link]("i is prime");
if(i==5) {
[Link]("i is odd");
[Link]("i is prime");
}
if(i==5) {
[Link]("i is prime");
}
[Link]("%d * %d = %d", 5, i, 5*i).println()
[Link]("%d * %d = %d", 5, i, 5*i).println()
i = i + 1
[Link]("%d * %d = %d", 5, i, 5*i).println()
i = i + 1
[Link]("%d * %d = %d", 5, i, 5*i).println()
for( i =1; i<=10; i++) {
[Link]("%d * %d = %d", 5, i, 5*i).println();
}
for( i =1; i<=10; i++) {
[Link]("%d * %d = %d", 6, i, 6*i).println();
}
for( i =1; i<=10; i++) {
[Link]("%d * %d = %d", 7, i, 7*i).println();
}
int table = 7;
for( i =1; i<=10; i++) {
[Link]("%d * %d = %d", table, i,
table*i).println();
}
table = 8
for( i =1; i<=10; i++) {
[Link]("%d * %d = %d", table, i,
table*i).println();
}
table = 8
[Link] 16/203
9/17/2018 in28Minutes | (0/25)
[Link] 18/203
9/17/2018 in28Minutes | (0/25)
Introduction To Methods -
Multiplication Table
Steps
Step 00 - Section 02 - Methods - An Introduction
Step 01 - Your First Java Method - Hello World Twice and Exercise Statements
Step 02 - Introduction to Java Methods - Exercises and Puzzles
Step 03 - Programming Tip - Editing Methods with JShell
Step 04 - Introduction to Java Methods - Arguments and Parameters
Step 05 - Introduction to Java Method Arguments - Exercises
Step 06 - Introduction to Java Method Arguments - Puzzles and Tips
Step 07 - Getting back to Multiplication Table - Creating a method
Step 08 - Print Multiplication Table with a Parameter and Method Overloading
Step 09 - Passing Multiple Parameters to a Java Method
Step 10 - Returning from a Java Method - An Introduction
Step 11 - Returning from a Java Method - Exercises
Step 99 - Methods - Section Review
Exercises
Methods - Basics
Write and execute a method named sayHelloWorldThrice to print Hello
World thrice.
Write and execute a method that prints the following four statements:
I've created my first variable
I've created my first loop
[Link] 19/203
9/17/2018 in28Minutes | (0/25)
I've created my first method
I'm excited to learn Java
Method Parameters
1. Write a method printNumbers(int n) that prints all successive integers
from 1 to n .
2. Write a method printSquaresOfNumbers(int n) that prints the squares
of all successive integers from 1 to n .
Code Snippets
3 * 4
$2
$2 * 3
for( i =1; i<=10; i++) {
[Link]("%d * %d = %d", table, i,
table*i).println();
}
for( i =1; i<=10; i++) {
[Link]("%d * %d = %d", table, i,
table*i).println();
}
for( i =1; i<=10; i++) {
[Link]("%d * %d = %d", table, i,
table*i).println();
}
for( i =1; i<=10; i++) {
[Link]("%d * %d = %d", table, i,
table*i).println();
[Link] 20/203
9/17/2018 in28Minutes | (0/25)
}
int table = 7;
for( i =1; i<=10; i++) {
[Link]("%d * %d = %d", table, i,
table*i).println(); }
table = 8
for( i =1; i<=10; i++) {
} sayHelloWorldTwice()
void printLearningExperience() {
[Link]("I've created sdf first variable");
[Link]("I've created fsadjf first method");
[Link]("I've created fsajdfl first loop");
[Link]("I'm excited fasdflkjfskfsd learn
Java");
}
printLearningExperience()
sayHelloWorld(4)
{
[Link]("%d * %d = %d", 5, i, 5 *
i).println();
}
void printMultiplicationTable() {
for(int i=1;i<=10;i++) {
[Link]("%d * %d = %d", 5, i, 5 *
i).println();
}
}
printMultiplicationTable()
printMultiplicationTable(6)
printMultiplicationTable(7)
printMultiplicationTable()
printMultiplicationTable(6)
[Link](1,2)
void sum(int firstNumber,int secondNumber) {
int sum = firstNumber +
[Link] 23/203
9/17/2018 in28Minutes | (0/25)
secondNumber;
[Link](sum);
}
sum(5, 10) void sum(int firstNumber,int secondNumber, int
thirdNumber) {
int sum = firstNumber + secondNumber + thirdNumber;
[Link](sum); }
sum(5, 10, 15) [Link](4,5)
$110 int max = [Link](15, 25);
max
sum(1, 10)
int sumOfTwoNumbers(int firstNumber, int secondNumber) {
int sum = firstNumber + secondNumber;
return sum;
}
sumOfTwoNumbers(1,1)
int sum = sumOfThreeNumbers(2,3,4);
calculateThirdAngle(20, 50)
int sumOfThreeNumbers(int firstNumber, int secondNumber,
int thirdNumber) {
int sum = firstNumber + secondNumber + thirdNumber;
return sum;
}
sumOfThreeNumbers(1,2,3)
sumOfThreeNumbers(15,2,3)
int calculateThirdAngle(int angle1, int angle2) {
int angle3 = 180 - (angle1 + angle2);
return angle3;
}
calculateThirdAngle(20, 20)
calculateThirdAngle(20, 20)
[Link] 24/203
9/17/2018 in28Minutes | (0/25)
Steps
Step 00 - Section 03 - Overview Of Java Platform - Section Overview
Step 01 - Overview Of Java Platform - An Introduction - java, javac, bytecode and
JVM
Step 02 - Java Class and Object - First Look
Step 03 - Create a method in a Java class
Step 04 - Create and Compile [Link] class
Step 05 - Run Planet calss with Java - Using a main method
Step 06 - Play and Learn with Planet Class
Step 07 - JDK vs JRE vs JVM
[Link] 25/203
9/17/2018 in28Minutes | (0/25)
{
...> }
| created class Planet
jshell>
jshell> /methods
| void | void printMultiplicationTable()
| void printMultiplicationTable(int)
[Link] 26/203
9/17/2018 in28Minutes | (0/25)
jshell>
jshell> [Link]()
| Error:
| non-static method revolve() cannot be referenced from a
static context
| [Link]()
| ^------------^
jshell> [Link]()
Revolve
[Link] 27/203
9/17/2018 in28Minutes | (0/25)
jshell> [Link]()
Revolve
}
...> }
| replaced class Country
| update replaced variable country, reset to null
| update replaced variable india, reset to null
| update replaced variable usa, reset to null
jshell> [Link]()
Coming Soon
jshell> [Link]()
Coming Soon
27 : class Country {
void comingSoon() {
[Link]("Coming Soon");
}
}
jshell> /list
[Link] 28/203
9/17/2018 in28Minutes | (0/25)
Planet
22 : class Planet
{
void revolve() {
[Link]("Revolve");
}
}
jshell>
/03-IntroductionToJavaPlatform/[Link]
class Planet {
void revolve() {
[Link]("Revolve");
}
[Link] 29/203
9/17/2018 in28Minutes | (0/25)
Introduction To Eclipse-First
Java Project
Steps
Step 00 - Intro to Section and Installing Eclipse
Step 01 - Creating a New Java Project with Eclipse
Step 02 - Your first Java class with Eclipse
Step 03 - Writing Multiplication Table Java Program with Eclipse
Step 04 - Adding more methods for Multiplication Table Program
Step 05 - Programming Tip 1 : Refactoring with Eclipse
Step 06 - Programming Tip 2 : Debugging with Eclipse
Step 07 - Programming Tip 3 : Eclipse vs JShell - How to choose?
Code Examples
/04-IntroductionToEclipse-
FirstJavaProject/src/com/in28minutes/firstjavaproject/Hello
[Link]
package [Link];
[Link] 30/203
9/17/2018 in28Minutes | (0/25)
/04-IntroductionToEclipse-
FirstJavaProject/src/com/in28minutes/firstjavaproject/Keybo
[Link]
package [Link];
/04-IntroductionToEclipse-
FirstJavaProject/src/com/in28minutes/firstjavaproject/Multip
[Link]
package [Link];
void print() {
print(5);
}
/04-IntroductionToEclipse-
FirstJavaProject/src/com/in28minutes/firstjavaproject/Multip
[Link]
package [Link];
public class MultiplicationTableRunner {
//[Link](6);
//[Link](6, 11, 20);
}
/04-IntroductionToEclipse-
FirstJavaProject/src/com/in28minutes/firstjavaproject/Mutlip
[Link]
package [Link];
[Link] 32/203
9/17/2018 in28Minutes | (0/25)
{
for (int i = 1; i <= 10; i++) {
[Link]("%d X %d = %d",
table, i, table * i).println();
}
}
[Link] 33/203
9/17/2018 in28Minutes | (0/25)
Steps
Step 00 - Introduction to Object Oriented Programming - Section Overview
Step 01 - Introduction to Object Oriented Programming - Basics
Step 02 - Introduction to Object Oriented Programming - Terminology - Class,
Object, State and Behavior
Step 03 - Introduction to Object Oriented Programming - Exercise - Online
Shopping System and Person
Step 04 - Create Motor Bike Java Class and a couple of objects
Step 05 - Exercise Solutions - Book class and Three instances
Step 06 - Introducing State of an object with speed variable
Step 07 - Understanding basics of Encapsulation with Setter methods
Step 08 - Exercises and Tips - Getters and Generating Getters and Setters with
Eclipse
Step 09 - Puzzles on this and initialization of member variables
Step 10 - First Advantage of Encapsulation
Step 11 - Introduction to Encapsulation - Level 2
Step 12 - Encapsulation Exercises - Better Validation and Book class
Step 13 - Introdcution to Abstraction
Step 14 - Introduction to Java Constructors
Step 15 - Introduction to Java Constructors - Exercises and Puzzles
Step 16 - Introduction to Object Oriented Programming - Conclusion
Exercises
In each of the following systems, identify the basic entities involved, and organize
[Link] 34/203
9/17/2018 in28Minutes | (0/25)
them using object oriented terminology:
Online Shopping System
Person
Provide Better Encapsulation and Validation for Book and MotorBike class
Create a constructor for Book class and create three instances
Code Examples
/05-
IntroductionToObjectOrientedProgramming/src/com/in28mi
nutes/oops/[Link]
package [Link];
}
[Link] 35/203
9/17/2018 in28Minutes | (0/25)
/05-
IntroductionToObjectOrientedProgramming/src/com/in28mi
nutes/oops/[Link]
package [Link];
public class BookRunner {
[Link](100);
[Link](50);
[Link](45);
}
/05-
IntroductionToObjectOrientedProgramming/src/com/in28mi
nutes/oops/[Link]
package [Link];
[Link] 36/203
9/17/2018 in28Minutes | (0/25)
//constructors
MotorBike() {
this(5);
}
MotorBike(int speed) {
[Link] = speed;
}
//behavior
public int getSpeed() {
return speed;
}
void start() {
[Link]("Bike Started");
}
}
/05-
IntroductionToObjectOrientedProgramming/src/com/in28mi
nutes/oops/[Link]
[Link] 37/203
9/17/2018 in28Minutes | (0/25)
package [Link];
[Link]([Link]());
[Link]([Link]());
[Link]([Link]());
[Link]();
[Link]();
//[Link](100);
[Link](100);
[Link](100);
[Link](250);
[Link](250);
[Link] 38/203
9/17/2018 in28Minutes | (0/25)
[Link]([Link]());
[Link]([Link]());
}
}
/05-
IntroductionToObjectOrientedProgramming/entireoutput-
[Link]
jshell>
[Link] 40/203
9/17/2018 in28Minutes | (0/25)
Steps
Step 00 - Primitive Data Types in Depth - Section Overview
Step 01 - Basics about Java Integer Data Types - Casting, Operators and More
Step 02 - Java Integer Data Types - Puzzles - Octal, Hexadecimal, Post and Pre
increment
Step 03 - Java Integer Data Types - Exercises - BiNumber - add, multiply and
double
Step 04 - Java Floating Point Data Types - Casting , Conversion and Accuracy
Step 05 - Introduction to BigDecimal Java Class
Step 06 - BigDecimal Puzzles - Adding Integers
Step 07 - BigDecimal Exercises - Simple Interest Calculation
Step 08 - Java Boolean Data Type - Relational and Logical Operators
Step 09 - Java Boolean Data Type - Puzzles - Short Circuit Operators
Step 10 - Java Character Data Type char - Representation and Conversion
Step 11 - Java char Data Type - Exercises 1 - isVowel
Step 12 - Java char Data Type - Exercises 2 - isDigit
Step 13 - Java char Data Type - Exercises 3 - isConsonant, List Upper Case and
Lower Case Characters
Step 14 - Primitive Data Types in Depth - Conclusion
Exercises
Big Decimal
Calculate formula for Simple Interest Formula
Total Amount = principal + principal * interest * noOfYears;
SimpleInterestCalculator calculator
[Link] 41/203
9/17/2018 in28Minutes | (0/25)
=
new SimpleInterestCalculator("4500.00", "7.5");
BigDecimal totalValue =
[Link](5);// 5 years
[Link](totalSum);
char data type
Implement MyChar class
Code Examples
/06-PrimitiveDataTypesAndAlternatives/[Link]
[Link]
[Link]
Byte.MAX_VALUE
Byte.MIN_VALUE
[Link]
[Link]
[Link]
Integer.MAX_VALUE
Short.MAX_VALUE
[Link]
Byte.MIN_VALUE
Byte.MAX_VALUE
[Link]
[Link]
[Link] 42/203
9/17/2018 in28Minutes | (0/25)
[Link]
Integer.MAX_VALUE
byte c = 13;
long l = 50000000000l; i = (int) l
l = i
int eight = 010;
int sixteen = 0x10;
int fifteen = 0XF; int big = 0XBBAACC; Short.MAX_VALUE
short s = (short) i;
int i1 = s;
i
i
i
i
34.5
34.56789
double dbl = 34.5678;
float f2 = (float)dbl;
dbl++
dbl--
dbl % 5
float f = i;
34.56789876 + 34.2234
[Link](number2);
number1
BigDecimal number3 = [Link](number2);
number1
BigDecimal number1 = new BigDecimal("34.56789876");
BigDecimal number10 = new BigDecimal(34.2234);
BigDecimal number11 = new BigDecimal("34.56789876");
[Link](number11)
[Link](number11)
[Link](number2)
[Link](new BigDecimal(i))
[Link](new BigDecimal(i)) [Link](new
BigDecimal(100))
[Link](new BigDecimal("100.01234"))
[Link](new BigDecimal("100.012"))
[Link](new BigDecimal("100.12")) [Link](new
BigDecimal("100.1")) [Link](new BigDecimal("1001"))
[Link](new BigDecimal("100"))
boolean isValue = false;
i > 7
i >= 7
i < 7
i <= 7
i == 6
i == 7
i == 8
i = 8
i = 7
i == 7
i > 15
i >= 15
i <= 25
i >= 15 && i <= 25
i = 30
i >= 15 && i <= 25
i = 5
i >= 15 && i <= 25
true && true
true && false
false && true
false && false
false || true
false || true
[Link] 44/203
9/17/2018 in28Minutes | (0/25)
true || false
true || true
false || false
false ^ false false ^ true
true ^ false
true ^ true !true
!false int x = 6;
!(x>7)
!(x>7)
true || ++i==11
i
int i = 10;
int j = 15;
j > 15 && i++ > 5
j
i
j > 15 & i++ > 5
j
i
i++;
i++;
char ch2 = '\u0022';
char ch3 = '\u00A2';
ch++
ch
++ch
++ch
ch + 5
ch
(int)ch
ch
[Link](ch);
char ch = '\t';
[Link](ch);
[Link] 45/203
9/17/2018 in28Minutes | (0/25)
[Link](ch);
(int)'1'
(int)'0' (int)'9'
(int)'2'
(int)'a' (int)'z'
(int)'A' (int)'Z'
for (char ch = 'A'; ch <= 'Z'; ch++) {
[Link](ch);
}
for (char ch = 'A'; ch <= 'Z'; ch++) {
[Link](ch);
}
for (char ch = 'A'; ch <= 'C'; ch++) {
[Link](ch);
}
/06-
PrimitiveDataTypesAndAlternatives/src/com/in28minutes/pri
mitive/datatypes/[Link]
package [Link];
[Link] 46/203
9/17/2018 in28Minutes | (0/25)
[Link] 47/203
9/17/2018 in28Minutes | (0/25)
public int getNumber2() {
return number2;
}
{
this.number1 = number1;
this.number2 = number2;
}
/06-
PrimitiveDataTypesAndAlternatives/src/com/in28minutes/pri
mitive/datatypes/[Link]
package [Link];
[Link] 48/203
9/17/2018 in28Minutes | (0/25)
{
BiNumber numbers = new BiNumber(2, 3);
[Link]([Link]());//2+3
[Link]([Link]());//2*3
[Link](numbers.getNumber1());//4
[Link](numbers.getNumber2());//6
}
/06-
PrimitiveDataTypesAndAlternatives/src/com/in28minutes/pri
mitive/datatypes/[Link]
package [Link];
{
[Link] = ch;
}
[Link] 49/203
9/17/2018 in28Minutes | (0/25)
U
if(ch == 'a' || ch == 'A')
return
true;
if(ch == 'e' || ch ==
'E')
return true;
return false;
}
return false;
}
[Link] 50/203
9/17/2018 in28Minutes | (0/25)
'z'
return true;
'Z'
return true;
return false;
}
return false;
}
[Link] 51/203
9/17/2018 in28Minutes | (0/25)
/06-
PrimitiveDataTypesAndAlternatives/src/com/in28minutes/pri
mitive/datatypes/[Link]
package [Link];
public class MyCharRunner {
[Link]([Link]());
[Link]([Link]());
[Link]();
[Link]();
}
/06-
PrimitiveDataTypesAndAlternatives/src/com/in28minutes/pri
mitive/datatypes/[Link]
package [Link];
import [Link];
BigDecimal principal;
BigDecimal interest;
/06-
PrimitiveDataTypesAndAlternatives/src/com/in28minutes/pri
mitive/datatypes/[Link]
package [Link];
import [Link];
[Link] 53/203
9/17/2018 in28Minutes | (0/25)
SimpleInterestCalculator calculator =
new
SimpleInterestCalculator("4500.00",
"7.5");
BigDecimal totalValue =
[Link](5);// 5 years
//6187.50000
[Link](totalValue);
}
[Link] 54/203
9/17/2018 in28Minutes | (0/25)
Steps
Step 00 - Conditionals with Java - Section Overview
Step 01 - Introduction to If Else Statement
Step 02 - Introduction to Nested If Else
Step 03 - If Else Statement - Puzzles
Step 04 - If Else Problem - How to get User Input in Java?
Step 05 - If Else Problem - How to get number 2 and choice from user?
Step 06 - If Else Problem - Implementing with Nested If Else
Step 07 - Java Switch Statement - An introduction
Step 08 - Java Switch Statement - Puzzles - Default, Break and Fall Through
Step 09 - Java Switch Statement - Exercises - isWeekDay, nameOfMonth,
nameOfDay
Step 10 - Java Ternary Operation - An Introduction
Step 11 - Conditionals with Java - Conclusion
Exercises
If and Nested If Else - Design a Menu
Ask User for input
Enter two numbers
Choose an Operation
add
multiply
divide
subtract
[Link] 55/203
9/17/2018 in28Minutes | (0/25)
...
Publish Result
Enter Number1:
2
Enter Number2:
1 - Add
2 - Subtract
3 - Divide
4 - Multiply
Choose Operation: 4
Result is - 8
Switch
public static boolean isWeekDay(int dayNumber) {
input - number of day 0 (Sunday) to 6(Saturday)
return if the day is a Week Day.
Code Examples
/07-Conditionals/[Link]
if(true)
[Link] 56/203
9/17/2018 in28Minutes | (0/25)
{
[Link]("True");
}
if(false) {
[Link]("True");
}
if(i==3) {
[Link]("True");
}
if(i<2) {
[Link]("True");
}
if(i<=3 || i>=35) {
[Link]("True");
}
if(i<=3 && i>=35) {
[Link]("True");
}
if (i==3) {
[Link]("True");
} else {
[Link]("i is not 3");
}
i = 5
if (i==3) {
[Link]("True");
} else {
[Link]("i is not 3");
}
if(i==1) {
[Link]("i");
}
switch (i) {
case 1 :
[Link] 57/203
9/17/2018 in28Minutes | (0/25)
[Link]("1");
case 5 : [Link]("5");
default : [Link]("default");
}
i = 1 switch (i)
{
case 1 : [Link]("1");
case 5 : [Link]("5");
default : [Link]("default");
} switch (i)
{
case 1 : [Link]("1"); break;
case 5 : [Link]("5"); break;
default : [Link]("default"); break;
}
boolean isEven;
int i =5;
if(i%2==0) {
isEven = true;
} else {
isEven = false;
}
isEven
i = 6
if(i%2==0) {
isEven = false;
}
if(i%2==0) {
isEven = true;
} else {
isEven = false;
}
isEven
isEven = ( i%2==0 ? true : false )
[Link] 58/203
9/17/2018 in28Minutes | (0/25)
i = 6
isEven = ( i%2==0 ? true : false )
i = 7
isEven = ( i%2==0 ? true : false )
i = 6
String even = ( i%2 ==0 ? "YES" : "NO" );
/07-
Conditionals/src/com/in28minutes/ifstatement/examples/IfS
[Link]
package [Link];
[Link] 59/203
9/17/2018 in28Minutes | (0/25)
15;
if (l < 20)
[Link]("l<20");//
if (l > 20)
[Link]("l>20");
else
[Link]("Who am I?");//
{
int m =
15;
if(m>20)
if(m<20)
[Link]("m>20");
else
[Link]("Who am I?");
}
{
int i = 24;
// i is 25
// i is 24
// i is neither 25 or 24
if (i == 25) {
[Link]("i = 25");
} else if (i == 24) {
[Link]("i = 24");
} else if (i == 23) {
[Link]("i = 23");
} else {
[Link]("i != 24 and i
/07-
Conditionals/src/com/in28minutes/ifstatement/examples/M
[Link]
package [Link];
import [Link];
[Link]("Enter Number2:
[Link] 61/203
9/17/2018 in28Minutes | (0/25)
");
int number2 = [Link]();
number1);
[Link]("Number2 " +
number2);
[Link]("Choice " +
choice);
performOperationUsingSwitch(number1,
number2, choice);
}
{
[Link]("Result " +
(number1 / number2));
} else if (choice == 4) {
[Link]("Result " +
(number1 * number2));
} else {
[Link]("Invalid
Operation");
}
}
break;
case
2:
[Link]("Result " +
(number1 - number2));
break;
case 3:
[Link]("Result " +
(number1 / number2));
break;
case 4:
[Link]("Result " +
(number1 * number2));
break;
default:
[Link]("Invalid
[Link] 63/203
9/17/2018 in28Minutes | (0/25)
Operation");
break;
}
/07-
Conditionals/src/com/in28minutes/ifstatement/examples/S
[Link]
package [Link];
{
//case 0 :
//case 6 : return false;
case 1 :
case 2 :
case 3 :
case 4 :
case 5 : return true;
}
return false;
[Link] 64/203
9/17/2018 in28Minutes | (0/25)
return "Invalid_day";
}
}
/07-
Conditionals/src/com/in28minutes/ifstatement/examples/S
[Link]
package [Link];
3:
[Link]("Number is 2 or
3");
break;
default:
[Link]("Default");
break;
}
}
{
int number = 10;
switch (number) {
case 1:
[Link](1);
break;
case 2:
[Link](2);
break;
case 3:
[Link](3);
break;
default:
[Link]("Default");
break;
}
}
break;
case 1:
[Link](1);
break;
case
2:
[Link](2);
break;
case
[Link] 67/203
9/17/2018 in28Minutes | (0/25)
3:
[Link](3);
break;
}
}
}*/
}
[Link] 68/203
9/17/2018 in28Minutes | (0/25)
Loops
[Link] 69/203
9/17/2018 in28Minutes | (0/25)
Steps
Step 00 - Java Loops - Section Introduction
Step 01 - Java For Loop - Syntax and Puzzles
Step 02 - Java For Loop - Exercises Overview and First Exercise Prime Numbers
Step 03 - Java For Loop - Exercise - Sum Upto N Numbers and Sum of Divisors
Step 04 - Java For Loop - Exercise - Print a Number Triangle
Step 05 - While Loop in Java - An Introduction
Step 06 - While Loop - Exericises - Cubes and Squares upto limit
Step 07 - Do While Loop in Java - An Introduction
Step 08 - Do While Loop in Java - An Example - Cube while user enters positive
numbers
Step 09 - Introduction to Break and Continue
Step 10 - Selecting Loop in Java - For vs While vs Do While
Exercises
For Loop
Implement MyNumber class with behavior shown in the example below:
[Link]();
//1
//1 2
//1 2 3
[Link] 70/203
9/17/2018 in28Minutes | (0/25)
//1 2 3 4 //1 2 3 4 5
While
Implement WhileNumberPlayer class with behavior shown in the example below:
[Link]();
//For limit = 30, output would be 1 4 9 16 25
[Link]();
//For limit = 30, output would be 1 8 27
Choosing Loops
Thinking Exercise
Enter Number1:
2
Enter Number2:
4
1 - Add
2 - Subtract
3 - Divide
4 - Multiply
5 - Exit
Choose Operation: 4
Result is 8
Choose Operation: 1
Result is
[Link] 71/203
9/17/2018 in28Minutes | (0/25)
6
Choose Operation: 5
Thank You!
Code Examples
/08-Loops/[Link]
if (i>2)
{
[Link]("i>2");
[Link] 72/203
9/17/2018 in28Minutes | (0/25)
}
int i = 3; if (i>2) {
[Link]("i>2"); }
i = 0
while (i <5) {
[Link](i);
i++;
}
i
i = 6
while (i < 5) {
[Link](i);
i++;
}
i = -2
while (i < 5) {
[Link](i);
}
while (i < 5) {
[Link](i);
i++;
}
i
while (i < 5) {
[Link](i + " ");
i++;
}
i
i = 1
do {
[Link](i + "
");
i++;
} while (i<5);
i = 10
[Link] 73/203
9/17/2018 in28Minutes | (0/25)
while (i < 5) {
[Link](i + " ");
i++; }
do {
[Link](i + " ");
i++;
} while (i<5);
for(i=1;i<=10;i++) {
if(i==5)
break;
[Link](i + " ");
}
for(i=1;i<=10;i++) {
if(i%2==0)
break;
[Link](i + " ");
}
for(i=1;i<=10;i++) {
if(i%2==0)
continue;
[Link](i + " ");
}
for(i=1;i<=10;i++) {
if(i%2!=0)
continue;
[Link](i + " ");
}
/08-
Loops/src/com/in28minutes/loops/DoWhileRepeatedQuestio
[Link]
package [Link];
import [Link];
public class DoWhileRepeatedQuestionRunner
[Link] 74/203
9/17/2018 in28Minutes | (0/25)
do {
if (number != -1) {
[Link]("Cube is
" + (number * number * number));
}
[Link]("Enter a number:
");
number = [Link]();
} while (number >= 0);
[Link]("Thank You! Have Fun!");
}
/08-Loops/src/com/in28minutes/loops/[Link]
package [Link];
[Link] 75/203
9/17/2018 in28Minutes | (0/25)
{
// 2 to number-1
// How can check if a number is divisible
by 2?
if (number < 2) {
return false;
}
return true;
}
return sum;
}
int sum =
[Link] 76/203
9/17/2018 in28Minutes | (0/25)
0;
{
sum = sum + i;
}
}
return sum;
}
/08-
Loops/src/com/in28minutes/loops/[Link]
package [Link];
import [Link];
[Link] 77/203
9/17/2018 in28Minutes | (0/25)
{
MyNumber number = new MyNumber(5);
[Link]();
}
/08-
Loops/src/com/in28minutes/loops/[Link]
package [Link];
[Link] 78/203
9/17/2018 in28Minutes | (0/25)
");
i++;
}
[Link]();
}
/08-
Loops/src/com/in28minutes/loops/WhileNumberPlayerRunn
[Link]
package [Link];
[Link] 79/203
9/17/2018 in28Minutes | (0/25)
[Link]();
[Link]();
[Link] 80/203
9/17/2018 in28Minutes | (0/25)
Reference Types
Steps
Step 00 - Java Reference Types - Section Introduction
Step 01 - Reference Types - How are they stored in Memory?
Step 02 - Java Reference Types - Puzzles
Step 03 - String class - Introduction and Exercise - Print each word and char on a
new line
Step 04 - String class - Exercise Solution and Some More Important Methods
Step 05 - Understanding String is Immutable and String Concat, Upper Case, Lower
Case, Trim methods
Step 06 - String Concatenation and Join, Replace Methods
Step 07 - Java String Alternatives - StringBuffer and StringBuilder
Step 08 - Java Wrapper Classes - An Introduction - Why and What?
Step 09 - Java Wrapper Classes - Creation - Constructor and valueOf
Step 10 - Java Wrapper Classes - Auto Boxing and a Few Wrapper Constants - SIZE,
BYTES, MAX_VALUE and MIN_VALUE
Step 11 - Java Dates - Introduction to LocalDate, LocalTime and LocalDateTime
Step 12 - Java Dates - Exploring LocalDate - Creation and Methods to play with
Date
Step 13 - Java Dates - Exploring LocalDate - Comparing Dates and Creating Specific
Dates
Step 14 - Java Reference Types - Conclusion
Exercises
String
Take a piece of Text into a String.
Print each character in the text on a seperate line
Print each word in the text on a seperate line
[Link] 81/203
9/17/2018 in28Minutes | (0/25)
Code Examples
/09-ReferenceTypes/[Link]
class Planet {
}
12.34
"Test".length()
BigDecimal bd = new BigDecimal("1.0");
[Link](0)
[Link](2) [Link](3)
[Link] 83/203
9/17/2018 in28Minutes | (0/25)
"".isEmpty()
"true".equals("true")
"value".equals("value")
[Link]("value") [Link]("VAlue")
[Link]("VAlue") [Link]("is awesome");
str
String anotherString = [Link](" is awesome");
str
anotherString
String string2 = [Link](".");
str
anotherString
string2
[Link]()
[Link]()
[Link]()
String str2 = " in28Minutes is awesome. ";
[Link]()
1 + 2
"1" + "2"
"1" + 2
"1" + 23
1 + 23
1 + 2 + "3"
"1" + 2 + 3
[Link]("Value is " + 20)
[Link]("Value is " + 20 + 20)
[Link]("Value is " + (20 + 20))
[Link](",", "2", "3", "4")
[Link](",", "A", "B","C")
[Link](",", "A")
[Link](",", "A", "B")
"abcd".replace('a', 'z');
[Link] 84/203
9/17/2018 in28Minutes | (0/25)
"abcd".replace("ab", "xyz");
sb sb
[Link](1,'e')
sb
StringBuilder sb = new StringBuilder("test");
Integer integer1 = new Integer("5234");
Integer integer2 = new Integer("5234");
Integer i1 = new Integer(5);
Integer i2 = new Integer(5);
Integer i3 = [Link](5);
Integer i4 = [Link](5);
i1 == i2
i3 == i4
Integer integer = [Link]("4567");
int i = [Link]();
Float f = [Link]("12.45");
[Link]()
[Link]()
Integer eight = [Link](8);
[Link](eight);
[Link](eight);
Integer eightyEight = [Link](88);
[Link](eightyEight);
seven++
seven
seven == sevenAgain
Integer seven = 7;
Integer sevenAgain = 7;
seven == sevenAgain
Integer.MAX_VALUE
Integer.MIN_VALUE
[Link] 85/203
9/17/2018 in28Minutes | (0/25)
[Link]
[Link]
import [Link];
import [Link]; import [Link].*;
[Link]()
[Link]()
[Link]()
[Link]()
[Link]()
[Link]()
[Link]()
[Link]()
[Link]()
[Link](100)
[Link](100)
[Link](100)
[Link](100)
LocalDate hundredYearsBefore = [Link](100);
today
LocalDateTime now = [Link]();
LocalDate today = [Link]();
LocalDate yesterady = [Link](2018, 01, 31);
LocalDate yesterday = [Link](2018, 01, 31);
today
yesterday
[Link](2016)
[Link](20)
[Link](3)
[Link](120)
[Link](yesterday)
[Link](yesterday)
[Link] 86/203
9/17/2018 in28Minutes | (0/25)
Steps
Step 00 - Introduction to Array and ArrayList - Section Introduction with a
Challenge
Step 01 - Understanding the need and Basics about an Array
Step 02 - Java Arrays - Creating and Accessing Values - Introduction
Step 03 - Java Arrays - Puzzles - Arrays of Objects, Primitive Data Types, toString
and Exceptions
Step 04 - Java Arrays - Compare, Sort and Fill
Step 05 - Java Arrays - Exercise - Create Student Class - Part 1 - Total and Average
Marks
Step 06 - Java Arrays - Exercise - Create Student Class - Part 2 - Maximum and
Minimum Mark
Step 07 - Introduction to Variable Arguments - Need
Step 08 - Introduction to Variable Arguments - Basics
Step 09 - Introduction to Variable Arguments - Enhancing Student Class
Step 10 - Java Arrays - Using Person Objects and String Elements with Exercises
Step 11 - Java String Arrays - Exercise Solutions - Print Day of Week with Most
number of letters and more
Step 12 - Adding and Removing Marks - Problem with Arrays
Step 13 - First Look at ArrayList - An Introduction
Step 14 - First Look at ArrayList - Refactoring Student Class to use ArrayList
Step 15 - First Look at ArrayList - Enhancing Student Class with Add and Remove
Marks
Step 16 - Introduction to Array and ArrayList - Conclusion
Exercises
[Link] 87/203
9/17/2018 in28Minutes | (0/25)
Student Class
[Link](35);
[Link](5);
String Arrays
Create a string array with days of the week
"Sunday", "Monday", "Tuesday", "Wednesday"
"Thursday", "Friday", "Saturday"
Code Examples
/10-
ArraysAndArrayList/src/com/in28minutes/arrays/StringRunn
[Link]
package [Link];
[Link] 88/203
9/17/2018 in28Minutes | (0/25)
};
String dayWithMostCharacters =
"";
{
if ([Link]() >
[Link]()) {
dayWithMostCharacters =
day;
}
}
/10-
ArraysAndArrayList/src/com/in28minutes/arrays/[Link]
package [Link];
import [Link];
[Link] 89/203
9/17/2018 in28Minutes | (0/25)
import [Link];
import [Link];
import [Link];
ArrayList<Integer>();
{
[Link] = name;
[Link] 90/203
9/17/2018 in28Minutes | (0/25)
}
return sum;
{
int sum = getTotalSumOfMarks();
int number =
getNumberOfMarks();
BigDecimal(number), 3, [Link]);
[Link](index);
/10-
ArraysAndArrayList/src/com/in28minutes/arrays/StudentRun
[Link]
package [Link];
import [Link];
100);
number);
int sum =
[Link]();
[Link]("sum of marks : " +
[Link] 92/203
9/17/2018 in28Minutes | (0/25)
sum);
maximumMark);
int minimumMark =
[Link]();
[Link]("minimum of marks : " +
minimumMark);
BigDecimal average =
[Link]();
[Link]("average : " + average);
[Link](student);
[Link](35);
[Link](student);
[Link](1);
[Link](student);
[Link] 93/203
9/17/2018 in28Minutes | (0/25)
Steps
Step 00 - Object Oriented Programming - Level 2 - Section Introduction
[Link] 94/203
9/17/2018 in28Minutes | (0/25)
Step 14 - Java Abstract Class - First Example - Creating Recipes with Template
Method
Exercises
Creating a simple class
Book book =
new Book(123, "Object Oriented Programming with Java",
"Ranga");
[Link] 95/203
9/17/2018 in28Minutes | (0/25)
[Link](
new Review(10, "Great Book", 5));
[Link](
new Review(101, "Awesome", 5);
[Link](book);
Inheritance
Person
name,phone,email;
Student
college, class
Employee
title, employer, employeeGrade, salary
toString (print all values including those of Person)
interface Flyable
void fly();
Bird "with wings"
Aeroplane "with fuel"
Flyable flyingObjects = {new Bird(), new Aeroplane()};
Loop and invoke fly method
void bark()
Dog "Bow Bow"
Cat "Meow Meow"
Animal[] animals = {new Cat(), new Dog()};
[Link] 96/203
9/17/2018 in28Minutes | (0/25)
Loop and invoke bark method
Code Examples
/[Link]
[Link]()
abstract class AbstractTest {
}
abstract class Algorithm1 extends AbstractAlgorithm {
}
abstract class AbstractAlgorithm {
private int stepCount;
public int getStepCount() {
return stepCount();
}
}
class Implementation implements Interface2 {
public void method2() { }
public void method1() { }
}
abstract class ImplementationAbstract implements Interface2
{
public void method1() { }
}
interface Interface3 {
int test = 5;
}
interface Interface4 {
default void print() {
[Link]("default");
}
}
class Test implements Interface4 {
}
[Link]()
class Test1 implements Interface4 {
public void print() {
[Link]("override");
}
}
[Link] 98/203
9/17/2018 in28Minutes | (0/25)
interface Interface1 {
void method1();
}
interface Interface2 {
void method2();
}
/src/com/in28minutes/oops/level2/[Link]
package [Link].level2;
/src/com/in28minutes/oops/level2/[Link]
package [Link].level2;
[Link] 99/203
9/17/2018 in28Minutes | (0/25)
//creation
public Address(String line1, String city, String
zip) {
super();
this.line1 = line1;
[Link] = city;
[Link] = zip;
}
/src/com/in28minutes/oops/level2/[Link]
package [Link].level2;
import [Link];
/src/com/in28minutes/oops/level2/[Link]
package [Link].level2;
[Link](book);
[Link] 101/203
9/17/2018 in28Minutes | (0/25)
/src/com/in28minutes/oops/level2/[Link]
package [Link].level2;
//state
private String name;
private Address homeAddress;
private Address workAddress;
//creating
public Customer(String name, Address homeAddress) {
[Link] = name;
[Link] = homeAddress;
}
//operations
public Address getHomeAddress() {
return homeAddress;
}
{
return [Link]("name - [%s] home
address - [%s] work address - [%s])"
, name, homeAddress,
workAddress);
/src/com/in28minutes/oops/level2/[Link]
package [Link].level2;
[Link](customer);
}
}
/src/com/in28minutes/oops/level2/[Link]
package [Link].level2;
[Link] 103/203
9/17/2018 in28Minutes | (0/25)
//state
private String make;
private double radius;
private String color;
//creation
public Fan(String make, double radius, String
color) {
[Link] = make;
[Link] = radius;
[Link] = color;
}
{
return [Link]("make - %s, radius -
%f , color - %s , isOn - %b , speed - %d",
make, radius, color, isOn,
speed);
}
/src/com/in28minutes/oops/level2/[Link]
package [Link].level2;
/src/com/in28minutes/oops/level2/inheritance/AnimalRunne
[Link]
package [Link];
[Link] 105/203
9/17/2018 in28Minutes | (0/25)
{
[Link]("Meow Meow");
}
}
/src/com/in28minutes/oops/level2/inheritance/[Link]
a
package [Link];
import [Link];
title;
}
[Link] 108/203
9/17/2018 public void setSalary(BigDecimal
in28Minutes | (0/25) salary) {
[Link] = salary;
}
/src/com/in28minutes/oops/level2/inheritance/[Link]
package [Link];
public class Person extends Object{
[Link] 109/203
9/17/2018 in28Minutes | (0/25)
/src/com/in28minutes/oops/level2/inheritance/[Link]
package [Link];
[Link] 110/203
9/17/2018 in28Minutes | (0/25)
/src/com/in28minutes/oops/level2/inheritance/StudentRunn
[Link]
package [Link];
//[Link]("in28minutes@[Link]");
/*
Person person = new Person();
[Link]("Ranga");
[Link]("ranga@[Link]");
[Link]("123-456-7890");
String value = [Link]();
[Link](value);
[Link](person);
*/
"Programmer Analyst");
//[Link]("Ranga");
[Link]("ranga@[Link]");
[Link]("123-456-7890");
[Link]('A');
[Link]("Programmer Analyst");
[Link](employee);
} }
/src/com/in28minutes/oops/level2/inheritance/StudentWith
[Link]
package [Link];
[Link] 112/203
9/17/2018 in28Minutes | (0/25)
{
return phoneNumber;
{
[Link] = college;
}
[Link] 113/203
9/17/2018 in28Minutes | (0/25)
[Link] 114/203
9/17/2018 } in28Minutes | (0/25)
/src/com/in28minutes/oops/level2/interfaces/[Link]
a
package [Link];
@Override
public void up()
{
[Link]("Move piece up");
}
@Override
public void down() {
[Link]("Move piece down");
}
@Override
public void left() {
[Link]("Move piece left");
}
@Override
public void right() {
[Link]("Move piece right");
}
}
[Link] 115/203
9/17/2018 in28Minutes | (0/25)
/src/com/in28minutes/oops/level2/interfaces/ComplexAlgori
[Link]
package [Link];
/src/com/in28minutes/oops/level2/interfaces/DummyAlgorit
[Link]
package [Link];
@Override
public int complexAlgorithm(int number1, int
number2) {
return number1 + number2;
}
/src/com/in28minutes/oops/level2/interfaces/FlyableRunner.
java
package [Link];
interface Flyable{
void fly();
}
[Link] 116/203
9/17/2018 in28Minutes | (0/25)
@Override
public void fly() {
[Link]("with wings");
}
@Override
public void fly() {
[Link]("with fuel");
}
}
/src/com/in28minutes/oops/level2/interfaces/[Link]
va
package [Link];
[Link] 118/203
9/17/2018 public static void main(String[]
in28Minutes | (0/25) args) {
GamingConsole[] games = {new MarioGame(),
new ChessGame()};
for(GamingConsole game:games) {
[Link]();
[Link]();
[Link]();
[Link]();
}
/src/com/in28minutes/oops/level2/interfaces/GamingConsol
[Link]
package [Link];
public interface GamingConsole {
public void up();
public void down();
public void left();
public void right();
}
/src/com/in28minutes/oops/level2/interfaces/[Link]
a
package [Link];
@Override
public void up()
[Link] 119/203
9/17/2018 in28Minutes | (0/25)
{
[Link]("Jump");
}
@Override
public void down() {
[Link]("Goes into a hole");
}
@Override
public void left() {
}
@Override
public void right() {
[Link]("Go Forward");
/src/com/in28minutes/oops/level2/interfaces/[Link]
package [Link];
interface Test {
void
nothing();
[Link] 120/203
9/17/2018 in28Minutes | (0/25)
@Override
public void nothing() {
// TODO Auto-generated method stub
@Override
public void nothing() {
// TODO Auto-generated method
stub
[Link]([Link](10, 20));
}
[Link] 121/203
9/17/2018 in28Minutes | (0/25)
/src/com/in28minutes/oops/level2/interfaces/RealAlgorithm.
java
package [Link];
@Override
public int complexAlgorithm(int number1, int
number2) {
return number1 * number2;
}
/src/com/in28minutes/oops/level2/[Link]
package [Link].level2;
public class RecipeRunner
RecipeWithMicrowave recipeWithMicrowave =
new RecipeWithMicrowave();
[Link]();
[Link] 122/203
9/17/2018 in28Minutes | (0/25)
/src/com/in28minutes/oops/level2/[Link]
a
package [Link].level2;
public class RecipeWithMicrowave extends AbstractRecipe{
@Override
void getReady() {
[Link]("Get the raw
materials");
[Link]("Switch on the
microwave");
}
@Override
void doTheDish() {
[Link]("get stuff ready");
[Link]("Put it in the
microwave");
}
@Override
void cleanup() {
[Link]("Cleanup the
utensils");
[Link]("Switch off the
microwave");
}
}
/src/com/in28minutes/oops/level2/[Link]
package [Link].level2;
[Link] 123/203
9/17/2018 in28Minutes | (0/25)
//state
private int length;
//creation
public Rectangle(int length, int width) {
[Link] = length;
[Link] = width;
}
//operations
[Link] 124/203
9/17/2018 in28Minutes | (0/25)
/src/com/in28minutes/oops/level2/[Link]
package [Link].level2;
23);
[Link](rectangle);
[Link](25);
[Link](rectangle);
}
}
/src/com/in28minutes/oops/level2/[Link]
package [Link].level2;
public class Review {
[Link] 125/203
9/17/2018 in28Minutes | (0/25)
id;
[Link] = description;
[Link] = rating;
}
/src/com/in28minutes/oops/level2/[Link]
package [Link].level2;
@Override
void getReady() {
[Link]("Get the raw materials");
[Link]("Get the utensils");
}
@Override
void doTheDish() {
[Link]("do the dish");
[Link] 126/203
9/17/2018 in28Minutes | (0/25)
@Override
void cleanup() {
[Link]("Cleanup the utensils");
}
[Link] 127/203
9/17/2018 in28Minutes | (0/25)
Collections
Steps
Step 01 - Java Collections - Section Overview with Need For Collections
Step 02 - List Interface - Introduction - Position is King
Step 03 - List Inteface - Immutability and Introduction of Implementations -
ArrayList, LinkedList and Vector
Step 04 - List Inteface Implementations - ArrayList vs LinkedList
Step 05 - List Inteface Implementations - ArrayList vs Vector
Step 06 - List Inteface - Methods to add, remove and change elements and lists
Step 07 - List and ArrayList - Iterating around elements
Step 08 - List and ArrayList - Choosing iteration approach for printing and deleting
elements
Step 09 - List and ArrayList - Puzzles - Type Safety and Removing Integers
Step 10 - List and ArrayList - Sorting - Introduction to Collections sort static
method
Step 11 - List and ArrayList - Sorting - Implementing Comparable Inteface in
Student Class
Step 12 - List and ArrayList - Sorting - Providing Flexibility by implementing
Comparator interface
Step 13 - List and ArrayList - A Summary
Step 14 - Set Interface - Introduction - No Duplication
Step 15 - Understanding Data Structures - Array, LinkedList and Hashing
Step 16 - Understanding Data Structures - Tree - Sorted Order
Step 17 - Set Interface - Hands on - HashSet, LinkedHashSet and TreeSet
Step 18 - Set Interface - Exercise - Find Unique Characters in a List
Step 19 - TreeSet - Methods from NavigableSet - floor,lower,upper, subSet, head
and tailSet
Step 20 - Queue Interface - Process Elements in Order
[Link] 128/203
9/17/2018 in28Minutes | (0/25)
Step 21 - Introduction to PriorityQueue - Basic Methods and Customized Priority
Step 22 - Map Interface - An Introduction - Key and Value
Step 23 - Map Interface - Implementations - HashMap, HashTable,
LinkedHashMap and TreeMap
Step 24 - Map Interface - Basic Operations
Step 25 - Map Interface - Comparison - HashMap vs LinkedHashMap vs TreeMap
Step 26 - Map Interface - Exercise - Count occurances of characters and words in a
piece of text
Step 27 - TreeMap - Methods from NavigableMap - floorKey, higherKey, firstEntry,
subMap and more
Step 28 - Java Collections - Conclusion with Three Tips
Exercises
Set Interface
Map Interface
Code Examples
/12-Collections/[Link]
[Link]()
[Link]()
[Link](0)
[Link]("Dog");
[Link]("Cat");
[Link]("Cat")
words
[Link]("Dog")
[Link]("Dog")
[Link] 129/203
9/17/2018 in28Minutes | (0/25)
for(String word:wordsArrayList) {
if([Link]("at")) {
[Link](word);
}
}
wordsArrayList
for(String word:words) {
if([Link]("at"))
[Link](word);
}
for(String word:wordsAl) {
if([Link]("at")) {
[Link](word);
}
}
for(String word:wordsAl) {
if([Link]("at")) {
[Link](word);
}
}
wordsAl
List<String> words = [Link]("Apple", "Bat" , "Cat");
List<String> wordsAl = new ArrayList<>(words);
Iterator<String> iterator = [Link]();
while([Link]()) {
if([Link]().endsWith("at")) {
[Link]();
}
}
wordsAl
List value = [Link]("A", 'A' , 1, 1.0);
[Link](2)
[Link](2) instanceof Integer
[Link](1) instanceof Character
[Link](3) instanceof Double
[Link](101);
[Link] 131/203
9/17/2018 in28Minutes | (0/25)
[Link](101)
[Link](101);
[Link](101)
[Link]([Link](101))
numbersAl
List<Integer> numbersAl = new ArrayList<>(numbers);
[Link](numbersAl);
numbersAl
[Link]("Apple");
Set<String> hashset = new HashSet<>(set);
[Link]("Apple")
hashset
Set<String> set = [Link]("A", "Z","D", "C", "B");
[Link]("A")
[Link]("B")
hashSet
[Link]("C")
hashSet
[Link]("CA")
hashSet
[Link]("CAfsadfa")
hashSet
[Link]("Cat")
[Link]("Bat")
[Link]("Apple")
treeSet
[Link]("Cat");
[Link]("Bat");
[Link]("Apple");
hashSet
[Link]("Dog");
hashSet
[Link]("Elephant");
[Link](5);
[Link](4);
[Link](3);
[Link] 132/203
9/17/2018 in28Minutes | (0/25)
[Link](2);
[Link](1);
hashSet
Set<Integer> hashSet = new HashSet<>();
[Link](589789);
[Link](58978);
[Link](5897);
[Link](589);
[Link](58);
[Link](5);
hashSet
Set<Integer> linkedHashSet = new LinkedHashSet<>();
[Link](589789);
[Link](58978);
[Link](5897);
[Link](589);
[Link](58);
[Link](5);
linkedHashSet
Set<Integer> treeSet = new TreeSet<>();
[Link](584567);
[Link](58456);
[Link](5845);
[Link](584);
[Link](58);
[Link](5);
treeSet
[Link](765432);
[Link](76543);
[Link](7654);
[Link](765);
[Link](76);
numbers
[Link](765432);
[Link](76543);
[Link](7654);
[Link] 133/203
9/17/2018 in28Minutes | (0/25)
[Link](765);
[Link](76);
numbers
[Link](765789);
numbers
[Link](76)
numbers
[Link](765432);
[Link](76543);
[Link](7654);
[Link](765);
[Link](76);
numbers
[Link](76)
List<Character> characters = [Link]('A','Z','A', 'B',
'Z','F');
TreeSet<Integer> numbers = new TreeSet<>
([Link](65,54,34,12,99));
[Link](40)
[Link](34)
[Link](34)
[Link](34)
[Link](36)
[Link](34)
numbers
[Link](20,80)
[Link](34,54)
[Link](34,65)
[Link](34,true,65,true)
[Link](34,false,65,false)
[Link](50)
[Link](50)
Queue<String> queue = new PriorityQueue<>();
[Link]()
[Link]("Apple")
[Link]([Link]("Zebra", "Monkey", "Cat"))
[Link] 134/203
9/17/2018 in28Minutes | (0/25)
queue
[Link]()
queue
[Link]()
[Link]()
[Link]()
[Link]()
[Link]("R",1);
map
[Link]("Z")
[Link]("A")
[Link]("C")
[Link]()
[Link]()
[Link]("A")
[Link]("F")
[Link](3)
map
[Link](4)
[Link]()
[Link]()
map
[Link]("F",5)
hashmap
[Link]("Z",11)
hashmap
Map<String, Integer> map = [Link]("A",3,"Z",5,"B",10);
Map<String, Integer> linkedHashmap = new LinkedHashMap<>
(map);
HashMap<String, Integer> hashmap = new HashMap<>();
[Link]("Z",5)
[Link]("A",15)
[Link]("F",25)
[Link]("L",250)
hashmap
LinkedHashMap<String, Integer> linkedHashMap = new
[Link] 135/203
9/17/2018 in28Minutes | (0/25)
LinkedHashMap<>();
hashmap
[Link]("F",25)
[Link]("A",15)
[Link]("Z",5)
[Link]("L",250)
linkedHashMap
[Link]("F",25)
[Link]("A",15)
[Link]("Z",5)
[Link]("L",250)
treemap
TreeMap<String, Integer> treemap = new TreeMap<>();
[Link]("F",25)
[Link]("Z",5)
[Link]("L",250)
[Link]("A",15)
[Link]("B",25)
[Link]("G",25)
treemap
[Link]("C")
[Link]("C")
[Link]("B")
[Link]("B")
[Link]("B")
[Link]("C")
[Link]("B")
[Link]("B")
[Link]("B")
[Link]()
[Link]()
treemap
[Link]("C", "Y")
[Link]("B", "Z")
[Link]("B",true, "Z",true)
[Link] 136/203
9/17/2018 in28Minutes | (0/25)
/12-Collections/src/collections/[Link]
package collections;
import [Link];
import [Link];
for(char character:characters) {
//Get the character
Integer integer =
[Link](character);
if(integer==null) {
[Link](character,
1);
} else {
[Link](character,
integer + 1);
}
}
[Link] 137/203
9/17/2018 in28Minutes | (0/25)
[Link](occurances);
for(String word:words) {
//Get the character
Integer integer =
[Link](word);
if(integer==null) {
[Link](word,
1);
} else {
[Link](word,
integer + 1);
}
}
[Link](stringOccurances);
/12-Collections/src/collections/[Link]
package collections;
import [Link];
import [Link];
import [Link];
import [Link];
[Link] 138/203
9/17/2018 in28Minutes | (0/25)
/12-Collections/src/collections/[Link]
package collections;
import [Link];
import [Link];
import [Link];
import [Link];
[Link] 139/203
9/17/2018 in28Minutes | (0/25)
import [Link];
/12-Collections/src/collections/[Link]
package collections;
@Override
public int compareTo(Student that) {
return [Link]([Link], [Link]);
}
}
/12-Collections/src/collections/[Link]
[Link] 141/203
9/17/2018 in28Minutes | (0/25)
package collections;
import [Link];
import [Link];
import [Link];
import [Link];
[Link](studentsAl);
[Link](studentsAl);
[Link]("Desc " + studentsAl);
//[Link](studentsAl, new
[Link] 142/203
9/17/2018 in28Minutes | (0/25)
AscendingStudentComparator());
[Link](new
AscendingStudentComparator());
[Link]("AscendingStudentComparator " +
studentsAl);
}
[Link] 143/203
9/17/2018 in28Minutes | (0/25)
Generics
Steps
Step 01 - Introduction to Generics - Why do we need Generics?
Step 02 - Implementing Generics for the Custom List
Step 03 - Extending Custom List with a Generic Return Method
Step 04 - Generics Puzzles - Restrictions with extends and Generic Methods
Step 05 - Generics and WildCards - Upper Bound and Lower Bound
Code Examples
/13-
Generics/src/com/in28minutes/generics/[Link]
package [Link];
import [Link];
import [Link];
import [Link];
[Link] 144/203
9/17/2018 in28Minutes | (0/25)
[Link](
sumOfNumberList([Link](1,
2, 3, 4, 5)));
[Link](sumOfNumberList(
[Link](1.1, 2.1, 3.1, 4.1,
5.1)));
[Link](sumOfNumberList(
[Link](1l, 2l, 3l, 4l,
5l)));
ArrayList());
[Link](value);
/13-
Generics/src/com/in28minutes/generics/[Link]
package [Link];
import [Link];
[Link] 146/203
9/17/2018 in28Minutes | (0/25)
[Link] 147/203
9/17/2018 in28Minutes | (0/25)
FunctionalProgramming
Steps
Step 01 - Introduction to Functional Programming - Functions are First Class
Citizens
Step 02 - Functional Programming - First Example with Function as Parameter
Step 03 - Functional Programming - Exercise - Loop a List of Numbers
Step 04 - Functional Programming - Filtering - Exercises to print odd and even
numbers from List
Step 05 - Functional Programming - Collect - Sum of Numbers in a List
Step 06 - Functional Programming vs Structural Programming - A Quick
Comparison
Step 07 - Functional Programming Terminology - Lambda Expression, Stream and
Operations on a Stream
Step 08 - Stream Intermediate Operations - Sort, Distinct, Filter and Map
Step 09 - Stream Intermediate Operations - Exercises - Squares of First 10, Map
String List to LowerCase and Length of String
Step 10 - Stream Terminal Operations - 1 - max operation with Comparator
Step 11 - Stream Terminal Operations - 2 - min, collect to List,
Step 12 - Optional class in Java - An Introduction
Step 13 - Behind the Screens with Functional Interfaces - Implement Predicate
Interface
Step 14 - Behind the Screens with Functional Interfaces - Implement Consumer
Interface
Step 15 - Behind the Screens with Functional Interfaces - Implement Function
Inteface for Mapping
Step 16 - Simplify Functional Programming code with Method References - static
and instance methods
Step 17 - Functions are First Class Citizens
[Link] 148/203
9/17/2018 in28Minutes | (0/25)
Step 18 - Introduction to Functional Programming - Conclusion
Exercises
Create a list of numbers
Print each element using forEach
Filter Odd and Even numbers
Code Examples
/14-FunctionalProgramming/[Link]
[Link] 149/203
9/17/2018 in28Minutes | (0/25)
[Link]().distinct().sorted().forEach(e-
>[Link](e));
[Link]().distinct().map(e -> e * e).forEach(e-
>[Link](e));
[Link](1,10).forEach(p->[Link](p))
[Link](1,11).forEach(p->[Link](p))
[Link](1,11).map(e -> e * e).forEach(p-
>[Link](p)) [Link]("Apple", "Ant",
"Bat").stream().map(s->[Link]()).forEach(p ->
[Link](p))
[Link]("Apple", "Ant", "Bat").stream().map(s-
>[Link]()).forEach(p -> [Link](p))
[Link](1,11).reduce( 0 , (n1,n2) -> n1+n2)
[Link](23,12,34,53).stream().max((n1,n2) ->
[Link](n1,n2))
$[Link]()
[Link](23,12,34,53).stream().max((n1,n2) ->
[Link](n1,n2)).get()
[Link](23,12,34,53).stream().max((n1,n2) ->
[Link](n1,n2)).get()
[Link](23,12,34,53).stream().max((n1,n2) ->
[Link](n1,n2)).get()
[Link](23,12,34,53).stream().min((n1,n2) ->
[Link](n1,n2)).get()
[Link](23,12,34,53).stream().filter(e -> e%2==1).forEach(e
-> [Link](e))
[Link](23,12,34,53).stream().filter(e ->
e%2==1).collect([Link]())
[Link](23,12,34,53).stream().filter(e ->
e%2==0).collect([Link]())
[Link](1,11).map(e -> e * e)
[Link](23,12,34,53).stream().filter(e ->
e%2==0).collect([Link]())
[Link](1,10).map(e -> e * e)
[Link](1,10).map(e -> e *
e).boxed().collect([Link]())
[Link] 150/203
9/17/2018 in28Minutes | (0/25)
[Link](1,11).map(e -> e *
e).boxed().collect([Link]())
[Link](23,45,67,12).stream().filter(n -> n%2==0).max(
(n1,n2) -> [Link](n1,n2) )
$[Link]()
$[Link]()
[Link](23,45,67).stream().filter(n -> n%2==0).max( (n1,n2)
-> [Link](n1,n2) )
$[Link]()
$[Link](0)
$[Link](0)
[Link](23,45,67).stream().filter(n -> n%2==0).max( (n1,n2)
-> [Link](n1,n2) ).orElse(0)
[Link](23,45,67,34).stream().filter(n -> n%2==0).max(
(n1,n2) -> [Link](n1,n2) ).orElse(0)
/14-
FunctionalProgramming/src/com/in28minutes/functionalpro
gramming/[Link]
package [Link];
import [Link];
them
/*
[Link]()
.forEach( element -
>[Link](element));*/
[Link](sum);
[Link] 152/203
9/17/2018 in28Minutes | (0/25)
/14-
FunctionalProgramming/src/com/in28minutes/functionalpro
gramming/[Link]
package [Link];
import [Link];
public class FunctionalProgrammingRunner {
[Link] 153/203
9/17/2018 in28Minutes | (0/25)
[Link]
.println("element - " +
element));
}
/14-
FunctionalProgramming/src/com/in28minutes/functionalpro
gramming/[Link]
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
@Override
public boolean test(Integer number) {
return number%2 == 0;
}
[Link] 154/203
9/17/2018 in28Minutes | (0/25)
@Override
public void accept(Integer number) {
[Link](number);
}
@Override
public Integer apply(Integer number) {
return number * number;
}
[Link](23,43,34,45,36,48).stream()
.filter(n -> n%2 ==0)
.map(n -> n * n)
.forEach(e -> [Link](e));
[Link](23,43,34,45,36,48).stream()
.filter(new EvenNumberPredicate())
.map(new NumberSquareMapper())
.forEach(new SystemOutConsumer());
//.map(n -> n *
[Link] 155/203
9/17/2018 in28Minutes | (0/25)
n)
//<R> Stream<R> map(Function<? super T, ?
extends R> mapper);
// R apply(T t);
//.filter(new EvenNumberPredicate())
//Stream<T> filter(Predicate<? super T>
predicate);
//boolean test(T t);
[Link](23,43,34,45,36,48).stream()
.filter(evenPredicate)
.map(n -> n * n)
.forEach(e ->
[Link](e));
}
}
[Link] 156/203
9/17/2018 in28Minutes | (0/25)
/14-
FunctionalProgramming/src/com/in28minutes/functionalpro
gramming/[Link]
package [Link];
import [Link];
.stream().map(String::length)
.forEach(MethodReferencesRunner::print);
[Link](23,45,67,34).stream()
.filter(n -> n%2==0)
.max( (n1,n2) ->
[Link](n1,n2) )
[Link] 157/203
9/17/2018 in28Minutes | (0/25)
.orElse(0);
.filter(MethodReferencesRunner::isEven)
.max(Integer::compare)
.orElse(0);
[Link](max);
}
[Link] 158/203
9/17/2018 in28Minutes | (0/25)
Steps
Step 01 - Introduction to Threads and MultiThreading - Need for Threads
Step 02 - Creating a Thread for Task1 - Extending Thread Class
Step 03 - Creating a Thread for Task2 - Implement Runnable Interface
Step 04 - Theory - States of a Thread
Step 05 - Placing Priority Requests for Threads
Step 06 - Communication between Threads - join method
Step 07 - Thread utility methods and synchronized keyword - sleep, yield
Step 08 - Need for Controlling the Execution of Threads
Step 09 - Introduction to Executor Service
Step 10 - Executor Service - Customizing number of Threads
Step 11 - Executor Service - Returning a Future from Thread using Callable
Step 12 - Executor Service - Waiting for completion of multiple tasks using
invokeAll
Step 13 - Executor Service - Wait for only the fastest task using invokeAny
Step 14 - Threads and MultiThreading - Conclusion
Code Examples
/15-ThreadsAndParallelism/src/[Link]
import [Link];
import [Link];
[Link] 159/203
9/17/2018 in28Minutes | (0/25)
[Link]("\nTask" + number +
"Done");
}
}
[Link](new Task(1));
[Link](new Task(2));
[Link](new Task(3));
[Link](new Task(4));
[Link](new Task(5));
[Link](new Task(6));
[Link](new
[Link] 160/203
9/17/2018 in28Minutes | (0/25)
Task(7));
[Link]();
}
}
/15-
ThreadsAndParallelism/src/[Link]
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
String result =
[Link](tasks);
[Link](result);
[Link]();
[Link] 161/203
9/17/2018 in28Minutes | (0/25)
/15-ThreadsAndParallelism/src/[Link]
List<Future<String>> results =
[Link](tasks);
for(Future<String> result:results) {
[Link]([Link]());
}
[Link]();
}
}
[Link] 162/203
9/17/2018 in28Minutes | (0/25)
/15-ThreadsAndParallelism/src/[Link]
[Link]("\nTask1 Done");
}
}
@Override
public void run() {
[Link]("\nTask2 Started");
[Link]("\nTask2 Done");
[Link] 163/203
9/17/2018 in28Minutes | (0/25)
//• NEW;
//• RUNNABLE;
//• RUNNING;
//• BLOCKED/WAITING;
//• TERMINATED/DEAD;
[Link]();
[Link]();
//Task3
for(int i=301;i<=399; i++)
[Link](i + "
[Link] 164/203
9/17/2018 in28Minutes | (0/25)
");
[Link]("\nTask3 Done");
[Link]("\nMain Done");
[Link] 165/203
9/17/2018 in28Minutes | (0/25)
Exception Handling
Steps
Step 01 - Introduction to Exception Handling - Your Thought Process during
Exception Handling
Step 02 - Basics of Exceptions - NullPointerException and StackTrace
Step 03 - Basics of Handling Exceptions - try and catch
Step 04 - Basics of Handling Exceptions - Exception Hierarchy, Matching and
Catching Multiple Exceptions
Step 05 - Basics of Handling Exceptions - Need for finally
Step 06 - Basics of Handling Exceptions - Puzzles
Step 07 - Checked Exceptions vs Unchecked Exceptions - An Example
Step 08 - Hierarchy of Errors and Exceptions - Checked and Runtime
Step 09 - Throwing an Exception - Currencies Do Not Match Runtime Exception
Step 10 - Throwing a Checked Exception - Throws in method signature and
handling
Step 11 - Throwing a Custom Exception - CurrenciesDoNotMatchException
Step 12 - Write less code with Try with Resources - New Feature in Java 7
Step 13 - Basics of Handling Exceptions - Puzzles 2
Step 14 - Exception Handling - Conclusion with Best Practices
Code Examples
/16-
ExceptionHandling/src/com/in28minutes/exceptionhandling/
[Link]
package [Link];
[Link] 166/203
9/17/2018 in28Minutes | (0/25)
{
[Link]();
}*/
//someOtherMethod1();
someOtherMethod2();
/16-
ExceptionHandling/src/com/in28minutes/exceptionhandling/
[Link]
package [Link];
[Link] 167/203
9/17/2018 in28Minutes | (0/25)
{
method1();
[Link]("Main Ended");
}
{
method2();
[Link]("Method1 Ended");
}
/16-
ExceptionHandling/src/com/in28minutes/exceptionhandling/
[Link]
package [Link];
{
try
{
//String str = null;
//[Link]();
int[] i = {1,2};
int number = i[3];
[Link]("Method2
Ended");
} catch (NullPointerException ex) {
[Link]("Matched
NullPointerException");
[Link]();
} catch (ArrayIndexOutOfBoundsException ex)
{
[Link]("Matched
ArrayIndexOutOfBoundsException");
[Link]();
} catch (Exception ex) {
[Link]("Matched
Exception");
[Link]();
}
}
}
/16-
ExceptionHandling/src/com/in28minutes/exceptionhandling/
[Link]
[Link] 169/203
9/17/2018 in28Minutes | (0/25)
package [Link];
import [Link];
try {
scanner = new Scanner([Link]);
int[] numbers = { 12, 3, 4, 5 };
} catch (Exception e) {
[Link]();
} finally {
[Link]("Before Scanner
Close");
if(scanner!=null) {
[Link]();
}
}
[Link] 170/203
9/17/2018 in28Minutes | (0/25)
/16-
ExceptionHandling/src/com/in28minutes/exceptionhandling/
[Link]
package [Link];
class Amount {
if() {
//throw new Exception("Currencies
Don't Match " + [Link] + " & " +[Link] );
throw new
CurrenciesDoNotMatchException("Currencies Don't Match " +
[Link] + " & " +[Link] );
}
}
}
10);
Amount amount2 = new Amount("EUR", 20);
[Link](amount2);
[Link](amount1);
}
/16-
ExceptionHandling/src/com/in28minutes/exceptionhandling/
[Link]
package [Link];
import [Link];
Scanner([Link])) {
int[] numbers = { 12, 3, 4, 5 };
int number = numbers[21];
}
}
[Link] 173/203
9/17/2018 in28Minutes | (0/25)
Files
Steps
Step 01 - List files and folders in Directory with Files list method
Step 02 - Recursively List and Filter all files and folders in Directory with Step Files
walk method and Search with find method
Step 03 - Read content from a File - Files readAllLines and lines methods
Step 04 - Writing Content to a File - Files write method
Step 05 - Files - Conclusion
Code Examples
/17-Files/src/files/[Link]
package files;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
Path currentDirectory =
[Link] 174/203
9/17/2018 in28Minutes | (0/25)
[Link](".");
//[Link](currentDirectory).forEach([Link]::println)
;
//[Link](currentDirectory,
4).filter(predicate).forEach([Link]::println);
BiPredicate<Path, BasicFileAttributes>
javaMatcher
= (path,attributes) ->
[Link](path).contains(".java");
BiPredicate<Path, BasicFileAttributes>
directoryMatcher
= (path,attributes) ->
[Link]();
[Link](currentDirectory, 4,
directoryMatcher )
.forEach([Link]::println);
/17-Files/src/files/[Link]
[Link] 175/203
9/17/2018 in28Minutes | (0/25)
package files;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class FileReadRunner {
//List<String> lines =
[Link](pathFileToRead);
//[Link](lines);
[Link](pathFileToRead)
.map(String::toLowerCase)
.filter(str -> [Link]("a"))
.forEach([Link]::println);
/17-Files/src/files/[Link]
package files;
import [Link];
import [Link];
import [Link];
import [Link];
[Link] 176/203
9/17/2018 in28Minutes | (0/25)
import [Link];
List<String> list =
[Link]("Apple",
"Boy", "Cat", "Dog", "Elephant");
[Link](pathFileToWrite, list);
/17-Files/resources/[Link]
123,122
jljlfsadf
Apple
Bat
Cat
/17-Files/resources/fi[Link]
Apple
Boy
[Link] 177/203
9/17/2018 in28Minutes | (0/25)
Cat Dog
Elephant
[Link] 178/203
9/17/2018 in28Minutes | (0/25)
Steps
Step 01 - Getting started with Synchronized
Step 02 - Problem with Synchronized - Less Concurrency
Step 03 - Enter Locks with ReEntrantLock
Step 04 - Introduction to Atomic Classes - AtomicInteger
Step 05 - Need for ConcurrentMap
Step 06 - Implementing an example with ConcurrentHashMap
Step 07 - ConcurrentHashMap uses different locks for diferrent regions
Step 08 - CopyOnWrite Concurrent Collections - When reads are more than writes
Step 09 - Conclusion
Code Examples
/src/com/in28minutes/concurrency/[Link]
package [Link];
[Link] 179/203
9/17/2018 in28Minutes | (0/25)
i
//increment
//set i
}
/src/com/in28minutes/concurrency/BiCounterWithAtomicInt
[Link]
package [Link];
import [Link];
import [Link];
import [Link];
[Link] 180/203
9/17/2018 in28Minutes | (0/25)
AtomicInteger();
/src/com/in28minutes/concurrency/[Link]
package [Link];
import [Link];
import [Link];
I
i++;
[Link]();
//Release Lock For I
}
/src/com/in28minutes/concurrency/[Link]
package [Link];
[Link] 182/203
9/17/2018 in28Minutes | (0/25)
[Link]([Link]());
/src/com/in28minutes/concurrency/[Link]
va
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
for(char character:[Link]()) {
[Link](character, ch -> new
LongAdder()).increment();
}
[Link](occurances);
[Link] 183/203
9/17/2018 in28Minutes | (0/25)
/*
Map<Character, LongAdder> occurances = new
Hashtable<>();
[Link](occurances);
*/
}
/src/com/in28minutes/concurrency/CopyOnWriteArrayListRu
[Link]
package [Link];
import [Link];
import [Link];
//add - copy
//get
[Link] 184/203
9/17/2018 in28Minutes | (0/25)
CopyOnWriteArrayList<>();
//Threads - 3
[Link]("Ant");
[Link]("Bat");
[Link]("Cat");
//Threads - 10000
for(String element:list) {
[Link](element);
}
/src/com/in28minutes/concurrency/[Link]
package [Link];
i;
}
}
[Link] 186/203
9/17/2018 in28Minutes | (0/25)
Java Tips
Steps
Java Tip 01 - Imports and Static Imports
Java Tip 02 - Blocks
Java Tip 03 - equals method
Java Tip 04 - hashcode method
Java Tip 05 - Class Access Modifiers - public and default
Java Tip 06 - Method Access Modifiers - public, protected, private and default
Java Tip 07 - Final classes and Final methods
Java Tip 08 - Final Variables and Final Arguments
Java Tip 09 - Why do we need static variables?
Java Tip 09 - Why do we need static methods?
Java Tip 10 - Static methods cannot use instance methods or variables
Java Tip 11 - public static final - Constants
Java Tip 12 - Nested Classes - Inner Class vs Static Nested Class
Java Tip 13 - Anonymous Classes
Java Tip 14 - Why Enum and Enum Basics - ordinal and values
Java Tip 15 - Enum - Constructor, variables and methods
Java Tip 16 - Quick look at inbuild Enums - Month, DayOfWeek
Code Examples
/src/com/in28minutes/tips/access/package1/ClassAccessModi
fi[Link]
package [Link].package1;
[Link] 187/203
9/17/2018 in28Minutes | (0/25)
/src/com/in28minutes/tips/access/package1/[Link]
va
package [Link].package1;
/src/com/in28minutes/tips/access/package1/MethodAccessR
[Link]
[Link] 188/203
9/17/2018 in28Minutes | (0/25)
package [Link].package1;
/src/com/in28minutes/tips/access/package2/ClassAccessMod
ifi[Link]
package [Link].package2;
import
[Link];
[Link] 189/203
9/17/2018 in28Minutes | (0/25)
/src/com/in28minutes/tips/access/package2/MethodAccessR
[Link]
package [Link].package2;
import [Link];
//[Link]();
//[Link]();
[Link]();
//[Link]();
/src/com/in28minutes/tips/anonymous/AnonymousClassRun
[Link]
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
[Link] 190/203
9/17/2018 in28Minutes | (0/25)
[Link](animals,
lengthComparator
);
[Link](animals);
/src/com/in28minutes/tips/blocks/[Link]
package [Link];
{
//[Link](Integer.MIN_VALUE);
[Link](SECONDS_IN_DAY);
//[Link]("main");
{
int i;
//[Link]("3>2");
//[Link]("3>2");
}
//[Link](i);
/src/com/in28minutes/tips/eclipse/[Link]
package [Link];
import [Link];
import [Link];
/src/com/in28minutes/tips/eclipse/[Link]
[Link] 192/203
9/17/2018 in28Minutes | (0/25)
package [Link];
import [Link];
//PAIR PROGRAMMING
class TestBean {
private int i; //i is awesome
private String str;
public TestBean() {
/*
fsadjflkas
fskljdfalsk
*/
super();
}
(non-Javadoc)
* @see [Link]#equals([Link])
*/
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != [Link]()) {
return false;
}
TestBean other = (TestBean) obj;
if (i != other.i) {
return false;
}
return true;
}
/**
* @return the i
*/
public int getI() {
return i;
}
/**
* @param i the i to set
*/
public void setI(int i) {
this.i = i;
}
/**
* @return the str
*/
public String getStr()
[Link] 194/203
9/17/2018 in28Minutes | (0/25)
{
return str;
}
/**
* @param str the str to set
*/
public void setStr(String str) {
[Link] = str;
}
@Override
public int compareTo(String arg0) {
return 0;
}
456;
}
/src/com/in28minutes/tips/enums/[Link]
package [Link];
import [Link];
[Link]
.println([Link]([Link]()));
/src/com/in28minutes/tips/enums/[Link]
package [Link];
public enum Season {
SPRING(4), SUMMER(1), WINTER(2), FALL(3) ;
private int
[Link] 196/203
9/17/2018 in28Minutes | (0/25)
value;
//0,1,2,3
}
/src/com/in28minutes/tips/equals/[Link]
package [Link];
class Client {
private int id;
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + id;
return result;
}
@Override
public boolean equals(Object that)
[Link] 197/203
9/17/2018 in28Minutes | (0/25)
{
if (this == that)
return true;
if (that == null)
return false;
if (getClass() != [Link]())
return false;
Client other = (Client) that;
if (id != [Link])
return false;
return true;
}
//equals
//hashcode
/src/com/in28minutes/tips/imports/[Link]
[Link] 198/203
9/17/2018 in28Minutes | (0/25)
package [Link];
[Link]("IMports");
[Link]("Static Imports");
sort(new ArrayList<String>());
BigDecimal db = null;
/src/com/in28minutes/tips/nonaccess/package1/FinalNonAcc
essModifi[Link]
package [Link].package1;
//}
class SomeClass {
final public void doSomething() {}
public void doSomethingElse(final int arg) {
//arg = 6;
}
}
//i = 7;
/src/com/in28minutes/tips/nonaccess/package1/StaticModifi
[Link]
package [Link].package1;
class Player{
private String name;
0;
[Link]([Link]());
[Link]([Link]());
}
[Link] 201/203
9/17/2018 in28Minutes | (0/25)
[Link] 202/203
9/17/2018 in28Minutes | (0/25)
[Link] 203/203