├── .github
└── FUNDING.yml
├── .gitignore
├── 00-02-java-eclipse-installation.md
├── 00-03-path-variable.md
├── 01-IntroductionToJavaProgrammingWithJShell-MultiplicationTable
├── README.md
├── commands.txt
└── notes.md
├── 02-IntroductionToMethods-MultiplicationTable
├── README.md
├── commands-and-output.txt
└── commands.txt
├── 03-IntroductionToJavaPlatform
├── Planet.java
├── README.md
└── commands-and-output.txt
├── 04-IntroductionToEclipse-FirstJavaProject
├── .classpath
├── .project
├── .settings
│ └── org.eclipse.jdt.core.prefs
├── README.md
└── src
│ └── com
│ └── in28minutes
│ └── firstjavaproject
│ ├── HelloWorld.java
│ ├── KeyboardShortcuts.java
│ ├── MultiplicationTable.java
│ ├── MultiplicationTableRunner.java
│ └── MutliplicationTableBeforeRefactoring.java
├── 05-IntroductionToObjectOrientedProgramming
├── .classpath
├── .project
├── 05-end-of-section.md
├── 05-step-04.md
├── 05-step-05.md
├── 05-step-06.md
├── 05-step-07.md
├── 05-step-08.md
├── 05-step-09.md
├── 05-step-10.md
├── 05-step-11.md
├── README.md
├── entireoutput-constructor-puzzles.txt
├── notes.md
└── src
│ └── com
│ └── in28minutes
│ └── oops
│ ├── Book.java
│ ├── BookRunner.java
│ ├── MotorBike.java
│ └── MotorBikeRunner.java
├── 06-PrimitiveDataTypesAndAlternatives
├── .classpath
├── .project
├── .settings
│ └── org.eclipse.jdt.core.prefs
├── 06-end-of-section.md
├── README.md
├── all-commands-and-output.txt
├── commands.txt
├── java-primitive-data-types-in-depth
│ └── .project
└── src
│ └── com
│ └── in28minutes
│ └── primitive
│ └── datatypes
│ ├── BiNumber.java
│ ├── BiNumberRunner.java
│ ├── MyChar.java
│ ├── MyCharRunner.java
│ ├── SimpleInterestCalculator.java
│ └── SimpleInterestCalculatorRunner.java
├── 07-Conditionals
├── .classpath
├── .project
├── .settings
│ └── org.eclipse.jdt.core.prefs
├── 01-just-before-switch.md
├── 02-end-of-section.md
├── README.md
├── commands-and-output.txt
├── commands.txt
└── src
│ └── com
│ └── in28minutes
│ └── ifstatement
│ └── examples
│ ├── IfStatementRunner.java
│ ├── MenuRunner.java
│ ├── SwitchExercisesRunner.java
│ └── SwitchStatementRunner.java
├── 08-Loops
├── .classpath
├── .project
├── .settings
│ └── org.eclipse.jdt.core.prefs
├── README.md
├── commands-and-output.txt
├── commands.txt
└── src
│ └── com
│ └── in28minutes
│ └── loops
│ ├── DoWhileRepeatedQuestionRunner.java
│ ├── MyNumber.java
│ ├── MyNumberRunner.java
│ ├── WhileNumberPlayer.java
│ └── WhileNumberPlayerRunner.java
├── 09-ReferenceTypes
├── commands-and-output.txt
├── commands.txt
└── readme.md
├── 10-ArraysAndArrayList
├── .classpath
├── .project
├── .settings
│ └── org.eclipse.jdt.core.prefs
├── 01-after-variable-arguments.md
├── 02-after-string-array.md
├── 03-end-of-section.md
├── commands-and-output.txt
├── commands.txt
├── readme.md
└── src
│ └── com
│ └── in28minutes
│ └── arrays
│ ├── StringRunner.java
│ ├── Student.java
│ └── StudentRunner.java
├── 11-ObjectOrientedProgrammingAgain
├── .classpath
├── .project
├── commands-and-output.txt
├── commands.txt
├── readme.md
└── src
│ └── com
│ └── in28minutes
│ └── oops
│ └── level2
│ ├── AbstractRecipe.java
│ ├── Address.java
│ ├── Book.java
│ ├── BookRunner.java
│ ├── Customer.java
│ ├── CustomerRunner.java
│ ├── Fan.java
│ ├── FanRunner.java
│ ├── Recipe1.java
│ ├── RecipeRunner.java
│ ├── RecipeWithMicrowave.java
│ ├── Rectangle.java
│ ├── RectangleRunner.java
│ ├── Review.java
│ ├── inheritance
│ ├── AnimalRunner.java
│ ├── Employee.java
│ ├── Person.java
│ ├── Student.java
│ ├── StudentRunner.java
│ └── StudentWithoutInheritance.java
│ └── interfaces
│ ├── ChessGame.java
│ ├── ComplexAlgorithm.java
│ ├── DummyAlgorithm.java
│ ├── FlyableRunner.java
│ ├── GameRunner.java
│ ├── GamingConsole.java
│ ├── MarioGame.java
│ ├── Project.java
│ └── RealAlgorithm.java
├── 13-Generics
├── .classpath
├── .project
└── src
│ └── com
│ └── in28minutes
│ └── generics
│ ├── GenericsRunner.java
│ └── MyCustomList.java
├── 14-FunctionalProgramming
├── .classpath
├── .project
├── commands-and-output.txt
├── commands.txt
└── src
│ └── com
│ └── in28minutes
│ └── functionalprogramming
│ ├── FPNumberRunner.java
│ ├── FunctionalProgrammingRunner.java
│ ├── LambdaBehindTheScreensRunner.java
│ └── MethodReferencesRunner.java
├── 15-ThreadsAndConcurrency
├── .classpath
├── .project
└── src
│ ├── CallableRunner.java
│ ├── ExecutorServiceRunner.java
│ ├── MultipleAnyCallableRunner.java
│ ├── MultipleCallableRunner.java
│ └── ThreadBasicsRunner.java
├── 17-Files
├── .classpath
├── .project
├── resources
│ ├── data.txt
│ └── file-write.txt
└── src
│ └── files
│ ├── DirectoryScanRunner.java
│ ├── FileReadRunner.java
│ └── FileWriteRunner.java
├── 18-ConcurrencyLocksAtomicityAndCollections
├── .classpath
├── .project
├── 18-Concurrency.md
└── src
│ └── com
│ └── in28minutes
│ └── concurrency
│ ├── BiCounter.java
│ ├── BiCounterWithAtomicInteger.java
│ ├── BiCounterWithLock.java
│ ├── ConcurrencyRunner.java
│ ├── ConcurrentMapRunner.java
│ ├── CopyOnWriteArrayListRunner.java
│ └── Counter.java
├── 21-modularization-1-combined
├── .classpath
├── .project
└── src
│ └── com
│ └── in28minutes
│ ├── consumer
│ ├── DirectConsumer.java
│ └── MySortingUtilConsumer.java
│ └── sorting
│ ├── algorithm
│ └── BubbleSort.java
│ └── util
│ └── MySortingUtil.java
├── 22-modularization-2-service-jar
├── .classpath
├── .project
└── src
│ └── com
│ └── in28minutes
│ └── sorting
│ ├── algorithm
│ └── BubbleSort.java
│ └── util
│ └── MySortingUtil.java
├── 23-modularization-3-consumer-jar
├── .classpath
├── .project
└── src
│ └── com
│ └── in28minutes
│ └── consumer
│ ├── DirectConsumer.java
│ └── MySortingUtilConsumer.java
├── 24-modularization-4-service-module
├── .classpath
├── .project
└── src
│ ├── com
│ └── in28minutes
│ │ └── sorting
│ │ ├── algorithm
│ │ └── BubbleSort.java
│ │ └── util
│ │ └── MySortingUtil.java
│ └── module-info.java
├── 25-modularization-5-consumer-module
├── .classpath
├── .project
└── src
│ ├── com
│ └── in28minutes
│ │ └── consumer
│ │ ├── DirectConsumer.java
│ │ └── MySortingUtilConsumer.java
│ └── module-info.java
├── 3 types of Arrays
├── 31-java-new-api-features
├── .classpath
├── .project
├── .settings
│ └── org.eclipse.jdt.core.prefs
├── resources
│ ├── sample-new.txt
│ └── sample.txt
└── src
│ └── com
│ └── in28minutes
│ └── api
│ ├── a
│ └── CopyOfApiRunner.java
│ ├── b
│ └── FileReadWriteRunner.java
│ ├── c
│ └── PredicateNotRunner.java
│ ├── d
│ └── StringNewApiRunner.java
│ ├── e
│ └── TypeInferencesRunner.java
│ ├── f
│ └── SwitchExpressionRunner.java
│ ├── g
│ └── TextBlocksRunner.java
│ └── h
│ └── RecordsRunner.java
├── 51-learn-spring-framework
├── .gitignore
├── 1.md
├── 2.md
├── 3.md
├── 4.md
├── 5.md
├── 6.md
├── old.md
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── in28minutes
│ │ │ └── learnspringframework
│ │ │ ├── LearnSpringFrameworkApplication.java
│ │ │ ├── game
│ │ │ ├── GameRunner.java
│ │ │ ├── GamingConsole.java
│ │ │ ├── MarioGame.java
│ │ │ ├── PacManGame.java
│ │ │ └── SuperContraGame.java
│ │ │ └── sample
│ │ │ └── enterprise
│ │ │ └── flow
│ │ │ ├── business
│ │ │ └── BusinessService.java
│ │ │ ├── data
│ │ │ └── DataService.java
│ │ │ └── web
│ │ │ └── Controller.java
│ └── resources
│ │ └── application.properties
│ └── test
│ └── java
│ └── com
│ └── in28minutes
│ └── learnspringframework
│ └── LearnSpringFrameworkApplicationTests.java
├── 52-learn-spring-boot
├── .gitignore
├── 1.md
├── 2.md
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── in28minutes
│ │ │ └── learnspringboot
│ │ │ ├── LearnSpringBootApplication.java
│ │ │ └── courses
│ │ │ ├── bean
│ │ │ └── Course.java
│ │ │ ├── controller
│ │ │ └── CourseController.java
│ │ │ └── repository
│ │ │ └── CourseRepository.java
│ └── resources
│ │ ├── application.properties
│ │ └── data.sql
│ └── test
│ └── java
│ └── com
│ └── in28minutes
│ └── learnspringboot
│ └── LearnSpringBootApplicationTests.java
├── 7 HARD practice Problems in ARRAYS
├── 99-TipsAndTricks
├── .classpath
├── .project
└── src
│ └── com
│ └── in28minutes
│ └── tips
│ ├── access
│ ├── package1
│ │ ├── ClassAccessModifiers.java
│ │ ├── ExampleClass.java
│ │ └── MethodAccessRunnerInsideSamePackage.java
│ └── package2
│ │ ├── ClassAccessModifiersRunnerInOtherPackage.java
│ │ └── MethodAccessRunnerInDifferentPackage.java
│ ├── anonymous
│ └── AnonymousClassRunner.java
│ ├── blocks
│ └── BlocksRunner.java
│ ├── eclipse
│ ├── DummyForTest.java
│ └── EclipseTipsAndTricks.java
│ ├── enums
│ ├── EnumRunner.java
│ └── Season.java
│ ├── equals
│ └── EqualsRunner.java
│ ├── imports
│ └── ImportsRunner.java
│ ├── nestedclass
│ └── NestedClassRunner.java
│ └── nonaccess
│ └── package1
│ ├── FinalNonAccessModifierRunner.java
│ └── StaticModifierRunner.java
├── Addition of two matrices and defining its process together
├── ArrayList in Java: Demo & Methods
├── Avarage of Arrays
├── Composition of class in Java
├── Constructors in Inheritance in Java
├── Cool_Profile
└── README.md
├── EDC
├── EDC_Schema.sql
├── Enrolment.java
├── OS.java
└── Oracle Documentation Java Source Code Example
├── Exercise-4 with Solution
├── Finally Block in Java & Why is it needed!
├── Java Program that reads an integer between 0 and 1000 and adds all the digits in the integer.
├── Java Sorting Algorithm
├── Java Thread Methods1
├── Java program to break an integer into a sequence of individual digits.
├── LICENSE
├── Method to repeat
├── Multiple array and loops together
├── My GitHub Profile README
├── Nested Try-Catch in Java
├── Practice Problemes
├── Practice Problems in ARRAYS
├── PrintSemiPyramid.java
├── PrintStart.java
├── Questions on Inheritance
├── README.md
├── Samir_Array
├── Sleep Sort Algorithm
├── Sum of first even number by for loop
├── Switch statements
├── To check a no is in Array or not
├── Untitled Document 1
├── _config.yml
├── a Java program that reads a number in inches, converts it to meters.
├── a Java program that reads an integer between 0 and 1000 and adds all the digits in the integer.
├── a Java program to convert temperature from Fahrenheit to Celsius degree.
├── a Java program to find the square root of a number using Babylonian method.
├── convert Roman number to an integer number.
├── do while loop practice
└── googleb3ec120995e10cda.html
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4 | patreon: # Replace with a single Patreon username
5 | open_collective: # Replace with a single Open Collective username
6 | ko_fi: # Replace with a single Ko-fi username
7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9 | liberapay: # Replace with a single Liberapay username
10 | issuehunt: # Replace with a single IssueHunt username
11 |
12 | otechie: # Replace with a single Otechie username
13 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
14 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Compiled class file
2 | *.class
3 |
4 | # Log file
5 | *.log
6 |
7 | # BlueJ files
8 | *.ctxt
9 |
10 | # Mobile Tools for Java (J2ME)
11 | .mtj.tmp/
12 |
13 | # Package Files #
14 | *.jar
15 | *.war
16 | *.nar
17 | *.ear
18 | *.zip
19 | *.tar.gz
20 | *.rar
21 |
22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
23 | hs_err_pid*
24 |
--------------------------------------------------------------------------------
/00-03-path-variable.md:
--------------------------------------------------------------------------------
1 | ## Setting PATH environment variable in Windows
2 |
3 | #### Launch Environment Variables
4 | Two Options
5 | - Short Route - ```Click``` Start Button or ```Ctrl + Esc``` to launch start menu and type in ```Env```.
6 | - Long Route - Select ```Control Panel``` and then ```System```.
7 |
8 | 
9 |
10 | #### Select and Edit Environment Variable
11 | Choose ```Edit System Environment Variables```.
12 |
13 | 
14 |
15 | #### Select and Edit Path Variable
16 | 
17 |
18 | #### Find your JDK Bin Folder on Windows Explorer
19 | 
20 |
21 | #### Copy and Add it to PATH
22 | 
23 |
24 |
25 | ## Close all command prompt windows
26 |
27 | ## Launch command prompt again
28 |
29 | Type in
30 | ```
31 | jshell --version
32 |
33 | ```
34 |
35 | #### Launch up Java and Jshell again
36 |
--------------------------------------------------------------------------------
/01-IntroductionToJavaProgrammingWithJShell-MultiplicationTable/notes.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SamirPaulb/Java/5b49a41c7e24e14e6dafafc54b5714ea8987598c/01-IntroductionToJavaProgrammingWithJShell-MultiplicationTable/notes.md
--------------------------------------------------------------------------------
/03-IntroductionToJavaPlatform/Planet.java:
--------------------------------------------------------------------------------
1 | class Planet {
2 |
3 | void revolve() {
4 | System.out.println("Revolve");
5 | }
6 |
7 | public static void main(String[] args) {
8 | Planet earth = new Planet();
9 | earth.revolve();
10 | }
11 | }
--------------------------------------------------------------------------------
/03-IntroductionToJavaPlatform/README.md:
--------------------------------------------------------------------------------
1 | 
2 |
3 |
4 | # JDK vs JRE vs JVM
5 |
6 | - JVM (Java Virtual Machine) runs Java bytecode.
7 | - JRE = JVM + Libraries + Other Components
8 | - JDK = JRE + Compilers + Debuggers
9 |
10 | #
--------------------------------------------------------------------------------
/04-IntroductionToEclipse-FirstJavaProject/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/04-IntroductionToEclipse-FirstJavaProject/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | FirstJavaProjectWithIn28Minutes
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/04-IntroductionToEclipse-FirstJavaProject/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=9
4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5 | org.eclipse.jdt.core.compiler.compliance=9
6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate
8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11 | org.eclipse.jdt.core.compiler.source=9
12 |
--------------------------------------------------------------------------------
/04-IntroductionToEclipse-FirstJavaProject/README.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SamirPaulb/Java/5b49a41c7e24e14e6dafafc54b5714ea8987598c/04-IntroductionToEclipse-FirstJavaProject/README.md
--------------------------------------------------------------------------------
/04-IntroductionToEclipse-FirstJavaProject/src/com/in28minutes/firstjavaproject/HelloWorld.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.firstjavaproject;
2 |
3 | public class HelloWorld {
4 |
5 | public static void main(String[] args) {
6 |
7 | }
8 |
9 | }
--------------------------------------------------------------------------------
/04-IntroductionToEclipse-FirstJavaProject/src/com/in28minutes/firstjavaproject/KeyboardShortcuts.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.firstjavaproject;
2 |
3 | public class KeyboardShortcuts {
4 | public static void main(String[] args) {
5 | int i = 0;
6 | System.out.println(i);
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/04-IntroductionToEclipse-FirstJavaProject/src/com/in28minutes/firstjavaproject/MultiplicationTable.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.firstjavaproject;
2 |
3 | public class MultiplicationTable {
4 |
5 | void print() {
6 | print(5);
7 | }
8 |
9 | void print(int table) {
10 | print(table, 1, 10);
11 | }
12 |
13 | void print(int table, int from, int to) {
14 | for (int i = from; i <= to; i++) {
15 | System.out.printf("%d X %d = %d", table, i, table * i).println();
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/04-IntroductionToEclipse-FirstJavaProject/src/com/in28minutes/firstjavaproject/MultiplicationTableRunner.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.firstjavaproject;
2 |
3 | public class MultiplicationTableRunner {
4 |
5 | public static void main(String[] args) {
6 | MultiplicationTable table = new MultiplicationTable();
7 | table.print();
8 |
9 | //table.print(6);
10 | //table.print(6, 11, 20);
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/04-IntroductionToEclipse-FirstJavaProject/src/com/in28minutes/firstjavaproject/MutliplicationTableBeforeRefactoring.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.firstjavaproject;
2 |
3 | public class MutliplicationTableBeforeRefactoring {
4 | void print() {
5 | for (int i = 1; i <= 10; i++) {
6 | System.out.printf("%d X %d = %d", 5, i, 5 * i).println();
7 | }
8 | }
9 |
10 | void print(int table) {
11 | for (int i = 1; i <= 10; i++) {
12 | System.out.printf("%d X %d = %d", table, i, table * i).println();
13 | }
14 | }
15 |
16 | void print(int table, int from, int to) {
17 | for (int i = from; i <= to; i++) {
18 | System.out.printf("%d X %d = %d", table, i, table * i).println();
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/05-IntroductionToObjectOrientedProgramming/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/05-IntroductionToObjectOrientedProgramming/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | introduction-to-object-oriented-programming
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/05-IntroductionToObjectOrientedProgramming/05-step-04.md:
--------------------------------------------------------------------------------
1 |
4 |
5 | ## Complete Code Example
6 |
7 |
8 | ### /src/com/in28minutes/oops/Book.java
9 |
10 | ```java
11 | package com.in28minutes.oops;
12 |
13 | public class Book {
14 |
15 | }
16 | ```
17 | ---
18 |
19 | ### /src/com/in28minutes/oops/BookRunner.java
20 |
21 | ```java
22 | package com.in28minutes.oops;
23 |
24 | public class BookRunner {
25 |
26 | public static void main(String[] args) {
27 | // Create a new class called Book
28 | // Create three instances
29 | Book artOfComputerProgramming = new Book();
30 | Book effectiveJava = new Book();
31 | Book cleanCode = new Book();
32 |
33 | }
34 |
35 | }
36 | ```
37 | ---
38 |
39 | ### /src/com/in28minutes/oops/MotorBike.java
40 |
41 | ```java
42 | package com.in28minutes.oops;
43 |
44 | public class MotorBike {
45 | void start() {
46 | System.out.println("Bike Started");
47 | }
48 | }
49 | ```
50 | ---
51 |
52 | ### /src/com/in28minutes/oops/MotorBikeRunner.java
53 |
54 | ```java
55 | package com.in28minutes.oops;
56 |
57 | public class MotorBikeRunner {
58 |
59 | public static void main(String[] args) {
60 | MotorBike ducati = new MotorBike();
61 | MotorBike honda = new MotorBike();
62 |
63 | ducati.start();
64 | honda.start();
65 | }
66 |
67 | }
68 |
69 | // Create a new class called Book
70 | // Create three instances
71 | // Art Of Computer Programming
72 | // Effective Java
73 | // Clean Code
74 |
75 | ```
76 | ---
77 |
--------------------------------------------------------------------------------
/05-IntroductionToObjectOrientedProgramming/05-step-05.md:
--------------------------------------------------------------------------------
1 |
4 |
5 | ## Complete Code Example
6 |
7 |
8 | ### /src/com/in28minutes/oops/Book.java
9 |
10 | ```java
11 | package com.in28minutes.oops;
12 |
13 | public class Book {
14 |
15 | int noOfCopies;
16 | //noOfCopies
17 | }
18 | ```
19 | ---
20 |
21 | ### /src/com/in28minutes/oops/BookRunner.java
22 |
23 | ```java
24 | package com.in28minutes.oops;
25 |
26 | public class BookRunner {
27 |
28 | public static void main(String[] args) {
29 | // Create a new class called Book
30 | // Create three instances
31 | Book artOfComputerProgramming = new Book();
32 | Book effectiveJava = new Book();
33 | Book cleanCode = new Book();
34 |
35 | artOfComputerProgramming.noOfCopies = 100;
36 | effectiveJava.noOfCopies = 50;
37 | cleanCode.noOfCopies = 45;
38 | }
39 |
40 | }
41 | ```
42 | ---
43 |
44 | ### /src/com/in28minutes/oops/MotorBike.java
45 |
46 | ```java
47 | package com.in28minutes.oops;
48 |
49 | public class MotorBike {
50 |
51 | //state
52 | int speed;
53 |
54 | //behaviour
55 |
56 | void start() {
57 | System.out.println("Bike Started");
58 | }
59 | }
60 | ```
61 | ---
62 |
63 | ### /src/com/in28minutes/oops/MotorBikeRunner.java
64 |
65 | ```java
66 | package com.in28minutes.oops;
67 |
68 | public class MotorBikeRunner {
69 |
70 | public static void main(String[] args) {
71 | MotorBike ducati = new MotorBike();
72 | MotorBike honda = new MotorBike();
73 |
74 | ducati.start();
75 | honda.start();
76 |
77 | ducati.speed = 100;
78 | honda.speed = 80;
79 |
80 | ducati.speed = 20;
81 | honda.speed = 0;
82 | }
83 |
84 | }
85 |
86 | // Create a new class called Book
87 | // Create three instances
88 | // Art Of Computer Programming
89 | // Effective Java
90 | // Clean Code
91 |
92 | ```
93 | ---
94 |
--------------------------------------------------------------------------------
/05-IntroductionToObjectOrientedProgramming/05-step-06.md:
--------------------------------------------------------------------------------
1 |
4 |
5 | ## Complete Code Example
6 |
7 |
8 | ### /src/com/in28minutes/oops/Book.java
9 |
10 | ```java
11 | package com.in28minutes.oops;
12 |
13 | public class Book {
14 | private int noOfCopies;
15 |
16 | public void setNoOfCopies(int noOfCopies) {
17 | this.noOfCopies = noOfCopies;
18 | }
19 | }
20 | ```
21 | ---
22 |
23 | ### /src/com/in28minutes/oops/BookRunner.java
24 |
25 | ```java
26 | package com.in28minutes.oops;
27 |
28 | public class BookRunner {
29 |
30 | public static void main(String[] args) {
31 | // Create a new class called Book
32 | // Create three instances
33 | Book artOfComputerProgramming = new Book();
34 | Book effectiveJava = new Book();
35 | Book cleanCode = new Book();
36 |
37 | artOfComputerProgramming.setNoOfCopies(100);
38 | effectiveJava.setNoOfCopies(50);
39 | cleanCode.setNoOfCopies(45);
40 | }
41 |
42 | }
43 | ```
44 | ---
45 |
46 | ### /src/com/in28minutes/oops/MotorBike.java
47 |
48 | ```java
49 | package com.in28minutes.oops;
50 |
51 | public class MotorBike {
52 |
53 | //state
54 | private int speed; //member variable
55 |
56 | //behaviour
57 | //method
58 | //inputs - int speed
59 | //outputs - void
60 | //name - setSpeed
61 | void setSpeed(int speed) { //local variable
62 | this.speed = speed;
63 | }
64 |
65 | void start() {
66 | System.out.println("Bike Started");
67 | }
68 | }
69 | ```
70 | ---
71 |
72 | ### /src/com/in28minutes/oops/MotorBikeRunner.java
73 |
74 | ```java
75 | package com.in28minutes.oops;
76 |
77 | public class MotorBikeRunner {
78 |
79 | public static void main(String[] args) {
80 | MotorBike ducati = new MotorBike();
81 | MotorBike honda = new MotorBike();
82 |
83 | ducati.start();
84 | honda.start();
85 |
86 | ducati.setSpeed(100);
87 | honda.setSpeed(80);
88 |
89 | ducati.setSpeed(20);
90 | honda.setSpeed(0);
91 | }
92 |
93 | }
94 |
95 | // Create a new class called Book
96 | // Create three instances
97 | // Art Of Computer Programming
98 | // Effective Java
99 | // Clean Code
100 |
101 | ```
102 | ---
103 |
--------------------------------------------------------------------------------
/05-IntroductionToObjectOrientedProgramming/05-step-07.md:
--------------------------------------------------------------------------------
1 |
4 |
5 | ## Complete Code Example
6 |
7 |
8 | ### /src/com/in28minutes/oops/Book.java
9 |
10 | ```java
11 | package com.in28minutes.oops;
12 |
13 | public class Book {
14 | private int noOfCopies;
15 |
16 | public void setNoOfCopies(int noOfCopies) {
17 | this.noOfCopies = noOfCopies;
18 | }
19 | }
20 | ```
21 | ---
22 |
23 | ### /src/com/in28minutes/oops/BookRunner.java
24 |
25 | ```java
26 | package com.in28minutes.oops;
27 |
28 | public class BookRunner {
29 |
30 | public static void main(String[] args) {
31 | // Create a new class called Book
32 | // Create three instances
33 | Book artOfComputerProgramming = new Book();
34 | Book effectiveJava = new Book();
35 | Book cleanCode = new Book();
36 |
37 | artOfComputerProgramming.setNoOfCopies(100);
38 | effectiveJava.setNoOfCopies(50);
39 | cleanCode.setNoOfCopies(45);
40 | }
41 |
42 | }
43 | ```
44 | ---
45 |
46 | ### /src/com/in28minutes/oops/MotorBike.java
47 |
48 | ```java
49 | package com.in28minutes.oops;
50 |
51 | public class MotorBike {
52 |
53 | //state
54 | private int speed; //member variable
55 |
56 | public int getSpeed() {
57 | return speed;
58 | }
59 |
60 | public void setSpeed(int speed) {
61 | this.speed = speed;
62 | }
63 |
64 | void start() {
65 | System.out.println("Bike Started");
66 | }
67 | }
68 | ```
69 | ---
70 |
71 | ### /src/com/in28minutes/oops/MotorBikeRunner.java
72 |
73 | ```java
74 | package com.in28minutes.oops;
75 |
76 | public class MotorBikeRunner {
77 |
78 | public static void main(String[] args) {
79 | MotorBike ducati = new MotorBike();
80 | MotorBike honda = new MotorBike();
81 |
82 | ducati.start();
83 | honda.start();
84 |
85 | ducati.setSpeed(100);
86 | System.out.println(ducati.getSpeed());
87 |
88 | honda.setSpeed(80);
89 | System.out.println(honda.getSpeed());
90 |
91 | }
92 |
93 | }
94 |
95 | // Create a new class called Book
96 | // Create three instances
97 | // Art Of Computer Programming
98 | // Effective Java
99 | // Clean Code
100 |
101 | ```
102 | ---
103 |
--------------------------------------------------------------------------------
/05-IntroductionToObjectOrientedProgramming/05-step-08.md:
--------------------------------------------------------------------------------
1 |
4 |
5 | ## Complete Code Example
6 |
7 |
8 | ### /src/com/in28minutes/oops/Book.java
9 |
10 | ```java
11 | package com.in28minutes.oops;
12 |
13 | public class Book {
14 | private int noOfCopies;
15 |
16 | public void setNoOfCopies(int noOfCopies) {
17 | this.noOfCopies = noOfCopies;
18 | }
19 | }
20 | ```
21 | ---
22 |
23 | ### /src/com/in28minutes/oops/BookRunner.java
24 |
25 | ```java
26 | package com.in28minutes.oops;
27 |
28 | public class BookRunner {
29 |
30 | public static void main(String[] args) {
31 | // Create a new class called Book
32 | // Create three instances
33 | Book artOfComputerProgramming = new Book();
34 | Book effectiveJava = new Book();
35 | Book cleanCode = new Book();
36 |
37 | artOfComputerProgramming.setNoOfCopies(100);
38 | effectiveJava.setNoOfCopies(50);
39 | cleanCode.setNoOfCopies(45);
40 | }
41 |
42 | }
43 | ```
44 | ---
45 |
46 | ### /src/com/in28minutes/oops/MotorBike.java
47 |
48 | ```java
49 | package com.in28minutes.oops;
50 |
51 | public class MotorBike {
52 |
53 | //state
54 | private int speed; //member variable
55 |
56 | public int getSpeed() {
57 | return speed;
58 | }
59 |
60 | public void setSpeed(int speed) {
61 | this.speed = speed;
62 | }
63 |
64 | void start() {
65 | System.out.println("Bike Started");
66 | }
67 | }
68 | ```
69 | ---
70 |
71 | ### /src/com/in28minutes/oops/MotorBikeRunner.java
72 |
73 | ```java
74 | package com.in28minutes.oops;
75 |
76 | public class MotorBikeRunner {
77 |
78 | public static void main(String[] args) {
79 | MotorBike ducati = new MotorBike();
80 | MotorBike honda = new MotorBike();
81 |
82 | ducati.start();
83 | honda.start();
84 |
85 | ducati.setSpeed(100);
86 | System.out.println(ducati.getSpeed());
87 |
88 | //honda.setSpeed(80);
89 | System.out.println(honda.getSpeed());
90 | }
91 |
92 | }
93 |
94 | // Create a new class called Book
95 | // Create three instances
96 | // Art Of Computer Programming
97 | // Effective Java
98 | // Clean Code
99 | ```
100 | ---
101 |
--------------------------------------------------------------------------------
/05-IntroductionToObjectOrientedProgramming/05-step-09.md:
--------------------------------------------------------------------------------
1 |
4 |
5 | ## Complete Code Example
6 |
7 |
8 | ### /src/com/in28minutes/oops/Book.java
9 |
10 | ```java
11 | package com.in28minutes.oops;
12 |
13 | public class Book {
14 | private int noOfCopies;
15 |
16 | public void setNoOfCopies(int noOfCopies) {
17 | if (noOfCopies > 0)
18 | this.noOfCopies = noOfCopies;
19 | }
20 |
21 | public void increaseNoOfCopies(int howMuch) {
22 | setNoOfCopies(this.noOfCopies + howMuch);
23 | }
24 |
25 | public void decreaseNoOfCopies(int howMuch) {
26 | setNoOfCopies(this.noOfCopies - howMuch);
27 | }
28 |
29 | }
30 | ```
31 | ---
32 |
33 | ### /src/com/in28minutes/oops/BookRunner.java
34 |
35 | ```java
36 | package com.in28minutes.oops;
37 |
38 | public class BookRunner {
39 |
40 | public static void main(String[] args) {
41 | // Create a new class called Book
42 | // Create three instances
43 | Book artOfComputerProgramming = new Book();
44 | Book effectiveJava = new Book();
45 | Book cleanCode = new Book();
46 |
47 | artOfComputerProgramming.setNoOfCopies(100);
48 | effectiveJava.setNoOfCopies(50);
49 | cleanCode.setNoOfCopies(45);
50 | }
51 |
52 | }
53 | ```
54 | ---
55 |
56 | ### /src/com/in28minutes/oops/MotorBike.java
57 |
58 | ```java
59 | package com.in28minutes.oops;
60 |
61 | public class MotorBike {
62 | //state
63 | private int speed; //member variable
64 |
65 | public int getSpeed() {
66 | return speed;
67 | }
68 |
69 | public void setSpeed(int speed) {
70 | if(speed > 0 )
71 | this.speed = speed;
72 | }
73 |
74 | public void increaseSpeed(int howMuch) {
75 | setSpeed(this.speed + howMuch);
76 | }
77 |
78 | public void decreaseSpeed(int howMuch) {
79 | setSpeed(this.speed - howMuch);
80 | }
81 |
82 | void start() {
83 | System.out.println("Bike Started");
84 | }
85 | }
86 | ```
87 | ---
88 |
89 | ### /src/com/in28minutes/oops/MotorBikeRunner.java
90 |
91 | ```java
92 | package com.in28minutes.oops;
93 |
94 | public class MotorBikeRunner {
95 |
96 | public static void main(String[] args) {
97 | MotorBike ducati = new MotorBike();
98 | MotorBike honda = new MotorBike();
99 |
100 | ducati.start();
101 | honda.start();
102 |
103 | ducati.setSpeed(100);
104 |
105 | ducati.increaseSpeed(100);
106 |
107 | honda.increaseSpeed(100);
108 |
109 | ducati.decreaseSpeed(250);
110 |
111 | honda.decreaseSpeed(250);
112 |
113 | System.out.println(ducati.getSpeed());
114 |
115 | System.out.println(honda.getSpeed());
116 | }
117 |
118 | }
119 |
120 | // Create a new class called Book
121 | // Create three instances
122 | // Art Of Computer Programming
123 | // Effective Java
124 | // Clean Code
125 | ```
126 | ---
127 |
--------------------------------------------------------------------------------
/05-IntroductionToObjectOrientedProgramming/05-step-10.md:
--------------------------------------------------------------------------------
1 |
4 |
5 | ## Complete Code Example
6 |
7 |
8 | ### /src/com/in28minutes/oops/Book.java
9 |
10 | ```java
11 | package com.in28minutes.oops;
12 |
13 | public class Book {
14 |
15 | private int noOfCopies;
16 |
17 | public void setNoOfCopies(int noOfCopies) {
18 | if (noOfCopies > 0)
19 | this.noOfCopies = noOfCopies;
20 | }
21 |
22 | public void increaseNoOfCopies(int howMuch) {
23 | setNoOfCopies(this.noOfCopies + howMuch);
24 | }
25 |
26 | public void decreaseNoOfCopies(int howMuch) {
27 | setNoOfCopies(this.noOfCopies - howMuch);
28 | }
29 |
30 | }
31 | ```
32 | ---
33 |
34 | ### /src/com/in28minutes/oops/BookRunner.java
35 |
36 | ```java
37 | package com.in28minutes.oops;
38 |
39 | public class BookRunner {
40 |
41 | public static void main(String[] args) {
42 | // Create a new class called Book
43 | // Create three instances
44 | Book artOfComputerProgramming = new Book();
45 | Book effectiveJava = new Book();
46 | Book cleanCode = new Book();
47 |
48 | artOfComputerProgramming.setNoOfCopies(100);
49 | effectiveJava.setNoOfCopies(50);
50 | cleanCode.setNoOfCopies(45);
51 | }
52 |
53 | }
54 | ```
55 | ---
56 |
57 | ### /src/com/in28minutes/oops/MotorBike.java
58 |
59 | ```java
60 | package com.in28minutes.oops;
61 |
62 | public class MotorBike {
63 | //state
64 | private int speed; //member variable
65 |
66 | MotorBike(int speed) {
67 | this.speed = speed;
68 | }
69 |
70 |
71 | public int getSpeed() {
72 | return speed;
73 | }
74 |
75 | public void setSpeed(int speed) {
76 | if(speed > 0 )
77 | this.speed = speed;
78 | }
79 |
80 | public void increaseSpeed(int howMuch) {
81 | setSpeed(this.speed + howMuch);
82 | }
83 |
84 | public void decreaseSpeed(int howMuch) {
85 | setSpeed(this.speed - howMuch);
86 | }
87 |
88 | void start() {
89 | System.out.println("Bike Started");
90 | }
91 | }
92 | ```
93 | ---
94 |
95 | ### /src/com/in28minutes/oops/MotorBikeRunner.java
96 |
97 | ```java
98 | package com.in28minutes.oops;
99 |
100 | public class MotorBikeRunner {
101 |
102 | public static void main(String[] args) {
103 |
104 | MotorBike ducati = new MotorBike(100);
105 |
106 | MotorBike honda = new MotorBike(200);
107 |
108 | System.out.println(ducati.getSpeed());
109 |
110 | System.out.println(honda.getSpeed());
111 |
112 |
113 | ducati.start();
114 |
115 | honda.start();
116 |
117 | //ducati.setSpeed(100);
118 |
119 | ducati.increaseSpeed(100);
120 |
121 | honda.increaseSpeed(100);
122 |
123 | ducati.decreaseSpeed(250);
124 |
125 | honda.decreaseSpeed(250);
126 |
127 | System.out.println(ducati.getSpeed());
128 |
129 | System.out.println(honda.getSpeed());
130 | }
131 |
132 | }
133 |
134 | // Create a new class called Book
135 | // Create three instances
136 | // Art Of Computer Programming
137 | // Effective Java
138 | // Clean Code
139 | ```
140 | ---
141 |
--------------------------------------------------------------------------------
/05-IntroductionToObjectOrientedProgramming/README.md:
--------------------------------------------------------------------------------
1 | # Introduction To Object Oriented Programming
2 |
3 | Build a Motor Bike Class
4 | - adjust speed and gears.
5 |
6 | We would want to create a few objects and play with them
7 | - Understand concepts of Class, Object, State, Behavior
8 | - Understand basics of Encapsulation and Abstraction
9 |
10 |
11 | ## Procedural/Structured Programming
12 |
13 | - Thinking in terms of procedures/methods/functions
14 |
15 | ```
16 | //Global Data
17 |
18 | fly() {
19 | travelToAirport();
20 | findCheckInCounter();
21 | checkIn();
22 | passSecurityCheck();
23 | waitForBoardingCall();
24 | boardTheFlight();
25 | wishTheAirHostess();
26 | takeOff();
27 | haveFun();
28 | landing();
29 | }
30 | ```
31 |
32 | ## Object Oriented Programming
33 |
34 | - Thinking about Objects
35 | - Class, Object
36 | - Data (state)
37 | - Actions (behaviour)
38 |
39 | Aeroplane
40 | - airline, make, type, position //data
41 | - takeoff(), land(), cruise() //actions
42 |
43 | AirHostess
44 | - name, address //data
45 | - wish(), serve() //actions
46 |
47 | Passenger
48 | - name, address //data
49 | - takeCab(), checkin(), walk(), smile() //actions
50 |
51 | ## Object Oriented Terminology
52 |
53 | ```
54 | class Planet {
55 | name, location, distanceFromSun //data/state/fields
56 | revolve(), rotate() //actions/behavior/methods
57 | }
58 | ```
59 |
60 | ```
61 | Planet earth = new Planet();
62 | Planet venus = new Planet();
63 | ```
64 |
65 | Terminology
66 | - Class - Template ex : Planet, Person
67 | - Objects/Instances - ex : earth, venus, mahatmaGandhi, nelsonMandela
68 | - Member Data/State/Fields - Data present in each object - name, location, distanceFromSun
69 | - Actions/Methods/Behaviour - What actions can be performed on each object?
70 |
71 | ## Exercises
72 |
73 | ### Online Shopping System
74 | - Customer
75 | - name, address
76 | - login(), logout(), selectProduct(product)
77 | - Shopping Cart
78 | - items
79 | - add(item), remove(item)
80 | - Product
81 | - name, price, quantityAvailable
82 | - order(), changePrice()
83 |
84 | ### Person
85 |
86 | - name, address, hobbies, work
87 | - walk(), run(), sleep(), eat(), drink()
88 |
--------------------------------------------------------------------------------
/05-IntroductionToObjectOrientedProgramming/entireoutput-constructor-puzzles.txt:
--------------------------------------------------------------------------------
1 | Last login: Mon Jan 29 10:33:44 on ttys000
2 | Rangas-MacBook-Pro:~ rangaraokaranam$ jshell
3 | | Welcome to JShell -- Version 9.0.1
4 | | For an introduction type: /help intro
5 |
6 | jshell> class Cart {
7 | ...> };
8 | | created class Cart
9 |
10 | jshell> Cart cart1 = new Cart();
11 | cart1 ==> Cart@3f49dace
12 |
13 | jshell> class Cart {
14 | ...> Cart() {
15 | ...> }
16 | ...> };
17 | | replaced class Cart
18 | | update replaced variable cart1, reset to null
19 |
20 | jshell> Cart cart1 = new Cart();
21 | cart1 ==> Cart@59494225
22 |
23 | jshell> class Cart {
24 | ...> Cart() {
25 | ...> System.out.println("Constructor is called");
26 | ...> }
27 | ...> }
28 | | modified class Cart
29 |
30 | jshell> Cart cart1 = new Cart();
31 | Constructor is called
32 | cart1 ==> Cart@6e1567f1
33 |
34 | jshell>
35 |
--------------------------------------------------------------------------------
/05-IntroductionToObjectOrientedProgramming/src/com/in28minutes/oops/Book.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.oops;
2 |
3 | public class Book {
4 |
5 | private int noOfCopies;
6 |
7 | public Book(int noOfCopies) {
8 | this.noOfCopies = noOfCopies;
9 | }
10 |
11 | public void setNoOfCopies(int noOfCopies) {
12 | if (noOfCopies > 0)
13 | this.noOfCopies = noOfCopies;
14 | }
15 |
16 | public void increaseNoOfCopies(int howMuch) {
17 | setNoOfCopies(this.noOfCopies + howMuch);
18 | }
19 |
20 | public void decreaseNoOfCopies(int howMuch) {
21 | setNoOfCopies(this.noOfCopies - howMuch);
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/05-IntroductionToObjectOrientedProgramming/src/com/in28minutes/oops/BookRunner.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.oops;
2 |
3 | public class BookRunner {
4 |
5 | public static void main(String[] args) {
6 | // Create a new class called Book
7 | // Create three instances
8 | Book artOfComputerProgramming = new Book(100);
9 | Book effectiveJava = new Book(50);
10 | Book cleanCode = new Book(40);
11 |
12 | artOfComputerProgramming.setNoOfCopies(100);
13 | effectiveJava.setNoOfCopies(50);
14 | cleanCode.setNoOfCopies(45);
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/05-IntroductionToObjectOrientedProgramming/src/com/in28minutes/oops/MotorBike.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.oops;
2 |
3 | public class MotorBike {
4 | //state
5 | private int speed; //member variable
6 |
7 |
8 | //constructors
9 | MotorBike() {
10 | this(5);
11 | }
12 |
13 | MotorBike(int speed) {
14 | this.speed = speed;
15 | }
16 |
17 | //behavior
18 | public int getSpeed() {
19 | return speed;
20 | }
21 |
22 | public void setSpeed(int speed) {
23 | if(speed > 0 )
24 | this.speed = speed;
25 | }
26 |
27 | public void increaseSpeed(int howMuch) {
28 | setSpeed(this.speed + howMuch);
29 | }
30 |
31 | public void decreaseSpeed(int howMuch) {
32 | setSpeed(this.speed - howMuch);
33 | }
34 |
35 | void start() {
36 | System.out.println("Bike Started");
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/05-IntroductionToObjectOrientedProgramming/src/com/in28minutes/oops/MotorBikeRunner.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.oops;
2 |
3 | public class MotorBikeRunner {
4 |
5 | public static void main(String[] args) {
6 |
7 | MotorBike ducati = new MotorBike(100);
8 |
9 | MotorBike honda = new MotorBike(200);
10 |
11 | MotorBike somethingElse = new MotorBike();
12 |
13 | System.out.println(ducati.getSpeed());
14 |
15 | System.out.println(honda.getSpeed());
16 |
17 | System.out.println(somethingElse.getSpeed());
18 |
19 |
20 | ducati.start();
21 |
22 | honda.start();
23 |
24 | //ducati.setSpeed(100);
25 |
26 | ducati.increaseSpeed(100);
27 |
28 | honda.increaseSpeed(100);
29 |
30 | ducati.decreaseSpeed(250);
31 |
32 | honda.decreaseSpeed(250);
33 |
34 | System.out.println(ducati.getSpeed());
35 |
36 | System.out.println(honda.getSpeed());
37 | }
38 |
39 | }
40 |
41 | // Create a new class called Book
42 | // Create three instances
43 | // Art Of Computer Programming
44 | // Effective Java
45 | // Clean Code
--------------------------------------------------------------------------------
/06-PrimitiveDataTypesAndAlternatives/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/06-PrimitiveDataTypesAndAlternatives/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | java-primitive-data-types-in-depth
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/06-PrimitiveDataTypesAndAlternatives/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=9
4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5 | org.eclipse.jdt.core.compiler.compliance=9
6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate
8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11 | org.eclipse.jdt.core.compiler.source=9
12 |
--------------------------------------------------------------------------------
/06-PrimitiveDataTypesAndAlternatives/commands.txt:
--------------------------------------------------------------------------------
1 | Byte.SIZE
2 | Byte.BYTES
3 | Byte.MAX_VALUE
4 | Byte.MIN_VALUE
5 | Short.BYTES
6 | Integer.BYTES
7 | Long.BYTES
8 | Integer.MAX_VALUE
9 | Short.MAX_VALUE
10 | Byte.SIZE
11 | Byte.MIN_VALUE
12 | Byte.MAX_VALUE
13 | Short.BYTES
14 | Integer.BYTES
15 | Long.BYTES
16 | Integer.MAX_VALUE
17 | byte c = 13;
18 | long l = 50000000000l;
19 | i = (int) l
20 | l = i
21 | void clear() { System.out.print("\033[H\033[2J ");}
22 | clear()
23 | int eight = 010;
24 | int sixteen = 0x10;
25 | int fifteen = 0XF;
26 | int big = 0XBBAACC;
27 | Short.MAX_VALUE
28 | short s = (short) i;
29 | int i1 = s;
30 | clear()
31 | i
32 | i
33 | i
34 | i
35 | clear()
36 | 34.5
37 | 34.56789
38 | double dbl = 34.5678;
39 | float f2 = (float)dbl;
40 | dbl++
41 | dbl--
42 | dbl % 5
43 | float f = i;
44 | clear()
45 | 34.56789876 + 34.2234
46 | number1.add(number2);
47 | number1
48 | BigDecimal number3 = number1.add(number2);
49 | number1
50 | BigDecimal number1 = new BigDecimal("34.56789876");
51 | BigDecimal number10 = new BigDecimal(34.2234);
52 | BigDecimal number11 = new BigDecimal("34.56789876");
53 | number10.add(number11)
54 | number10.multiply(number11)
55 | clear()
56 | BigDecimal number = new BigDecimal("11.5");
57 | BigDecimal number2 = new BigDecimal("23.45678");
58 | number.add(number2)
59 | number.add(new BigDecimal(i))
60 | number.multiply(new BigDecimal(i))
61 | number.divide(new BigDecimal(100))
62 | number.divide(new BigDecimal("100.01234"))
63 | number.divide(new BigDecimal("100.012"))
64 | number.divide(new BigDecimal("100.12"))
65 | number.divide(new BigDecimal("100.1"))
66 | number.divide(new BigDecimal("1001"))
67 | number.divide(new BigDecimal("100"))
68 | clear()
69 | clear()
70 | clear()
71 | boolean isValue = false;
72 | i > 7
73 | i >= 7
74 | i < 7
75 | i <= 7
76 | i == 6
77 | i == 7
78 | i == 8
79 | i = 8
80 | i = 7
81 | i == 7
82 | clear()
83 | i > 15
84 | clear()
85 | i >= 15
86 | i <= 25
87 | i >= 15 && i <= 25
88 | i = 30
89 | i >= 15 && i <= 25
90 | i = 5
91 | i >= 15 && i <= 25
92 | true && true
93 | true && false
94 | false && true
95 | false && false
96 | false || true
97 | false || true
98 | true || false
99 | true || true
100 | false || false
101 | false ^ false
102 | false ^ true
103 | true ^ false
104 | true ^ true
105 | !true
106 | !false
107 | int x = 6;
108 | !(x>7)
109 | !(x>7)
110 | clear()
111 | true || ++i==11
112 | i
113 | int i = 10;
114 | int j = 15;
115 | j > 15 && i++ > 5
116 | j
117 | i
118 | j > 15 & i++ > 5
119 | j
120 | i
121 | i++;
122 | i++;
123 | clear()
124 | char ch2 = '\u0022';
125 | char ch3 = '\u00A2';
126 | ch++
127 | ch
128 | ++ch
129 | ++ch
130 | ch + 5
131 | ch
132 | (int)ch
133 | ch
134 | System.out.println(ch);
135 | char ch = '\t';
136 | System.out.println(ch);
137 | System.out.println(ch);
138 | (int)'1'
139 | (int)'0'
140 | (int)'9'
141 | (int)'2'
142 | (int)'a'
143 | (int)'z'
144 | (int)'A'
145 | (int)'Z'
146 | for (char ch = 'A'; ch <= 'Z'; ch++) {
147 | System.out.println(ch);
148 |
149 | }
150 | for (char ch = 'A'; ch <= 'Z'; ch++) {
151 | System.out.println(ch);
152 | }
153 | for (char ch = 'A'; ch <= 'C'; ch++) {
154 | System.out.println(ch);
155 | }
--------------------------------------------------------------------------------
/06-PrimitiveDataTypesAndAlternatives/java-primitive-data-types-in-depth/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | java-primitive-data-types-in-depth
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/06-PrimitiveDataTypesAndAlternatives/src/com/in28minutes/primitive/datatypes/BiNumber.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.primitive.datatypes;
2 |
3 | public class BiNumber {
4 | private int number1;
5 | private int number2;
6 |
7 | public int getNumber1() {
8 | return number1;
9 | }
10 |
11 | public void setNumber1(int number1) {
12 | this.number1 = number1;
13 | }
14 |
15 | public int getNumber2() {
16 | return number2;
17 | }
18 |
19 | public void setNumber2(int number2) {
20 | this.number2 = number2;
21 | }
22 |
23 | public BiNumber(int number1, int number2) {
24 | this.number1 = number1;
25 | this.number2 = number2;
26 | }
27 |
28 | public int add() {
29 | return number1 + number2;
30 | }
31 |
32 | public int multiply() {
33 | return number1 * number2;
34 | }
35 |
36 | public void doubleValue() {
37 | this.number1 *= 2;
38 | this.number2 *= 2;
39 | }
40 | }
--------------------------------------------------------------------------------
/06-PrimitiveDataTypesAndAlternatives/src/com/in28minutes/primitive/datatypes/BiNumberRunner.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.primitive.datatypes;
2 |
3 | public class BiNumberRunner {
4 |
5 | public static void main(String[] args) {
6 | BiNumber numbers = new BiNumber(2, 3);
7 |
8 | System.out.println(numbers.add());//2+3
9 | System.out.println(numbers.multiply());//2*3
10 |
11 | numbers.doubleValue();//Double both numbers
12 |
13 | System.out.println(numbers.getNumber1());//4
14 | System.out.println(numbers.getNumber2());//6
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/06-PrimitiveDataTypesAndAlternatives/src/com/in28minutes/primitive/datatypes/MyChar.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.primitive.datatypes;
2 |
3 | public class MyChar {
4 |
5 | private char ch;
6 |
7 | public MyChar(char ch) {
8 | this.ch = ch;
9 | }
10 |
11 | public boolean isVowel() {
12 | //'a' e i o u or A E I O U
13 | if(ch == 'a' || ch == 'A')
14 | return true;
15 |
16 | if(ch == 'e' || ch == 'E')
17 | return true;
18 |
19 | if(ch == 'i' || ch == 'E')
20 | return true;
21 |
22 | if(ch == 'o' || ch == 'O')
23 | return true;
24 |
25 | if(ch == 'u' || ch == 'U')
26 | return true;
27 |
28 | return false;
29 | }
30 |
31 | public boolean isDigit() {
32 | if(ch >= 48 && ch <=57) //between '0' and '9'
33 | return true;
34 |
35 | return false;
36 | }
37 |
38 | public boolean isAlphabet() {
39 | if(ch >= 97 && ch <=122) //between 'a' and 'z'
40 | return true;
41 |
42 | if(ch >= 65 && ch <=90) //between 'A' and 'Z'
43 | return true;
44 |
45 | return false;
46 | }
47 |
48 | public boolean isConsonant() {
49 | //Alphabet and it is not VOWEL
50 | //! [a , e, i ,o , u]
51 | if(isAlphabet() && !isVowel())
52 | return true;
53 |
54 | return false;
55 |
56 | }
57 |
58 | public static void printLowerCaseAlphabets() {
59 | //'a' to 'z'
60 | for (char ch = 'a'; ch <= 'z'; ch++) {
61 | System.out.println(ch);
62 | }
63 | }
64 |
65 | public static void printUpperCaseAlphabets() {
66 | for (char ch = 'A'; ch <= 'Z'; ch++) {
67 | System.out.println(ch);
68 | }
69 |
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/06-PrimitiveDataTypesAndAlternatives/src/com/in28minutes/primitive/datatypes/MyCharRunner.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.primitive.datatypes;
2 |
3 | public class MyCharRunner {
4 |
5 | public static void main(String[] args) {
6 | MyChar myChar = new MyChar('B');
7 | System.out.println(myChar.isVowel());
8 |
9 | //'a', 'e', 'i', 'o', 'u' and Capitals
10 | System.out.println(myChar.isDigit());
11 | System.out.println(myChar.isAlphabet()); //'a' to 'z' or 'A' to 'Z'
12 |
13 | System.out.println(myChar.isConsonant());
14 |
15 | MyChar.printLowerCaseAlphabets();
16 | MyChar.printUpperCaseAlphabets();
17 | }
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/06-PrimitiveDataTypesAndAlternatives/src/com/in28minutes/primitive/datatypes/SimpleInterestCalculator.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.primitive.datatypes;
2 |
3 | import java.math.BigDecimal;
4 |
5 | public class SimpleInterestCalculator {
6 |
7 | BigDecimal principal;
8 |
9 | BigDecimal interest;
10 |
11 | public SimpleInterestCalculator(String principal, String interest) {
12 | this.principal = new BigDecimal(principal);
13 | this.interest = new BigDecimal(interest).divide(new BigDecimal(100));
14 | }
15 |
16 | public BigDecimal calculateTotalValue(int noOfYears) {
17 | // Total Value = principal + principal * interest * noOfYears;
18 | BigDecimal noOfYearsBigDecimal = new BigDecimal(noOfYears);
19 | BigDecimal totalValue = principal.add(principal.multiply(interest).multiply(noOfYearsBigDecimal));
20 | return totalValue;
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/06-PrimitiveDataTypesAndAlternatives/src/com/in28minutes/primitive/datatypes/SimpleInterestCalculatorRunner.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.primitive.datatypes;
2 |
3 | import java.math.BigDecimal;
4 |
5 | public class SimpleInterestCalculatorRunner {
6 |
7 | public static void main(String[] args) {
8 |
9 | SimpleInterestCalculator calculator =
10 | new SimpleInterestCalculator("4500.00", "7.5");
11 | BigDecimal totalValue =
12 | calculator.calculateTotalValue(5);// 5 years
13 | //6187.50000
14 | System.out.println(totalValue);
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/07-Conditionals/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/07-Conditionals/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | conditionals-if-and-switch
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/07-Conditionals/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=9
4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5 | org.eclipse.jdt.core.compiler.compliance=9
6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate
8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11 | org.eclipse.jdt.core.compiler.source=9
12 |
--------------------------------------------------------------------------------
/07-Conditionals/commands.txt:
--------------------------------------------------------------------------------
1 | if(true) {
2 | System.out.println("True");
3 | }
4 | if(false) {
5 | System.out.println("True");
6 | }
7 | if(i==3) {
8 | System.out.println("True");
9 | }
10 | if(i<2) {
11 | System.out.println("True");
12 | }
13 | if(i<=3 || i>=35) {
14 | System.out.println("True");
15 | }
16 | if(i<=3 && i>=35) {
17 | System.out.println("True");
18 | }
19 | if (i==3) {
20 | System.out.println("True");
21 | } else {
22 | System.out.println("i is not 3");
23 | }
24 | i = 5
25 | if (i==3) {
26 | System.out.println("True");
27 | } else {
28 | System.out.println("i is not 3");
29 | }
30 | void clear() { System.out.print("\033[H\033[2J ");}
31 | clear()
32 | if(i==1) {
33 | System.out.println("i");
34 | }
35 | switch (i) {
36 | case 1 : System.out.println("1");
37 | case 5 : System.out.println("5");
38 | default : System.out.println("default");
39 | }
40 | i = 1
41 | switch (i) {
42 | case 1 : System.out.println("1");
43 | case 5 : System.out.println("5");
44 | default : System.out.println("default");
45 | }
46 | switch (i) {
47 | case 1 : System.out.println("1"); break;
48 | case 5 : System.out.println("5"); break;
49 | default : System.out.println("default"); break;
50 | }
51 | clear()
52 | boolean isEven;
53 | int i =5;
54 | if(i%2==0) {
55 | isEven = true;
56 | } else {
57 | isEven = false;
58 | }
59 | isEven
60 | i = 6
61 | if(i%2==0) {
62 | isEven = false;
63 | }
64 | if(i%2==0) {
65 | isEven = true;
66 | } else {
67 | isEven = false;
68 | }
69 | isEven
70 | isEven = ( i%2==0 ? true : false )
71 | i = 6
72 | isEven = ( i%2==0 ? true : false )
73 | i = 7
74 | isEven = ( i%2==0 ? true : false )
75 | i = 6
76 | String even = ( i%2 ==0 ? "YES" : "NO" );
--------------------------------------------------------------------------------
/07-Conditionals/src/com/in28minutes/ifstatement/examples/IfStatementRunner.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.ifstatement.examples;
2 |
3 | public class IfStatementRunner {
4 |
5 | public static void main(String[] args) {
6 | puzzle5();
7 | }
8 |
9 | private static void puzzle1() {
10 | int k = 15;
11 | if (k > 20) {
12 | System.out.println(1);
13 | } else if (k > 10) {
14 | System.out.println(2);
15 | } else if (k < 20) {
16 | System.out.println(3);
17 | } else {
18 | System.out.println(4);
19 | }
20 |
21 | }
22 |
23 | private static void puzzle2() {
24 | int l = 15;
25 |
26 | if (l < 20)
27 | System.out.println("l<20");//
28 | if (l > 20)
29 | System.out.println("l>20");
30 | else
31 | System.out.println("Who am I?");//
32 | }
33 |
34 |
35 |
36 | private static void puzzle3() {
37 | int m = 15;
38 |
39 | if(m>20)
40 | if(m<20)
41 | System.out.println("m>20");
42 | else
43 | System.out.println("Who am I?");
44 | }
45 |
46 |
47 | private static void puzzle5() {
48 | int number = 5;
49 | if(number < 0)
50 | number = number + 10;
51 | number++;
52 | System.out.println(number);
53 | }
54 |
55 | private static void basicNestedIfElse() {
56 | int i = 24;
57 | // i is 25
58 | // i is 24
59 | // i is neither 25 or 24
60 | if (i == 25) {
61 | System.out.println("i = 25");
62 | } else if (i == 24) {
63 | System.out.println("i = 24");
64 | } else if (i == 23) {
65 | System.out.println("i = 23");
66 | } else {
67 | System.out.println("i != 24 and i !=25 and i !=23");
68 | }
69 | }
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/07-Conditionals/src/com/in28minutes/ifstatement/examples/MenuRunner.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.ifstatement.examples;
2 |
3 | import java.util.Scanner;
4 |
5 | public class MenuRunner {
6 | public static void main(String[] args) {
7 | // Type obj = new Type(argument);
8 | Scanner scanner = new Scanner(System.in);
9 | System.out.print("Enter Number1: ");
10 | int number1 = scanner.nextInt();
11 |
12 | System.out.print("Enter Number2: ");
13 | int number2 = scanner.nextInt();
14 |
15 | System.out.println("Choices Available are ");
16 | System.out.println("1 - Add");
17 | System.out.println("2 - Subtract");
18 | System.out.println("3 - Divide");
19 | System.out.println("4 - Multiply");
20 |
21 | System.out.print("Enter Choice: ");
22 | int choice = scanner.nextInt();
23 |
24 | System.out.println("Your Choices are");
25 | System.out.println("Number1 " + number1);
26 | System.out.println("Number2 " + number2);
27 | System.out.println("Choice " + choice);
28 |
29 | performOperationUsingSwitch(number1, number2, choice);
30 | }
31 |
32 | private static void performOperationUsingNestedIfElse(int number1, int number2, int choice) {
33 | if (choice == 1) {
34 | System.out.println("Result " + (number1 + number2));
35 | } else if (choice == 2) {
36 | System.out.println("Result " + (number1 - number2));
37 | } else if (choice == 3) {
38 | System.out.println("Result " + (number1 / number2));
39 | } else if (choice == 4) {
40 | System.out.println("Result " + (number1 * number2));
41 | } else {
42 | System.out.println("Invalid Operation");
43 | }
44 | }
45 |
46 | private static void performOperationUsingSwitch(int number1, int number2, int choice) {
47 | switch (choice) {
48 | case 1:
49 | System.out.println("Result " + (number1 + number2));
50 | break;
51 | case 2:
52 | System.out.println("Result " + (number1 - number2));
53 | break;
54 | case 3:
55 | System.out.println("Result " + (number1 / number2));
56 | break;
57 | case 4:
58 | System.out.println("Result " + (number1 * number2));
59 | break;
60 | default:
61 | System.out.println("Invalid Operation");
62 | break;
63 | }
64 |
65 | }
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/07-Conditionals/src/com/in28minutes/ifstatement/examples/SwitchExercisesRunner.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.ifstatement.examples;
2 |
3 | public class SwitchExercisesRunner {
4 |
5 | public static void main(String[] args) {
6 | System.out.println(isWeekDay(5));
7 | }
8 |
9 | public static boolean isWeekDay(int dayNumber) {
10 | switch(dayNumber) {
11 | //case 0 :
12 | //case 6 : return false;
13 | case 1 :
14 | case 2 :
15 | case 3 :
16 | case 4 :
17 | case 5 : return true;
18 | }
19 |
20 | return false;
21 | }
22 |
23 | public static String determineNameOfDay(int dayNumber) {
24 | switch (dayNumber) {
25 | case 0:
26 | return "Sunday";
27 | case 1:
28 | return "Monday";
29 | case 2:
30 | return "Tuesday";
31 | case 3:
32 | return "Wednesday";
33 | case 4:
34 | return "Thursday";
35 | case 5:
36 | return "Friday";
37 | case 6:
38 | return "Saturday";
39 | }
40 |
41 | return "Invalid_day";
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/07-Conditionals/src/com/in28minutes/ifstatement/examples/SwitchStatementRunner.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.ifstatement.examples;
2 |
3 | public class SwitchStatementRunner {
4 | public static void main(String[] args) {
5 | puzzle4();
6 | }
7 |
8 | private static void puzzle1() {
9 | int number = 2;
10 | switch (number) {
11 | case 1:
12 | System.out.println(1);
13 | case 2:
14 | System.out.println(2);
15 | case 3:
16 | System.out.println(3);
17 | default:
18 | System.out.println("Default");
19 | }
20 | }
21 |
22 | private static void puzzle2() {
23 | int number = 2;
24 | switch (number) {
25 | case 1:
26 | System.out.println(1);
27 | break;
28 | case 2:
29 | case 3:
30 | System.out.println("Number is 2 or 3");
31 | break;
32 | default:
33 | System.out.println("Default");
34 | break;
35 | }
36 | }
37 |
38 | private static void puzzle3() {
39 | int number = 10;
40 | switch (number) {
41 | case 1:
42 | System.out.println(1);
43 | break;
44 | case 2:
45 | System.out.println(2);
46 | break;
47 | case 3:
48 | System.out.println(3);
49 | break;
50 | default:
51 | System.out.println("Default");
52 | break;
53 | }
54 | }
55 |
56 | private static void puzzle4() {
57 | int number = 10;
58 | switch (number) {
59 | default:
60 | System.out.println("Default");
61 | break;
62 | case 1:
63 | System.out.println(1);
64 | break;
65 | case 2:
66 | System.out.println(2);
67 | break;
68 | case 3:
69 | System.out.println(3);
70 | break;
71 | }
72 | }
73 |
74 | private static void puzzle5() {
75 | long l = 15;
76 | /*switch(l){
77 |
78 | }*/
79 | }
80 |
81 | private static void puzzle6() {
82 | int number = 10;
83 | int i = number * 2;
84 | switch (number) {
85 | //case number>5: System.out.println("number>5");
86 | }
87 | }
88 |
89 | }
90 |
--------------------------------------------------------------------------------
/08-Loops/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/08-Loops/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | loops
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/08-Loops/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=9
4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5 | org.eclipse.jdt.core.compiler.compliance=9
6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate
8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11 | org.eclipse.jdt.core.compiler.source=9
12 |
--------------------------------------------------------------------------------
/08-Loops/commands.txt:
--------------------------------------------------------------------------------
1 | void clear() { System.out.print("\033[H\033[2J ");}
2 | clear()
3 | clear()
4 | for (int i = 0; i<= 10; i++) {
5 | System.out.print (i + " ");
6 | }
7 | for (int i = 0; i<= 10; i = i + 2) {
8 | System.out.print (i + " ");
9 | }
10 | for (int i = 1; i<= 10; i = i + 2) {
11 | System.out.print (i + " ");
12 | }
13 | for (int i = 11; i<= 10; i = i + 2) {
14 | System.out.print (i + " ");
15 | }
16 | for (int i = 11; i<= 20;) {
17 | System.out.print (i + " ");
18 | i++;
19 | }
20 | for (; i<= 30;i++) {
21 | System.out.print (i + " ");
22 | }
23 | clear()
24 | 9 % 2
25 | 9 % 3
26 | clear()
27 | if (i>2) {
28 | System.out.println("i>2");
29 | }
30 | int i = 3;
31 | if (i>2) {
32 | System.out.println("i>2");
33 | }
34 | i = 0
35 | while (i <5) {
36 | System.out.println(i);
37 | i++;
38 | }
39 | i
40 | i = 6
41 | while (i < 5) {
42 | System.out.println(i);
43 | i++;
44 | }
45 | i = -2
46 | while (i < 5) {
47 | System.out.println(i);
48 | }
49 | while (i < 5) {
50 | System.out.println(i);
51 | i++;
52 | }
53 | i
54 | clear()
55 | while (i < 5) {
56 | System.out.print(i + " ");
57 | i++;
58 | }
59 | i
60 | i = 1
61 | do {
62 | System.out.print(i + " ");
63 | i++;
64 | } while (i<5);
65 | i = 10
66 | while (i < 5) {
67 | System.out.print(i + " ");
68 | i++;
69 | }
70 | do {
71 | System.out.print(i + " ");
72 | i++;
73 | } while (i<5);
74 | clear()
75 | for(i=1;i<=10;i++) {
76 | if(i==5)
77 | break;
78 | System.out.print(i + " ");
79 | }
80 | for(i=1;i<=10;i++) {
81 | if(i%2==0)
82 | break;
83 | System.out.print(i + " ");
84 | }
85 | for(i=1;i<=10;i++) {
86 | if(i%2==0)
87 | continue;
88 | System.out.print(i + " ");
89 | }
90 | for(i=1;i<=10;i++) {
91 | if(i%2!=0)
92 | continue;
93 | System.out.print(i + " ");
94 | }
--------------------------------------------------------------------------------
/08-Loops/src/com/in28minutes/loops/DoWhileRepeatedQuestionRunner.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.loops;
2 |
3 | import java.util.Scanner;
4 |
5 | public class DoWhileRepeatedQuestionRunner {
6 |
7 | public static void main(String[] args) {
8 |
9 | Scanner scanner = new Scanner(System.in);
10 | int number = -1;
11 |
12 | do {
13 | if (number != -1) {
14 | System.out.println("Cube is " + (number * number * number));
15 | }
16 | System.out.print("Enter a number: ");
17 | number = scanner.nextInt();
18 | } while (number >= 0);
19 | System.out.print("Thank You! Have Fun!");
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/08-Loops/src/com/in28minutes/loops/MyNumber.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.loops;
2 |
3 | public class MyNumber {
4 |
5 | private int number;
6 |
7 | public MyNumber(int number) {
8 | this.number = number;
9 | }
10 |
11 | public boolean isPrime() {
12 | // 2 to number-1
13 | // How can check if a number is divisible by 2?
14 |
15 | if (number < 2) {
16 | return false;
17 | }
18 |
19 | for (int i = 2; i <= number - 1; i++) {
20 | if (number % i == 0) {
21 | return false;
22 | }
23 | }
24 |
25 | return true;
26 | }
27 |
28 | public int sumUptoN() {
29 | int sum = 0;
30 |
31 | for (int i = 1; i <= number; i++) {
32 | sum = sum + i;
33 | }
34 |
35 | return sum;
36 | }
37 |
38 | public int sumOfDivisors() {
39 | // 6 except 1 , 6 => 2,3
40 | // 2 + 3 + 4 + 5
41 |
42 | int sum = 0;
43 |
44 | for (int i = 2; i <= number - 1; i++) {
45 | if (number % i == 0) {
46 | sum = sum + i;
47 | }
48 | }
49 |
50 | return sum;
51 | }
52 |
53 | public void printNumberTriangle() {
54 | // 1
55 | // 1 2
56 | // 1 2 3
57 | // 1 2 3 4
58 | // 1 2 3 4 5
59 |
60 | for (int i = 1; i <= number; i++) {
61 | for (int j = 1; j <= i; j++) {
62 | System.out.print(j + " ");
63 | }
64 | System.out.println();
65 | }
66 |
67 | }
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/08-Loops/src/com/in28minutes/loops/MyNumberRunner.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.loops;
2 |
3 | import com.in28minutes.loops.MyNumber;
4 |
5 | public class MyNumberRunner {
6 |
7 | public static void main(String[] args) {
8 | MyNumber number = new MyNumber(5);
9 |
10 | boolean isPrime = number.isPrime();
11 | System.out.println("isPrime " + isPrime);
12 |
13 | int sum = number.sumUptoN();
14 | System.out.println("sumUptoN " + sum);
15 |
16 | int sumOfDivisors = number.sumOfDivisors();
17 | System.out.println("sumOfDivisors " + sumOfDivisors);
18 |
19 | number.printNumberTriangle();
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/08-Loops/src/com/in28minutes/loops/WhileNumberPlayer.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.loops;
2 |
3 | public class WhileNumberPlayer {
4 |
5 | private int limit;
6 |
7 | public WhileNumberPlayer(int limit) {
8 | this.limit = limit;
9 | }
10 |
11 | // For limit = 30, output would be 1 4 9 16 25
12 | public void printSquaresUptoLimit() {
13 | int i = 1;
14 | while (i * i < limit) {
15 | System.out.print(i * i + " ");
16 | i++;
17 | }
18 | System.out.println();
19 | }
20 |
21 | // For limit = 27, output would be 1 8 27
22 | public void printCubesUptoLimit() {
23 | int i = 1;
24 | while (i * i * i <= limit) {
25 | System.out.print(i * i * i + " ");
26 | i++;
27 | }
28 | System.out.println();
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/08-Loops/src/com/in28minutes/loops/WhileNumberPlayerRunner.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.loops;
2 |
3 | public class WhileNumberPlayerRunner {
4 | public static void main(String[] args) {
5 | WhileNumberPlayer player = new WhileNumberPlayer(27);
6 | player.printSquaresUptoLimit();
7 | player.printCubesUptoLimit();
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/10-ArraysAndArrayList/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/10-ArraysAndArrayList/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | introduction-to-array-and-arraylist
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/10-ArraysAndArrayList/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=9
4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5 | org.eclipse.jdt.core.compiler.compliance=9
6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate
8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11 | org.eclipse.jdt.core.compiler.source=9
12 |
--------------------------------------------------------------------------------
/10-ArraysAndArrayList/01-after-variable-arguments.md:
--------------------------------------------------------------------------------
1 |
4 |
5 | ## Complete Code Example
6 |
7 |
8 | ### /src/com/in28minutes/arrays/Student.java
9 |
10 | ```java
11 | package com.in28minutes.arrays;
12 |
13 | import java.math.BigDecimal;
14 | import java.math.RoundingMode;
15 |
16 | public class Student {
17 |
18 | private String name;
19 | private int[] marks;
20 |
21 | public Student(String name, int... marks) {
22 | this.name = name;
23 | this.marks = marks;
24 | }
25 |
26 | public int getNumberOfMarks() {
27 | return marks.length;
28 | }
29 |
30 | public int getTotalSumOfMarks() {
31 | int sum = 0;
32 | for (int mark : marks) {
33 | sum += mark;
34 | }
35 | return sum;
36 | }
37 |
38 | public int getMaximumMark() {
39 | int maximum = Integer.MIN_VALUE; // 95, 98, 10
40 | for (int mark : marks) {
41 | if (mark > maximum) {
42 | maximum = mark;
43 | }
44 | }
45 | return maximum;
46 | }
47 |
48 | public int getMinimumMark() {
49 | int minimum = Integer.MAX_VALUE; // 95, 98, 10
50 | for (int mark : marks) {
51 | if (mark < minimum) {
52 | minimum = mark;
53 | }
54 | }
55 | return minimum;
56 | }
57 |
58 | public BigDecimal getAverageMarks() {
59 | int sum = getTotalSumOfMarks();
60 | int number = getNumberOfMarks();
61 |
62 | return new BigDecimal(sum).divide(new BigDecimal(number), 3, RoundingMode.UP);
63 | }
64 |
65 | }
66 | ```
67 | ---
68 |
69 | ### /src/com/in28minutes/arrays/StudentRunner.java
70 |
71 | ```java
72 | package com.in28minutes.arrays;
73 |
74 | import java.math.BigDecimal;
75 |
76 | public class StudentRunner {
77 |
78 | public static void main(String[] args) {
79 |
80 | Student student = new Student("Ranga", 97, 98, 100);
81 |
82 | int number = student.getNumberOfMarks();
83 | System.out.println("number of marks : " + number);
84 |
85 | int sum = student.getTotalSumOfMarks();
86 | System.out.println("sum of marks : " + sum);
87 |
88 | int maximumMark = student.getMaximumMark();
89 | System.out.println("maximum of marks : " + maximumMark);
90 |
91 | int minimumMark = student.getMinimumMark();
92 | System.out.println("minimum of marks : " + minimumMark);
93 |
94 | BigDecimal average = student.getAverageMarks();
95 | System.out.println("average : " + average);
96 |
97 | }
98 |
99 | }
100 | ```
101 | ---
102 |
--------------------------------------------------------------------------------
/10-ArraysAndArrayList/commands.txt:
--------------------------------------------------------------------------------
1 | int mark1;
2 | mark1 = 100
3 | int mark2 = 75;
4 | int mark3 = 60;
5 | int mark4 = 56;
6 | sum = mark1 + mark2 + mark3 + mark4;
7 | for(int mark:marks)
8 | sum+= mark;
9 | sum;
10 | sum
11 | for(int mark:marks)
12 | sum+= mark;
13 | sum
14 | int sum = 0;
15 | for(int mark:marks) {
16 | sum = sum + mark;
17 | }
18 | sum
19 | void clear() { System.out.print("\033[H\033[2J ");}
20 | clear()
21 | marks[0]
22 | marks3[0]
23 | marks3[0] = 10
24 | marks3[0]
25 | marks3[0] = 1
26 | marks3[1] = 2
27 | marks3[2] = 3
28 | marks3[3] = 4
29 | marks3[4] = 5
30 | marks3
31 | marks2
32 | int[] marks2 = {1,2,3,4,5};
33 | int[] marks3 = new int[5];
34 | marks2.length
35 | marks.length
36 | marks3.length
37 | clear()
38 | marks.length
39 | for(int i=0; i< marks.length-1; i++) {
40 | System.out.println(marks[i]);
41 | }
42 | for(int i=0; i< marks.length; i++) {
43 | System.out.println(marks[i]);
44 | }
45 | clear()
46 | double[] values = new double[5];
47 | boolean[] test = new boolean[5];
48 | marks[6]
49 | System.out.println(marks);
50 | System.out.println(Arrays.toString(marks));
51 | clear()
52 | for(int mark:marks)
53 | System.out.println(mark);
54 | for(int i=0; i items = new ArrayList();
119 | items.add("Apple");
120 | items.add("Bat")
121 | items.add("Cat")
122 | items
123 | items.remove("Cat")
124 | items
125 | items.remove(0)
126 | items
--------------------------------------------------------------------------------
/10-ArraysAndArrayList/src/com/in28minutes/arrays/StringRunner.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.arrays;
2 |
3 | public class StringRunner {
4 |
5 | public static void main(String[] args) {
6 |
7 | String[] daysOfWeek = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
8 |
9 | String dayWithMostCharacters = "";
10 |
11 | for (String day : daysOfWeek) {
12 | if (day.length() > dayWithMostCharacters.length()) {
13 | dayWithMostCharacters = day;
14 | }
15 | }
16 |
17 | System.out.println("Day with Most number of characters " + dayWithMostCharacters);
18 |
19 | for (int i = daysOfWeek.length - 1; i >= 0; i--) {
20 | System.out.println(daysOfWeek[i]);
21 | }
22 |
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/10-ArraysAndArrayList/src/com/in28minutes/arrays/Student.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.arrays;
2 |
3 | import java.math.BigDecimal;
4 | import java.math.RoundingMode;
5 | import java.util.ArrayList;
6 | import java.util.Collections;
7 |
8 | public class Student {
9 |
10 | private String name;
11 | private ArrayList marks = new ArrayList();
12 |
13 | public Student(String name, int... marks) {
14 | this.name = name;
15 |
16 | for (int mark : marks) {
17 | this.marks.add(mark);
18 | }
19 | }
20 |
21 | public int getNumberOfMarks() {
22 | return marks.size();
23 | }
24 |
25 | public int getTotalSumOfMarks() {
26 | int sum = 0;
27 | for (int mark : marks) {
28 | sum += mark;
29 | }
30 | return sum;
31 | }
32 |
33 | public int getMaximumMark() {
34 | return Collections.max(marks);
35 | }
36 |
37 | public int getMinimumMark() {
38 | return Collections.min(marks);
39 | }
40 |
41 | public BigDecimal getAverageMarks() {
42 | int sum = getTotalSumOfMarks();
43 | int number = getNumberOfMarks();
44 |
45 | return new BigDecimal(sum).divide(new BigDecimal(number), 3, RoundingMode.UP);
46 | }
47 |
48 | public String toString() {
49 | return name + marks;
50 | }
51 |
52 | public void addNewMark(int mark) {
53 | marks.add(mark);
54 | }
55 |
56 | public void removeMarkAtIndex(int index) {
57 | marks.remove(index);
58 |
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/10-ArraysAndArrayList/src/com/in28minutes/arrays/StudentRunner.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.arrays;
2 |
3 | import java.math.BigDecimal;
4 |
5 | public class StudentRunner {
6 |
7 | public static void main(String[] args) {
8 |
9 | Student student = new Student("Ranga", 97, 98, 100);
10 |
11 | int number = student.getNumberOfMarks();
12 | System.out.println("number of marks : " + number);
13 |
14 | int sum = student.getTotalSumOfMarks();
15 | System.out.println("sum of marks : " + sum);
16 |
17 | int maximumMark = student.getMaximumMark();
18 | System.out.println("maximum of marks : " + maximumMark);
19 |
20 | int minimumMark = student.getMinimumMark();
21 | System.out.println("minimum of marks : " + minimumMark);
22 |
23 | BigDecimal average = student.getAverageMarks();
24 | System.out.println("average : " + average);
25 |
26 | System.out.println(student);
27 |
28 | student.addNewMark(35);
29 |
30 | System.out.println(student);
31 |
32 | student.removeMarkAtIndex(1);
33 |
34 | System.out.println(student);
35 |
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/11-ObjectOrientedProgrammingAgain/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/11-ObjectOrientedProgrammingAgain/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | object-oriented-programming-2
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/11-ObjectOrientedProgrammingAgain/commands.txt:
--------------------------------------------------------------------------------
1 | class Pet extends Animal {
2 | public void groom() {
3 | System.out.println("Groom");
4 | }
5 | }
6 | dog.toString()
7 | dog.groom()
8 | Pet pet = new Dog();
9 | pet.groom()
10 | pet instanceof Pet
11 | pet instanceof Dog
12 | pet instanceof Animal
13 | pet instanceof Object
14 | animal instanceof Pet
15 | animal instanceof Dog
16 | animal instanceof Object
17 | void clear() { System.out.print("\033[H\033[2J ");}
18 | clear()
19 | class Animal {
20 | public void bark() {
21 | System.out.println("TEst");
22 | }
23 | }
24 | animal.bark()
25 | abstract class AbstractAnimal {
26 | abstract public void bark();
27 | }
28 | class Dog extends AbstractAnimal {
29 | public void bark() {
30 | System.out.println("Bow Bow");
31 | }
32 | }
33 | Dog dog = new Dog();
34 | dog.bark()
35 | clear()
36 | abstract class AbstractTest {
37 | }
38 | abstract class Algorithm1 extends AbstractAlgorithm {
39 | }
40 | abstract class AbstractAlgorithm {
41 | private int stepCount;
42 | public int getStepCount() {
43 | return stepCount();
44 | }
45 | }
46 | clear()
47 | class Implementation implements Interface2 {
48 | public void method2() { }
49 | public void method1() { }
50 | }
51 | abstract class ImplementationAbstract implements Interface2 {
52 | public void method1() { }
53 | }
54 | interface Interface3 {
55 | int test = 5;
56 | }
57 | interface Interface4 {
58 | default void print() {
59 | System.out.println("default");
60 | }
61 | }
62 | class Test implements Interface4 {
63 | }
64 | test.print()
65 | class Test1 implements Interface4 {
66 | public void print() {
67 | System.out.println("override");
68 | }
69 | }
70 | Test1 test = new Test1();
71 | test.print()
72 | interface Interface1 {
73 | void method1();
74 | }
75 | interface Interface2 {
76 | void method2();
77 | }
78 | clear()
--------------------------------------------------------------------------------
/11-ObjectOrientedProgrammingAgain/src/com/in28minutes/oops/level2/AbstractRecipe.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.oops.level2;
2 |
3 | public abstract class AbstractRecipe {
4 |
5 | public void execute() {
6 | getReady();
7 | doTheDish();
8 | cleanup();
9 | }
10 |
11 | abstract void getReady();
12 | abstract void doTheDish();
13 | abstract void cleanup();
14 | }
15 |
--------------------------------------------------------------------------------
/11-ObjectOrientedProgrammingAgain/src/com/in28minutes/oops/level2/Address.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.oops.level2;
2 |
3 | public class Address {
4 | private String line1;
5 | private String city;
6 | private String zip;
7 |
8 | //creation
9 | public Address(String line1, String city, String zip) {
10 | super();
11 | this.line1 = line1;
12 | this.city = city;
13 | this.zip = zip;
14 | }
15 |
16 | public String toString() {
17 | return line1 + " " + city + " " + zip;
18 |
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/11-ObjectOrientedProgrammingAgain/src/com/in28minutes/oops/level2/Book.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.oops.level2;
2 |
3 | import java.util.ArrayList;
4 |
5 | public class Book {
6 |
7 | private int id;
8 | private String name;
9 | private String author;
10 | private ArrayList reviews = new ArrayList<>();
11 |
12 | public Book(int id, String name, String author) {
13 | this.id = id;
14 | this.name = name;
15 | this.author = author;
16 | }
17 |
18 | public void addReview(Review review) {
19 | this.reviews.add(review);
20 | }
21 |
22 | public String toString() {
23 | return String.format("id =%d name = %s author = %s Reviews = [%s]",
24 | id, name, author, reviews);
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/11-ObjectOrientedProgrammingAgain/src/com/in28minutes/oops/level2/BookRunner.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.oops.level2;
2 |
3 | public class BookRunner {
4 |
5 | public static void main(String[] args) {
6 | Book book = new Book(123, "Object Oriented Programming with Java",
7 | "Ranga");
8 | book.addReview(new Review(10, "Great Book", 5));
9 | book.addReview(new Review(101, "Awesome", 5));
10 |
11 | System.out.println(book);
12 |
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/11-ObjectOrientedProgrammingAgain/src/com/in28minutes/oops/level2/Customer.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.oops.level2;
2 |
3 | public class Customer {
4 |
5 | //state
6 | private String name;
7 | private Address homeAddress;
8 | private Address workAddress;
9 |
10 | //creating
11 | public Customer(String name, Address homeAddress) {
12 | this.name = name;
13 | this.homeAddress = homeAddress;
14 | }
15 |
16 | //operations
17 | public Address getHomeAddress() {
18 | return homeAddress;
19 | }
20 |
21 | public void setHomeAddress(Address homeAddress) {
22 | this.homeAddress = homeAddress;
23 | }
24 |
25 | public Address getWorkAddress() {
26 | return workAddress;
27 | }
28 |
29 | public void setWorkAddress(Address workAddress) {
30 | this.workAddress = workAddress;
31 | }
32 |
33 | public String toString() {
34 | return String.format("name - [%s] home address - [%s] work address - [%s])"
35 | , name, homeAddress, workAddress);
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/11-ObjectOrientedProgrammingAgain/src/com/in28minutes/oops/level2/CustomerRunner.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.oops.level2;
2 |
3 | public class CustomerRunner {
4 |
5 | public static void main(String[] args) {
6 | Address homeAddress = new Address("line 1", "Hyderabad", "500035");
7 | Customer customer = new Customer("Ranga", homeAddress);
8 | System.out.println(customer);
9 |
10 | Address workAddress = new Address("line 1 for work", "Hyderabad", "500078");
11 | customer.setWorkAddress(workAddress);
12 |
13 | System.out.println(customer);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/11-ObjectOrientedProgrammingAgain/src/com/in28minutes/oops/level2/Fan.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.oops.level2;
2 |
3 | public class Fan {
4 |
5 | //state
6 | private String make;
7 | private double radius;
8 | private String color;
9 |
10 | private boolean isOn;
11 | private byte speed; //0 to 5
12 |
13 | //creation
14 | public Fan(String make, double radius, String color) {
15 | this.make = make;
16 | this.radius = radius;
17 | this.color = color;
18 | }
19 |
20 | public void switchOn() {
21 | this.isOn = true;
22 | setSpeed((byte)5);
23 | }
24 |
25 | public void switchOff() {
26 | this.isOn = false;
27 | setSpeed((byte)0);
28 | }
29 |
30 | public void setSpeed(byte speed) {
31 | this.speed = speed;
32 | }
33 |
34 | //print the state
35 | public String toString() {
36 | return String.format("make - %s, radius - %f , color - %s , isOn - %b , speed - %d",
37 | make, radius, color, isOn, speed);
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/11-ObjectOrientedProgrammingAgain/src/com/in28minutes/oops/level2/FanRunner.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.oops.level2;
2 |
3 | public class FanRunner {
4 | public static void main(String[] args) {
5 | Fan fan = new Fan("Manufacturer 1", 0.34567, "GREEN");
6 | fan.switchOn();
7 | System.out.println(fan);
8 | fan.setSpeed((byte)3);
9 | System.out.println(fan);
10 | fan.switchOff();
11 | System.out.println(fan);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/11-ObjectOrientedProgrammingAgain/src/com/in28minutes/oops/level2/Recipe1.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.oops.level2;
2 |
3 | public class Recipe1 extends AbstractRecipe{
4 |
5 | @Override
6 | void getReady() {
7 | System.out.println("Get the raw materials");
8 | System.out.println("Get the utensils");
9 | }
10 |
11 | @Override
12 | void doTheDish() {
13 | System.out.println("do the dish");
14 | }
15 |
16 | @Override
17 | void cleanup() {
18 | System.out.println("Cleanup the utensils");
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/11-ObjectOrientedProgrammingAgain/src/com/in28minutes/oops/level2/RecipeRunner.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.oops.level2;
2 |
3 | public class RecipeRunner {
4 |
5 | public static void main(String[] args) {
6 | Recipe1 recipe = new Recipe1();
7 | recipe.execute();
8 |
9 | RecipeWithMicrowave recipeWithMicrowave = new RecipeWithMicrowave();
10 | recipeWithMicrowave.execute();
11 |
12 | }
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/11-ObjectOrientedProgrammingAgain/src/com/in28minutes/oops/level2/RecipeWithMicrowave.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.oops.level2;
2 |
3 | public class RecipeWithMicrowave extends AbstractRecipe{
4 |
5 | @Override
6 | void getReady() {
7 | System.out.println("Get the raw materials");
8 | System.out.println("Switch on the microwave");
9 | }
10 |
11 | @Override
12 | void doTheDish() {
13 | System.out.println("get stuff ready");
14 | System.out.println("Put it in the microwave");
15 | }
16 |
17 | @Override
18 | void cleanup() {
19 | System.out.println("Cleanup the utensils");
20 | System.out.println("Switch off the microwave");
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/11-ObjectOrientedProgrammingAgain/src/com/in28minutes/oops/level2/Rectangle.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.oops.level2;
2 |
3 | public class Rectangle {
4 |
5 | //state
6 | private int length;
7 | private int width;
8 |
9 | //creation
10 | public Rectangle(int length, int width) {
11 | this.length = length;
12 | this.width = width;
13 | }
14 |
15 |
16 | //operations
17 | public int getLength() {
18 | return length;
19 | }
20 |
21 | public void setLength(int length) {
22 | this.length = length;
23 | }
24 |
25 | public int getWidth() {
26 | return width;
27 | }
28 |
29 | public void setWidth(int width) {
30 | this.width = width;
31 | }
32 |
33 | public int area() {
34 | return length * width;
35 | }
36 |
37 | public int perimeter() {
38 | return 2 * (length + width);
39 | }
40 |
41 | public String toString() {
42 | return String.format("length - %d width - %d area - %d perimeter - %d",
43 | length, width, area(), perimeter());
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/11-ObjectOrientedProgrammingAgain/src/com/in28minutes/oops/level2/RectangleRunner.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.oops.level2;
2 |
3 | public class RectangleRunner {
4 |
5 | public static void main(String[] args) {
6 | Rectangle rectangle = new Rectangle(12, 23);
7 | System.out.println(rectangle);
8 | rectangle.setWidth(25);
9 | System.out.println(rectangle);
10 | }
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/11-ObjectOrientedProgrammingAgain/src/com/in28minutes/oops/level2/Review.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.oops.level2;
2 |
3 | public class Review {
4 |
5 | private int id;
6 | private String description;
7 | private int rating;
8 |
9 | public Review(int id, String description, int rating) {
10 | this.id = id;
11 | this.description = description;
12 | this.rating = rating;
13 | }
14 |
15 | public String toString() {
16 | return id + " " + description + " " + rating;
17 | }
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/11-ObjectOrientedProgrammingAgain/src/com/in28minutes/oops/level2/inheritance/AnimalRunner.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.oops.level2.inheritance;
2 |
3 | abstract class Animal {
4 | abstract void bark();
5 | }
6 |
7 | class Dog extends Animal {
8 | public void bark() {
9 | System.out.println("Bow Bow");
10 | }
11 | }
12 |
13 | class Cat extends Animal {
14 | public void bark() {
15 | System.out.println("Meow Meow");
16 | }
17 | }
18 |
19 | public class AnimalRunner {
20 | public static void main(String[] args) {
21 | Animal[] animals = {new Cat(), new Dog()};
22 | for(Animal animal:animals) {
23 | animal.bark();
24 | }
25 |
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/11-ObjectOrientedProgrammingAgain/src/com/in28minutes/oops/level2/inheritance/Employee.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.oops.level2.inheritance;
2 |
3 | import java.math.BigDecimal;
4 |
5 | public class Employee extends Person {
6 | private String title;
7 | private String employerName;
8 | private char employeeGrade;
9 | private BigDecimal salary;
10 |
11 | public Employee(String name, String title) {
12 | super(name);
13 | this.title = title;
14 | System.out.println("Employee Constructor");
15 | }
16 |
17 | public String getTitle() {
18 | return title;
19 | }
20 |
21 | public void setTitle(String title) {
22 | this.title = title;
23 | }
24 |
25 | public String getEmployerName() {
26 | return employerName;
27 | }
28 |
29 | public void setEmployerName(String employerName) {
30 | this.employerName = employerName;
31 | }
32 |
33 | public char getEmployeeGrade() {
34 | return employeeGrade;
35 | }
36 |
37 | public void setEmployeeGrade(char employeeGrade) {
38 | this.employeeGrade = employeeGrade;
39 | }
40 |
41 | public BigDecimal getSalary() {
42 | return salary;
43 | }
44 |
45 | public void setSalary(BigDecimal salary) {
46 | this.salary = salary;
47 | }
48 |
49 | public String toString() {
50 | return super.toString() + "#" + title + "#" + employerName + "#" + employeeGrade;
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/11-ObjectOrientedProgrammingAgain/src/com/in28minutes/oops/level2/inheritance/Person.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.oops.level2.inheritance;
2 |
3 | public class Person extends Object{
4 | private String name;
5 | private String email;
6 | private String phoneNumber;
7 |
8 | public Person(String name) {
9 | System.out.println("Person Constructor");
10 | this.name = name;
11 | }
12 |
13 | public String getName() {
14 | return name;
15 | }
16 |
17 | public String getEmail() {
18 | return email;
19 | }
20 |
21 | public void setEmail(String email) {
22 | this.email = email;
23 | }
24 |
25 | public String getPhoneNumber() {
26 | return phoneNumber;
27 | }
28 |
29 | public void setPhoneNumber(String phoneNumber) {
30 | this.phoneNumber = phoneNumber;
31 | }
32 |
33 | public String toString() {
34 | return name + "#" + email + "#" + phoneNumber;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/11-ObjectOrientedProgrammingAgain/src/com/in28minutes/oops/level2/inheritance/Student.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.oops.level2.inheritance;
2 |
3 | public class Student extends Person {
4 | private String collegeName;
5 | private int year;
6 |
7 | public Student(String name, String collegeName) {
8 | super(name);
9 | this.collegeName = collegeName;
10 | }
11 |
12 | public String getCollegeName() {
13 | return collegeName;
14 | }
15 |
16 | public void setCollegeName(String collegeName) {
17 | this.collegeName = collegeName;
18 | }
19 |
20 | public int getYear() {
21 | return year;
22 | }
23 |
24 | public void setYear(int year) {
25 | this.year = year;
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/11-ObjectOrientedProgrammingAgain/src/com/in28minutes/oops/level2/inheritance/StudentRunner.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.oops.level2.inheritance;
2 |
3 | public class StudentRunner {
4 |
5 | public static void main(String[] args) {
6 |
7 | //Student student = new Student();
8 | //student.setName("Ranga");
9 | //student.setEmail("in28minutes@gmail.com");
10 |
11 | /*
12 | Person person = new Person();
13 | person.setName("Ranga");
14 | person.setEmail("ranga@in28minutes.com");
15 | person.setPhoneNumber("123-456-7890");
16 | String value = person.toString();
17 | System.out.println(value);
18 | System.out.println(person);
19 | */
20 |
21 | Employee employee = new Employee("Ranga", "Programmer Analyst");
22 | //employee.setName("Ranga");
23 | employee.setEmail("ranga@in28minutes.com");
24 | employee.setPhoneNumber("123-456-7890");
25 | employee.setEmployeeGrade('A');
26 | employee.setTitle("Programmer Analyst");
27 |
28 | System.out.print(employee);
29 |
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/11-ObjectOrientedProgrammingAgain/src/com/in28minutes/oops/level2/inheritance/StudentWithoutInheritance.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.oops.level2.inheritance;
2 |
3 | public class StudentWithoutInheritance {
4 | private String name;
5 | private String email;
6 | private String phoneNumber;
7 |
8 | private String college;
9 | private int year;
10 |
11 | public String getName() {
12 | return name;
13 | }
14 |
15 | public void setName(String name) {
16 | this.name = name;
17 | }
18 |
19 | public String getEmail() {
20 | return email;
21 | }
22 |
23 | public void setEmail(String email) {
24 | this.email = email;
25 | }
26 |
27 | public String getPhoneNumber() {
28 | return phoneNumber;
29 | }
30 |
31 | public void setPhoneNumber(String phoneNumber) {
32 | this.phoneNumber = phoneNumber;
33 | }
34 |
35 | public String getCollege() {
36 | return college;
37 | }
38 |
39 | public void setCollege(String college) {
40 | this.college = college;
41 | }
42 |
43 | public int getYear() {
44 | return year;
45 | }
46 |
47 | public void setYear(int year) {
48 | this.year = year;
49 | }
50 |
51 |
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/11-ObjectOrientedProgrammingAgain/src/com/in28minutes/oops/level2/interfaces/ChessGame.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.oops.level2.interfaces;
2 |
3 | public class ChessGame implements GamingConsole{
4 |
5 | @Override
6 | public void up() {
7 | System.out.println("Move piece up");
8 | }
9 |
10 | @Override
11 | public void down() {
12 | System.out.println("Move piece down");
13 | }
14 |
15 | @Override
16 | public void left() {
17 | System.out.println("Move piece left");
18 | }
19 |
20 | @Override
21 | public void right() {
22 | System.out.println("Move piece right");
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/11-ObjectOrientedProgrammingAgain/src/com/in28minutes/oops/level2/interfaces/ComplexAlgorithm.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.oops.level2.interfaces;
2 |
3 | public interface ComplexAlgorithm {
4 | int complexAlgorithm(int number1, int number2);
5 | }
6 |
--------------------------------------------------------------------------------
/11-ObjectOrientedProgrammingAgain/src/com/in28minutes/oops/level2/interfaces/DummyAlgorithm.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.oops.level2.interfaces;
2 |
3 | public class DummyAlgorithm implements ComplexAlgorithm{
4 |
5 | @Override
6 | public int complexAlgorithm(int number1, int number2) {
7 | return number1 + number2;
8 | }
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/11-ObjectOrientedProgrammingAgain/src/com/in28minutes/oops/level2/interfaces/FlyableRunner.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.oops.level2.interfaces;
2 |
3 | interface Flyable{
4 | void fly();
5 | }
6 |
7 | class Bird implements Flyable{
8 |
9 | @Override
10 | public void fly() {
11 | System.out.println("with wings");
12 | }
13 |
14 | }
15 |
16 | class Aeroplane implements Flyable{
17 |
18 | @Override
19 | public void fly() {
20 | System.out.println("with fuel");
21 | }
22 |
23 | }
24 |
25 | public class FlyableRunner {
26 |
27 | public static void main(String[] args) {
28 | Flyable[] flyingObjects = { new Bird(), new Aeroplane()};
29 | for(Flyable object : flyingObjects) {
30 | object.fly();
31 | }
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/11-ObjectOrientedProgrammingAgain/src/com/in28minutes/oops/level2/interfaces/GameRunner.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.oops.level2.interfaces;
2 |
3 | public class GameRunner {
4 |
5 | public static void main(String[] args) {
6 | GamingConsole[] games = {new MarioGame(), new ChessGame()};
7 |
8 | for(GamingConsole game:games) {
9 | game.up();
10 | game.down();
11 | game.left();
12 | game.right();
13 | }
14 |
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/11-ObjectOrientedProgrammingAgain/src/com/in28minutes/oops/level2/interfaces/GamingConsole.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.oops.level2.interfaces;
2 |
3 | public interface GamingConsole {
4 | public void up();
5 | public void down();
6 | public void left();
7 | public void right();
8 | }
9 |
--------------------------------------------------------------------------------
/11-ObjectOrientedProgrammingAgain/src/com/in28minutes/oops/level2/interfaces/MarioGame.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.oops.level2.interfaces;
2 |
3 | public class MarioGame implements GamingConsole{
4 |
5 | @Override
6 | public void up() {
7 | System.out.println("Jump");
8 | }
9 |
10 | @Override
11 | public void down() {
12 | System.out.println("Goes into a hole");
13 | }
14 |
15 | @Override
16 | public void left() {
17 | }
18 |
19 | @Override
20 | public void right() {
21 | System.out.println("Go Forward");
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/11-ObjectOrientedProgrammingAgain/src/com/in28minutes/oops/level2/interfaces/Project.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.oops.level2.interfaces;
2 |
3 | public class Project {
4 |
5 | interface Test {
6 | void nothing();
7 |
8 | default void nothing1() {
9 |
10 | }
11 |
12 | }
13 |
14 | class Class1 implements Test {
15 |
16 | @Override
17 | public void nothing() {
18 | // TODO Auto-generated method stub
19 |
20 | }
21 |
22 | }
23 |
24 | class Class2 implements Test {
25 |
26 | @Override
27 | public void nothing() {
28 | // TODO Auto-generated method stub
29 |
30 | }
31 |
32 | }
33 |
34 | public static void main(String[] args) {
35 | ComplexAlgorithm algorithm = new RealAlgorithm();
36 | System.out.println(algorithm.complexAlgorithm(10, 20));
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/11-ObjectOrientedProgrammingAgain/src/com/in28minutes/oops/level2/interfaces/RealAlgorithm.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.oops.level2.interfaces;
2 |
3 | public class RealAlgorithm implements ComplexAlgorithm{
4 |
5 | @Override
6 | public int complexAlgorithm(int number1, int number2) {
7 | return number1 * number2;
8 | }
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/13-Generics/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/13-Generics/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | generics
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/13-Generics/src/com/in28minutes/generics/GenericsRunner.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.generics;
2 |
3 | import java.util.ArrayList;
4 | import java.util.LinkedList;
5 | import java.util.List;
6 |
7 | public class GenericsRunner {
8 |
9 | static X doubleValue(X value) {
10 | return value;
11 | }
12 |
13 | static void duplicate(X list) {
14 | list.addAll(list);
15 | }
16 |
17 | static double sumOfNumberList(
18 | List extends Number> numbers) {
19 | double sum = 0.0;
20 | for (Number number : numbers) {
21 | sum += number.doubleValue();
22 | }
23 | return sum;
24 | }
25 |
26 | static void addACoupleOfValues(
27 | List super Number> numbers) {
28 | numbers.add(1);
29 | numbers.add(1.0);
30 | numbers.add(1.0f);
31 | numbers.add(1l);
32 | }
33 |
34 | public static void main(String[] args) {
35 | List emptyList = new ArrayList();
36 | addACoupleOfValues(emptyList);
37 | System.out.println(emptyList);
38 |
39 | System.out.println(
40 | sumOfNumberList(List.of(1, 2, 3, 4, 5)));
41 | System.out.println(sumOfNumberList(
42 | List.of(1.1, 2.1, 3.1, 4.1, 5.1)));
43 | System.out.println(sumOfNumberList(
44 | List.of(1l, 2l, 3l, 4l, 5l)));
45 |
46 | String value1 = doubleValue(new String());
47 | Integer number1 = doubleValue(Integer.valueOf(5));
48 | ArrayList list1 = doubleValue(new ArrayList());
49 |
50 | LinkedList numbers = new LinkedList<>(
51 | List.of(1, 2, 3));
52 | duplicate(numbers);
53 | System.out.println(numbers);
54 |
55 | MyCustomList list = new MyCustomList<>();
56 | list.addElement("Element 1");
57 | list.addElement("Element 2");
58 | String value = list.get(0);
59 |
60 | System.out.println(value);
61 |
62 | MyCustomList list2 = new MyCustomList<>();
63 | list2.addElement(Integer.valueOf(5));
64 | list2.addElement(Integer.valueOf(7));
65 | Integer number = list2.get(0);
66 | System.out.println(number);
67 |
68 | }
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/13-Generics/src/com/in28minutes/generics/MyCustomList.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.generics;
2 |
3 | import java.util.ArrayList;
4 |
5 | public class MyCustomList{
6 |
7 | ArrayList list = new ArrayList<>();
8 |
9 | public void addElement(T element) {
10 | list.add(element);
11 | }
12 |
13 | public void removeElement(T element) {
14 | list.remove(element);
15 | }
16 |
17 | public String toString() {
18 | return list.toString();
19 | }
20 |
21 | public T get(int index) {
22 | return list.get(index);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/14-FunctionalProgramming/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/14-FunctionalProgramming/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | functional-programming
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/14-FunctionalProgramming/commands.txt:
--------------------------------------------------------------------------------
1 | List list = List.of(1,4,7,9);
2 | list.stream().forEach(
3 | element -> System.out.println(element)
4 | )
5 | list.stream().filter(
6 | element -> element%2 == 1)
7 | list.stream().filter(
8 | element -> element%2 == 1).
9 | forEach(
10 | element -> System.out.println(element))
11 | list.stream().filter(element -> element%2==1).forEach(element->System.out.println(element))
12 | list.stream().filter(element -> element%2==0).forEach(element->System.out.println(element))
13 | void clear() { System.out.print("\033[H\033[2J ");}
14 | clear()
15 | numbers.stream().sorted().forEach(e->System.out.println(e));
16 | List numbers = List.of(3,5,3,213,45,5,7);
17 | numbers.stream().distinct().forEach(e->System.out.println(e));
18 | numbers.stream().distinct().sorted().forEach(e->System.out.println(e));
19 | numbers.stream().distinct().map(e -> e * e).forEach(e->System.out.println(e));
20 | clear()
21 | IntStream.range(1,10).forEach(p->System.out.println(p))
22 | IntStream.range(1,11).forEach(p->System.out.println(p))
23 | IntStream.range(1,11).map(e -> e * e).forEach(p->System.out.println(p))
24 | List.of("Apple", "Ant", "Bat").stream().map(s->s.toLowerCase()).forEach(p -> System.out.println(p))
25 | List.of("Apple", "Ant", "Bat").stream().map(s->s.length()).forEach(p -> System.out.println(p))
26 | clear()
27 | IntStream.range(1,11).reduce( 0 , (n1,n2) -> n1+n2)
28 | List.of(23,12,34,53).stream().max((n1,n2) -> Integer.compare(n1,n2))
29 | $24.isPresent()
30 | List.of(23,12,34,53).stream().max((n1,n2) -> Integer.compare(n1,n2)).get()
31 | List.of(23,12,34,53).stream().max((n1,n2) -> Integer.compare(n1,n2)).get()
32 | List.of(23,12,34,53).stream().max((n1,n2) -> Integer.compare(n1,n2)).get()
33 | List.of(23,12,34,53).stream().min((n1,n2) -> Integer.compare(n1,n2)).get()
34 | List.of(23,12,34,53).stream().filter(e -> e%2==1).forEach(e -> System.out.println(e))
35 | List.of(23,12,34,53).stream().filter(e -> e%2==1).collect(Collectors.toList())
36 | List.of(23,12,34,53).stream().filter(e -> e%2==0).collect(Collectors.toList())
37 | IntStream.range(1,11).map(e -> e * e)
38 | List.of(23,12,34,53).stream().filter(e -> e%2==0).collect(Collectors.toList())
39 | IntStream.range(1,10).map(e -> e * e)
40 | IntStream.range(1,10).map(e -> e * e).boxed().collect(Collectors.toList())
41 | IntStream.range(1,11).map(e -> e * e).boxed().collect(Collectors.toList())
42 | clear()
43 | List.of(23,45,67,12).stream().filter(n -> n%2==0).max( (n1,n2) -> Integer.compare(n1,n2) )
44 | $39.get()
45 | $39.isPresent()
46 | List.of(23,45,67).stream().filter(n -> n%2==0).max( (n1,n2) -> Integer.compare(n1,n2) )
47 | $42.isPresent()
48 | $42.orElse(0)
49 | $42.orElse(0)
50 | List.of(23,45,67).stream().filter(n -> n%2==0).max( (n1,n2) -> Integer.compare(n1,n2) ).orElse(0)
51 | List.of(23,45,67,34).stream().filter(n -> n%2==0).max( (n1,n2) -> Integer.compare(n1,n2) ).orElse(0)
--------------------------------------------------------------------------------
/14-FunctionalProgramming/src/com/in28minutes/functionalprogramming/FPNumberRunner.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.functionalprogramming;
2 |
3 | import java.util.List;
4 |
5 | public class FPNumberRunner {
6 |
7 | public static void main(String[] args) {
8 | List numbers = List.of(4,6,8,13,3,15);
9 |
10 | //Exercise - Print squares of first 10 numbers!
11 | //Clue - IntStream.range(1,10)
12 |
13 | //List.of("Apple", "Ant", "Bat").stream()
14 | //Map all of these to lowercase and print them
15 |
16 | //List.of("Apple", "Ant", "Bat").stream()
17 | //Print the length of each element
18 |
19 | /*
20 | numbers.stream()
21 | .forEach( element ->System.out.println(element));*/
22 |
23 | int sum = fpSum(numbers);
24 |
25 | System.out.println(sum);
26 |
27 | }
28 |
29 | private static int fpSum(List numbers) {
30 | return numbers.stream()
31 | .reduce(0,
32 | (number1, number2) -> number1 + number2);
33 | }
34 |
35 | private static int normalSum(List numbers) {
36 | int sum = 0;
37 | for(int number:numbers) {
38 | sum += number;
39 | }
40 | return sum;
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/14-FunctionalProgramming/src/com/in28minutes/functionalprogramming/FunctionalProgrammingRunner.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.functionalprogramming;
2 |
3 | import java.util.List;
4 |
5 | public class FunctionalProgrammingRunner {
6 |
7 | public static void main(String[] args) {
8 | List list = List.of("Apple", "Bat", "Cat",
9 | "Dog");
10 | printWithFPWithFiltering(list);
11 |
12 | }
13 |
14 | private static void printBasic(List list) {
15 | for (String string : list) {
16 | System.out.println(string);
17 | }
18 | }
19 |
20 | private static void printBasicWithFiltering(
21 | List list) {
22 | for (String string : list) {
23 | if (string.endsWith("at")) {
24 | System.out.println(string);
25 | }
26 | }
27 | }
28 |
29 | private static void printWithFP(List list) {
30 | list.stream().forEach(element -> System.out
31 | .println("element - " + element));
32 | }
33 |
34 | private static void printWithFPWithFiltering(List list) {
35 | list.stream()
36 | .filter(element -> element.endsWith("at"))
37 | .forEach(element -> System.out.println("element - " + element));
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/14-FunctionalProgramming/src/com/in28minutes/functionalprogramming/LambdaBehindTheScreensRunner.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.functionalprogramming;
2 |
3 | import java.util.List;
4 | import java.util.function.Consumer;
5 | import java.util.function.Function;
6 | import java.util.function.Predicate;
7 |
8 | class EvenNumberPredicate implements Predicate {
9 |
10 | @Override
11 | public boolean test(Integer number) {
12 | return number%2 == 0;
13 | }
14 |
15 | }
16 |
17 | class SystemOutConsumer implements Consumer {
18 |
19 | @Override
20 | public void accept(Integer number) {
21 | System.out.println(number);
22 | }
23 |
24 | }
25 |
26 | class NumberSquareMapper implements Function {
27 |
28 | @Override
29 | public Integer apply(Integer number) {
30 | return number * number;
31 | }
32 |
33 | }
34 |
35 | public class LambdaBehindTheScreensRunner {
36 |
37 |
38 |
39 | public static void main(String[] args) {
40 |
41 | List.of(23,43,34,45,36,48).stream()
42 | .filter(n -> n%2 ==0)
43 | .map(n -> n * n)
44 | .forEach(e -> System.out.println(e));
45 |
46 | List.of(23,43,34,45,36,48).stream()
47 | .filter(new EvenNumberPredicate())
48 | .map(new NumberSquareMapper())
49 | .forEach(new SystemOutConsumer());
50 |
51 | //.map(n -> n * n)
52 | // Stream map(Function super T, ? extends R> mapper);
53 | // R apply(T t);
54 |
55 | //.filter(new EvenNumberPredicate())
56 | //Stream filter(Predicate super T> predicate);
57 | //boolean test(T t);
58 |
59 | //.forEach(e -> System.out.println(e));
60 | //Consumer super T> action
61 | //void accept(T t);
62 |
63 | //1.Storing functions in variables
64 | //2.Passing functions to methods <=
65 | //3.Returning functions from methods
66 |
67 | Predicate super Integer> evenPredicate = createEvenPredicate();
68 | Predicate super Integer> oddPredicate = n -> n%2 ==1;
69 |
70 | List.of(23,43,34,45,36,48).stream()
71 | .filter(evenPredicate)
72 | .map(n -> n * n)
73 | .forEach(e -> System.out.println(e));
74 | }
75 |
76 | private static Predicate super Integer> createEvenPredicate() {
77 | return n -> n%2 ==0;
78 | }
79 |
80 | }
81 |
--------------------------------------------------------------------------------
/14-FunctionalProgramming/src/com/in28minutes/functionalprogramming/MethodReferencesRunner.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.functionalprogramming;
2 |
3 | import java.util.List;
4 |
5 | public class MethodReferencesRunner {
6 |
7 | public static void print(Integer number) {
8 | System.out.println(number);
9 | }
10 |
11 | public static void main(String[] args) {
12 | List.of("Ant", "Bat", "Cat", "Dog", "Elephant")
13 | .stream().map(s -> s.length())
14 | .forEach(s -> MethodReferencesRunner
15 | .print(s));
16 |
17 | List.of("Ant", "Bat", "Cat", "Dog", "Elephant")
18 | .stream().map(String::length)
19 | .forEach(MethodReferencesRunner::print);
20 |
21 | List.of(23,45,67,34).stream()
22 | .filter(n -> n%2==0)
23 | .max( (n1,n2) -> Integer.compare(n1,n2) )
24 | .orElse(0);
25 |
26 | Integer max = List.of(23, 45, 67, 34).stream()
27 | .filter(MethodReferencesRunner::isEven)
28 | .max(Integer::compare)
29 | .orElse(0);
30 |
31 | System.out.println(max);
32 | }
33 |
34 | public static boolean isEven(Integer number) {
35 | return number % 2 == 0;
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/15-ThreadsAndConcurrency/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/15-ThreadsAndConcurrency/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | Multithreading
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/15-ThreadsAndConcurrency/src/CallableRunner.java:
--------------------------------------------------------------------------------
1 | import java.util.concurrent.Callable;
2 | import java.util.concurrent.ExecutionException;
3 | import java.util.concurrent.ExecutorService;
4 | import java.util.concurrent.Executors;
5 | import java.util.concurrent.Future;
6 |
7 | class CallableTask implements Callable {
8 |
9 | private String name;
10 |
11 | public CallableTask(String name) {
12 | this.name = name;
13 | }
14 |
15 | @Override
16 | public String call() throws Exception {
17 | Thread.sleep(1000);
18 | return "Hello " + name;
19 | }
20 |
21 | }
22 |
23 | public class CallableRunner {
24 |
25 | public static void main(String[] args) throws InterruptedException, ExecutionException {
26 | ExecutorService executorService = Executors.newFixedThreadPool(1);
27 |
28 | Future welcomeFuture =
29 | executorService.submit(new CallableTask("in28Minutes"));
30 |
31 | System.out.print("\n new CallableTask(\"in28Minutes\") executed");
32 |
33 | String welcomeMessage = welcomeFuture.get();
34 |
35 | System.out.println(welcomeMessage);
36 |
37 | System.out.print("\n Main completed");
38 |
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/15-ThreadsAndConcurrency/src/ExecutorServiceRunner.java:
--------------------------------------------------------------------------------
1 | import java.util.concurrent.ExecutorService;
2 | import java.util.concurrent.Executors;
3 |
4 | class Task extends Thread {
5 |
6 | private int number;
7 |
8 | public Task(int number) {
9 | this.number = number;
10 | }
11 |
12 | public void run() { //SIGNATURE
13 | System.out.print("\nTask " + number + " Started");
14 |
15 | for(int i=number*100;i<=number*100 + 99; i++)
16 | System.out.print(i + " ");
17 |
18 | System.out.print("\nTask" + number + "Done");
19 | }
20 | }
21 |
22 |
23 | public class ExecutorServiceRunner {
24 |
25 | public static void main(String[] args) {
26 | //ExecutorService executorService = Executors.newSingleThreadExecutor();
27 | ExecutorService executorService = Executors.newFixedThreadPool(5);
28 |
29 | executorService.execute(new Task(1));
30 | executorService.execute(new Task(2));
31 | executorService.execute(new Task(3));
32 | executorService.execute(new Task(4));
33 | executorService.execute(new Task(5));
34 | executorService.execute(new Task(6));
35 | executorService.execute(new Task(7));
36 |
37 | executorService.shutdown();
38 |
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/15-ThreadsAndConcurrency/src/MultipleAnyCallableRunner.java:
--------------------------------------------------------------------------------
1 | import java.util.List;
2 | import java.util.concurrent.ExecutionException;
3 | import java.util.concurrent.ExecutorService;
4 | import java.util.concurrent.Executors;
5 | import java.util.concurrent.Future;
6 |
7 | public class MultipleAnyCallableRunner {
8 |
9 | public static void main(String[] args) throws InterruptedException, ExecutionException {
10 | ExecutorService executorService = Executors.newFixedThreadPool(3);
11 |
12 | List tasks = List.of(
13 | new CallableTask("in28Minutes"),
14 | new CallableTask("Ranga"),
15 | new CallableTask("Adam"));
16 |
17 | String result = executorService.invokeAny(tasks);
18 |
19 | System.out.println(result);
20 |
21 | executorService.shutdown();
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/15-ThreadsAndConcurrency/src/MultipleCallableRunner.java:
--------------------------------------------------------------------------------
1 | import java.util.List;
2 | import java.util.concurrent.ExecutionException;
3 | import java.util.concurrent.ExecutorService;
4 | import java.util.concurrent.Executors;
5 | import java.util.concurrent.Future;
6 |
7 | public class MultipleCallableRunner {
8 |
9 | public static void main(String[] args) throws InterruptedException, ExecutionException {
10 | ExecutorService executorService = Executors.newFixedThreadPool(3);
11 |
12 | List tasks = List.of(new CallableTask("in28Minutes"),
13 | new CallableTask("Ranga"), new CallableTask("Adam"));
14 |
15 | List> results = executorService.invokeAll(tasks);
16 |
17 | for(Future result:results) {
18 | System.out.println(result.get());
19 | }
20 |
21 | executorService.shutdown();
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/15-ThreadsAndConcurrency/src/ThreadBasicsRunner.java:
--------------------------------------------------------------------------------
1 | //extends Thread
2 | //implements Runnable
3 |
4 | class Task1 extends Thread {
5 |
6 | public void run() { //SIGNATURE
7 | System.out.print("\nTask1 Started");
8 |
9 | for(int i=101;i<=199; i++)
10 | System.out.print(i + " ");
11 |
12 | System.out.print("\nTask1 Done");
13 | }
14 | }
15 |
16 | class Task2 implements Runnable {
17 |
18 | @Override
19 | public void run() {
20 | System.out.print("\nTask2 Started");
21 |
22 | for(int i=201;i<=299; i++)
23 | System.out.print(i + " ");
24 |
25 | System.out.print("\nTask2 Done");
26 |
27 |
28 | }
29 |
30 | }
31 |
32 |
33 | public class ThreadBasicsRunner {
34 |
35 | public static void main(String[] args) throws InterruptedException {
36 |
37 | //• NEW;
38 | //• RUNNABLE;
39 | //• RUNNING;
40 | //• BLOCKED/WAITING;
41 | //• TERMINATED/DEAD;
42 |
43 | //Task1 - 101 to 199
44 | System.out.print("\nTask1 Kicked Off");
45 | Task1 task1 = new Task1();
46 | task1.setPriority(1);
47 | task1.start(); //task1.run();
48 |
49 | System.out.print("\nTask2 Kicked Off");
50 |
51 | Task2 task2 = new Task2();
52 | Thread task2Thread = new Thread(task2);
53 | task2Thread.setPriority(10);
54 | task2Thread.start();
55 |
56 | task1.join();
57 | task2Thread.join();
58 |
59 | System.out.print("\nTask3 Kicked Off");
60 |
61 | //Task3
62 | for(int i=301;i<=399; i++)
63 | System.out.print(i + " ");
64 |
65 | System.out.print("\nTask3 Done");
66 |
67 | System.out.print("\nMain Done");
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/17-Files/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/17-Files/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | files
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/17-Files/resources/data.txt:
--------------------------------------------------------------------------------
1 | 123,122
2 | jljlfsadf
3 | Apple
4 | Bat
5 | Cat
6 |
7 |
--------------------------------------------------------------------------------
/17-Files/resources/file-write.txt:
--------------------------------------------------------------------------------
1 | Apple
2 | Boy
3 | Cat
4 | Dog
5 | Elephant
6 |
7 |
--------------------------------------------------------------------------------
/17-Files/src/files/DirectoryScanRunner.java:
--------------------------------------------------------------------------------
1 | package files;
2 |
3 | import java.io.IOException;
4 | import java.nio.file.Files;
5 | import java.nio.file.Path;
6 | import java.nio.file.Paths;
7 | import java.nio.file.attribute.BasicFileAttributes;
8 | import java.util.function.BiPredicate;
9 | import java.util.function.Predicate;
10 |
11 | public class DirectoryScanRunner {
12 |
13 | public static void main(String[] args) throws IOException {
14 |
15 | Path currentDirectory = Paths.get(".");
16 | //Files.list(currentDirectory).forEach(System.out::println);
17 |
18 | Predicate super Path> predicate
19 | = path -> String.valueOf(path).contains(".java");
20 |
21 | //Files.walk(currentDirectory, 4).filter(predicate).forEach(System.out::println);
22 |
23 | BiPredicate javaMatcher
24 | = (path,attributes) -> String.valueOf(path).contains(".java");
25 |
26 | BiPredicate directoryMatcher
27 | = (path,attributes) -> attributes.isDirectory();
28 |
29 |
30 | Files.find(currentDirectory, 4, directoryMatcher )
31 | .forEach(System.out::println);
32 |
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/17-Files/src/files/FileReadRunner.java:
--------------------------------------------------------------------------------
1 | package files;
2 |
3 | import java.io.IOException;
4 | import java.nio.file.Files;
5 | import java.nio.file.Path;
6 | import java.nio.file.Paths;
7 | import java.util.List;
8 |
9 | public class FileReadRunner {
10 |
11 | public static void main(String[] args) throws IOException {
12 | Path pathFileToRead = Paths.get("./resources/data.txt");
13 |
14 | //List lines = Files.readAllLines(pathFileToRead);
15 | //System.out.println(lines);
16 |
17 | Files.lines(pathFileToRead)
18 | .map(String::toLowerCase)
19 | .filter(str -> str.contains("a"))
20 | .forEach(System.out::println);
21 |
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/17-Files/src/files/FileWriteRunner.java:
--------------------------------------------------------------------------------
1 | package files;
2 |
3 | import java.io.IOException;
4 | import java.nio.file.Files;
5 | import java.nio.file.Path;
6 | import java.nio.file.Paths;
7 | import java.util.List;
8 |
9 | public class FileWriteRunner {
10 |
11 | public static void main(String[] args) throws IOException {
12 | Path pathFileToWrite = Paths.get("./resources/file-write.txt");
13 |
14 | List list =
15 | List.of("Apple", "Boy", "Cat", "Dog", "Elephant");
16 |
17 | Files.write(pathFileToWrite, list);
18 |
19 |
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/18-ConcurrencyLocksAtomicityAndCollections/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/18-ConcurrencyLocksAtomicityAndCollections/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | concurrency
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/18-ConcurrencyLocksAtomicityAndCollections/src/com/in28minutes/concurrency/BiCounter.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.concurrency;
2 |
3 | public class BiCounter {
4 | private int i = 0;
5 | private int j = 0;
6 |
7 | synchronized public void incrementI() {
8 | i++;
9 | //get i
10 | //increment
11 | //set i
12 | }
13 |
14 | public int getI() {
15 | return i;
16 | }
17 |
18 | synchronized public void incrementJ() {
19 | j++;
20 | //get j
21 | //increment
22 | //set j
23 | }
24 |
25 | public int getJ() {
26 | return j;
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/18-ConcurrencyLocksAtomicityAndCollections/src/com/in28minutes/concurrency/BiCounterWithAtomicInteger.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.concurrency;
2 |
3 | import java.util.concurrent.atomic.AtomicInteger;
4 | import java.util.concurrent.locks.Lock;
5 | import java.util.concurrent.locks.ReentrantLock;
6 |
7 | public class BiCounterWithAtomicInteger {
8 | private AtomicInteger i = new AtomicInteger();
9 | private AtomicInteger j = new AtomicInteger();
10 |
11 | public void incrementI() {
12 | i.incrementAndGet();
13 | }
14 |
15 | public int getI() {
16 | return i.get();
17 | }
18 |
19 | public void incrementJ() {
20 | j.incrementAndGet();
21 | }
22 |
23 | public int getJ() {
24 | return j.get();
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/18-ConcurrencyLocksAtomicityAndCollections/src/com/in28minutes/concurrency/BiCounterWithLock.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.concurrency;
2 |
3 | import java.util.concurrent.locks.Lock;
4 | import java.util.concurrent.locks.ReentrantLock;
5 |
6 | public class BiCounterWithLock {
7 | private int i = 0;
8 | private int j = 0;
9 |
10 | Lock lockForI = new ReentrantLock();
11 | Lock lockForJ = new ReentrantLock();
12 |
13 | public void incrementI() {
14 | lockForI.lock();//Get Lock For I
15 | i++;
16 | lockForI.unlock();
17 | //Release Lock For I
18 | }
19 |
20 | public int getI() {
21 | return i;
22 | }
23 |
24 | public void incrementJ() {
25 | lockForJ.lock();//Get Lock For J
26 | j++;
27 | lockForJ.unlock();//Release Lock For J
28 | }
29 |
30 | public int getJ() {
31 | return j;
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/18-ConcurrencyLocksAtomicityAndCollections/src/com/in28minutes/concurrency/ConcurrencyRunner.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.concurrency;
2 |
3 | public class ConcurrencyRunner {
4 |
5 | public static void main(String[] args) {
6 | Counter counter = new Counter();
7 | counter.increment();
8 | counter.increment();
9 | counter.increment();
10 | System.out.println(counter.getI());
11 |
12 | }
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/18-ConcurrencyLocksAtomicityAndCollections/src/com/in28minutes/concurrency/ConcurrentMapRunner.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.concurrency;
2 |
3 | import java.util.Hashtable;
4 | import java.util.Map;
5 | import java.util.concurrent.ConcurrentHashMap;
6 | import java.util.concurrent.ConcurrentMap;
7 | import java.util.concurrent.atomic.LongAdder;
8 |
9 | public class ConcurrentMapRunner {
10 |
11 | public static void main(String[] args) {
12 | ConcurrentMap occurances = new ConcurrentHashMap<>();
13 |
14 | String str = "ABCD ABCD ABCD";
15 |
16 | for(char character:str.toCharArray()) {
17 | occurances.computeIfAbsent(character, ch -> new LongAdder()).increment();
18 | }
19 |
20 | System.out.println(occurances);
21 |
22 |
23 | }
24 |
25 | /*
26 | Map occurances = new Hashtable<>();
27 |
28 | String str = "ABCD ABCD ABCD";
29 | for(char character:str.toCharArray()) {
30 | LongAdder longAdder = occurances.get(character);
31 | if(longAdder == null) {
32 | longAdder = new LongAdder();
33 | }
34 | longAdder.increment();
35 | occurances.put(character, longAdder);
36 | }
37 |
38 | System.out.println(occurances);
39 |
40 | */
41 | }
42 |
--------------------------------------------------------------------------------
/18-ConcurrencyLocksAtomicityAndCollections/src/com/in28minutes/concurrency/CopyOnWriteArrayListRunner.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.concurrency;
2 |
3 | import java.util.List;
4 | import java.util.concurrent.CopyOnWriteArrayList;
5 |
6 | public class CopyOnWriteArrayListRunner {
7 |
8 | //add - copy
9 | //get
10 |
11 | public static void main(String[] args) {
12 | List list = new CopyOnWriteArrayList<>();
13 |
14 | //Threads - 3
15 | list.add("Ant");
16 | list.add("Bat");
17 | list.add("Cat");
18 |
19 | //Threads - 10000
20 | for(String element:list) {
21 | System.out.println(element);
22 | }
23 |
24 | // TODO Auto-generated method stub
25 |
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/18-ConcurrencyLocksAtomicityAndCollections/src/com/in28minutes/concurrency/Counter.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.concurrency;
2 |
3 | public class Counter {
4 | private int i = 0;
5 |
6 | synchronized public void increment() {
7 | i++;
8 | //get i
9 | //increment
10 | //set i
11 | }
12 |
13 | public int getI() {
14 | return i;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/21-modularization-1-combined/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/21-modularization-1-combined/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | modularization-1-combined
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/21-modularization-1-combined/src/com/in28minutes/consumer/DirectConsumer.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.consumer;
2 |
3 | import java.util.List;
4 | import java.util.logging.Logger;
5 |
6 | import com.in28minutes.sorting.algorithm.BubbleSort;
7 |
8 | public class DirectConsumer {
9 |
10 | private static Logger logger =
11 | Logger.getLogger(DirectConsumer.class.getName());
12 |
13 | public static void main(String[] args) {
14 | BubbleSort util = new BubbleSort();
15 | List sorted
16 | = util.sort(List.of("Ranga", "Ravi", "Sathish", "Adam","Eve"));
17 | logger.info(sorted.toString());
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/21-modularization-1-combined/src/com/in28minutes/consumer/MySortingUtilConsumer.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.consumer;
2 |
3 | import java.util.List;
4 | import java.util.logging.Logger;
5 |
6 | import com.in28minutes.sorting.util.MySortingUtil;
7 |
8 | public class MySortingUtilConsumer {
9 |
10 | private static Logger logger =
11 | Logger.getLogger(MySortingUtilConsumer.class.getName());
12 |
13 | public static void main(String[] args) {
14 | MySortingUtil util = new MySortingUtil();
15 | List sorted
16 | = util.sort(List.of("Ranga", "Ravi", "Sathish", "Adam","Eve"));
17 | logger.info(sorted.toString());
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/21-modularization-1-combined/src/com/in28minutes/sorting/algorithm/BubbleSort.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.sorting.algorithm;
2 |
3 | import java.util.List;
4 |
5 | public class BubbleSort {
6 |
7 | public List sort(List names) {
8 | return names;
9 | }
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/21-modularization-1-combined/src/com/in28minutes/sorting/util/MySortingUtil.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.sorting.util;
2 |
3 | import java.util.List;
4 |
5 | import com.in28minutes.sorting.algorithm.BubbleSort;
6 |
7 | public class MySortingUtil {
8 |
9 | public List sort(List names){
10 | BubbleSort bubbleSort = new BubbleSort();
11 | return bubbleSort.sort(names);
12 | }
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/22-modularization-2-service-jar/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/22-modularization-2-service-jar/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | modularization-2-service-jar
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/22-modularization-2-service-jar/src/com/in28minutes/sorting/algorithm/BubbleSort.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.sorting.algorithm;
2 |
3 | import java.util.List;
4 |
5 | public class BubbleSort {
6 |
7 | public List sort(List names) {
8 | return names;
9 | }
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/22-modularization-2-service-jar/src/com/in28minutes/sorting/util/MySortingUtil.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.sorting.util;
2 |
3 | import java.util.List;
4 |
5 | import com.in28minutes.sorting.algorithm.BubbleSort;
6 |
7 | public class MySortingUtil {
8 |
9 | public List sort(List names){
10 | BubbleSort bubbleSort = new BubbleSort();
11 | return bubbleSort.sort(names);
12 | }
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/23-modularization-3-consumer-jar/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/23-modularization-3-consumer-jar/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | modularization-3-consumer-jar
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/23-modularization-3-consumer-jar/src/com/in28minutes/consumer/DirectConsumer.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.consumer;
2 |
3 | import java.util.List;
4 | import java.util.logging.Logger;
5 |
6 | import com.in28minutes.sorting.algorithm.BubbleSort;
7 |
8 | public class DirectConsumer {
9 |
10 | private static Logger logger =
11 | Logger.getLogger(DirectConsumer.class.getName());
12 |
13 | public static void main(String[] args) {
14 | BubbleSort util = new BubbleSort();
15 | List sorted
16 | = util.sort(List.of("Ranga", "Ravi", "Sathish", "Adam","Eve"));
17 | logger.info(sorted.toString());
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/23-modularization-3-consumer-jar/src/com/in28minutes/consumer/MySortingUtilConsumer.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.consumer;
2 |
3 | import java.util.List;
4 | import java.util.logging.Logger;
5 |
6 | import com.in28minutes.sorting.util.MySortingUtil;
7 |
8 | public class MySortingUtilConsumer {
9 |
10 | private static Logger logger =
11 | Logger.getLogger(MySortingUtilConsumer.class.getName());
12 |
13 | public static void main(String[] args) {
14 | MySortingUtil util = new MySortingUtil();
15 | List sorted
16 | = util.sort(List.of("Ranga", "Ravi", "Sathish", "Adam","Eve"));
17 | logger.info(sorted.toString());
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/24-modularization-4-service-module/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/24-modularization-4-service-module/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | modularization-4-service-module
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/24-modularization-4-service-module/src/com/in28minutes/sorting/algorithm/BubbleSort.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.sorting.algorithm;
2 |
3 | import java.util.List;
4 |
5 | public class BubbleSort {
6 |
7 | public List sort(List names) {
8 | return names;
9 | }
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/24-modularization-4-service-module/src/com/in28minutes/sorting/util/MySortingUtil.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.sorting.util;
2 |
3 | import java.util.List;
4 |
5 | import com.in28minutes.sorting.algorithm.BubbleSort;
6 |
7 | public class MySortingUtil {
8 |
9 | public List sort(List names){
10 | BubbleSort bubbleSort = new BubbleSort();
11 | return bubbleSort.sort(names);
12 | }
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/24-modularization-4-service-module/src/module-info.java:
--------------------------------------------------------------------------------
1 | module com.in28minutes.service.provider {
2 | exports com.in28minutes.sorting.util;
3 | exports com.in28minutes.sorting.algorithm;
4 | }
--------------------------------------------------------------------------------
/25-modularization-5-consumer-module/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/25-modularization-5-consumer-module/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | modularization-5-consumer-module
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/25-modularization-5-consumer-module/src/com/in28minutes/consumer/DirectConsumer.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.consumer;
2 |
3 | import java.util.List;
4 | import java.util.logging.Logger;
5 |
6 | import com.in28minutes.sorting.algorithm.BubbleSort;
7 |
8 | public class DirectConsumer {
9 |
10 | private static Logger logger =
11 | Logger.getLogger(DirectConsumer.class.getName());
12 |
13 | public static void main(String[] args) {
14 | BubbleSort util = new BubbleSort();
15 | List sorted
16 | = util.sort(List.of("Ranga", "Ravi", "Sathish", "Adam","Eve"));
17 | logger.info(sorted.toString());
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/25-modularization-5-consumer-module/src/com/in28minutes/consumer/MySortingUtilConsumer.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.consumer;
2 |
3 | import java.util.List;
4 | import java.util.logging.Logger;
5 |
6 | import com.in28minutes.sorting.util.MySortingUtil;
7 |
8 | public class MySortingUtilConsumer {
9 |
10 | private static Logger logger =
11 | Logger.getLogger(MySortingUtilConsumer.class.getName());
12 |
13 | public static void main(String[] args) {
14 | MySortingUtil util = new MySortingUtil();
15 | List sorted
16 | = util.sort(List.of("Ranga", "Ravi", "Sathish", "Adam","Eve"));
17 | logger.info(sorted.toString());
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/25-modularization-5-consumer-module/src/module-info.java:
--------------------------------------------------------------------------------
1 | module com.in28minutes.consumer {
2 | requires com.in28minutes.service.provider;
3 | requires transitive java.logging;
4 | }
--------------------------------------------------------------------------------
/3 types of Arrays:
--------------------------------------------------------------------------------
1 | package com.company;
2 |
3 | public class cwh_26_arrays {
4 | public static void main(String[] args) {
5 | /* Classroom of 500 students - You have to store marks of these 500 students
6 | You have 2 options:
7 | 1. Create 500 variables
8 | 2. Use Arrays (recommended)
9 | */
10 | // There are three main ways to create an array in Java
11 | // 1. Declaration and memory allocation
12 | // int [] marks = new int[5];
13 |
14 | // 2. Declaration and then memory allocation
15 | // int [] marks;
16 | // marks = new int[5];
17 | // Initialization
18 | // marks[0] = 100;
19 | // marks[1] = 60;
20 | // marks[2] = 70;
21 | // marks[3] = 90;
22 | // marks[4] = 86;
23 |
24 | // 3. Declaration, memory allocation and initialization together
25 | int [] marks = {98, 45, 79, 99, 80};
26 |
27 | // marks[5] = 96; - throws an error
28 | System.out.println(marks[4]);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/31-java-new-api-features/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/31-java-new-api-features/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | java-new-api-features
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/31-java-new-api-features/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3 | org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=16
5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
6 | org.eclipse.jdt.core.compiler.compliance=16
7 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate
8 | org.eclipse.jdt.core.compiler.debug.localVariable=generate
9 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate
10 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
11 | org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
12 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
13 | org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
14 | org.eclipse.jdt.core.compiler.release=disabled
15 | org.eclipse.jdt.core.compiler.source=16
16 |
--------------------------------------------------------------------------------
/31-java-new-api-features/resources/sample-new.txt:
--------------------------------------------------------------------------------
1 | Sample
2 | Lines 2
3 | Lines 3
--------------------------------------------------------------------------------
/31-java-new-api-features/resources/sample.txt:
--------------------------------------------------------------------------------
1 | Sample
2 | Line 2
3 | Line 3
--------------------------------------------------------------------------------
/31-java-new-api-features/src/com/in28minutes/api/a/CopyOfApiRunner.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.api.a;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | public class CopyOfApiRunner {
7 |
8 | public static void main(String[] args) {
9 | List names = new ArrayList();
10 | names.add("Ranga");
11 | names.add("Ravi");
12 | names.add("John");
13 |
14 | List copyOfNames = List.copyOf(names);
15 |
16 | doNotChange(copyOfNames);
17 | System.out.println(copyOfNames);
18 |
19 | }
20 |
21 | private static void doNotChange(List names) {
22 | names.add("ShouldNotbeAllowed");
23 |
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/31-java-new-api-features/src/com/in28minutes/api/b/FileReadWriteRunner.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.api.b;
2 |
3 | import java.io.IOException;
4 | import java.nio.file.Files;
5 | import java.nio.file.Path;
6 | import java.nio.file.Paths;
7 |
8 | public class FileReadWriteRunner {
9 |
10 | public static void main(String[] args) throws IOException {
11 | Path path = Paths.get("./resources/sample.txt");
12 | String fileContent = Files.readString(path);
13 | System.out.println(fileContent);
14 | String newFileContent = fileContent.replace("Line", "Lines");
15 |
16 | Path newFilePath = Paths.get("./resources/sample-new.txt");
17 | Files.writeString(newFilePath, newFileContent);
18 |
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/31-java-new-api-features/src/com/in28minutes/api/c/PredicateNotRunner.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.api.c;
2 |
3 | import java.util.List;
4 | import java.util.function.Predicate;
5 |
6 | public class PredicateNotRunner {
7 |
8 | public static boolean isEven(Integer number) {
9 | return number%2==0;
10 | }
11 |
12 | public static void main(String[] args) {
13 | List numbers = List.of(3,4,5,67,89,88);
14 | // Predicate evenNumberPredicate = number -> number%2==0;
15 | // numbers.stream().filter(evenNumberPredicate.negate()).forEach(System.out::println);
16 | numbers.stream().filter(Predicate.not(PredicateNotRunner::isEven))
17 | .forEach(System.out::println);
18 |
19 |
20 |
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/31-java-new-api-features/src/com/in28minutes/api/d/StringNewApiRunner.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.api.d;
2 |
3 | class SampleClass {
4 | String str = null;
5 | }
6 |
7 | public class StringNewApiRunner {
8 |
9 |
10 | public static void main(String[] args) {
11 | System.out.println(" ".isBlank());
12 | System.out.println(" L R ".strip().replace(" ","@"));
13 | System.out.println(" L R ".stripLeading().replace(" ","@"));
14 | System.out.println(" L R ".stripTrailing().replace(" ","@"));
15 | "Line1\nLine2\nLine3\nLine4".lines().forEach(System.out::println);
16 |
17 | System.out.println("UPPER".transform(s -> s.substring(2)));
18 | System.out.println("My name is %s. My age is %d.".formatted("Ranga", 25));
19 |
20 |
21 | SampleClass sample = new SampleClass();
22 | String str = null;
23 | System.out.println(sample.str.isBlank());
24 | //Exception in thread "main" java.lang.NullPointerException:
25 | // Cannot invoke "String.isBlank()" because "sample.str" is null
26 | //at com.in28minutes.api.d.StringNewApiRunner.main(StringNewApiRunner.java:23)
27 |
28 |
29 | //Exception in thread "main" java.lang.NullPointerException:
30 | //Cannot invoke "String.isBlank()" because "str" is null
31 | //at com.in28minutes.api.d.StringNewApiRunner.main(StringNewApiRunner.java:15)
32 |
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/31-java-new-api-features/src/com/in28minutes/api/e/TypeInferencesRunner.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.api.e;
2 |
3 | import java.util.List;
4 | import java.util.stream.Stream;
5 |
6 | public class TypeInferencesRunner {
7 |
8 | public static void main(String[] args) {
9 | var names1 = List.of("Ranga", "Ravi");
10 | var names2 = List.of("John", "Adam");
11 | var var = "";
12 |
13 | final var names = List.of(names1,names2);
14 |
15 | names.stream().forEach(System.out::println);
16 |
17 | for(var name:names1)
18 | System.out.println(name);
19 |
20 | var filter = List.of("Ranga", "Ravi").stream().filter(s -> s.length()<5);
21 | filter.forEach(System.out::println);
22 |
23 |
24 |
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/31-java-new-api-features/src/com/in28minutes/api/f/SwitchExpressionRunner.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.api.f;
2 |
3 | public class SwitchExpressionRunner {
4 |
5 | public static String findDayOfTheWeek(int day) {
6 | String dayOfWeek = "";
7 |
8 | switch(day) {
9 | case 0: dayOfWeek = "Sunday"; break;
10 | case 1: dayOfWeek = "Monday"; break;
11 | case 2: dayOfWeek = "Tuesday"; break;
12 | case 3: dayOfWeek = "Wednesday"; break;
13 | default: throw new IllegalArgumentException("Invalid Option"+ day);
14 | }
15 |
16 | return dayOfWeek;
17 | }
18 |
19 | public static String findDayOfTheWeekWithSwitchExpression(int day) {
20 | String dayOfWeek = switch(day) {
21 | case 0 -> {
22 | System.out.println("Do Some complex logic here");
23 | yield "Sunday";
24 | }
25 | case 1 -> "Monday";
26 | case 2 -> "Tuesday";
27 | case 3 ->"Wednesday";
28 | default -> throw new IllegalArgumentException("Invalid Option"+ day);
29 | };
30 |
31 | return dayOfWeek;
32 | }
33 |
34 |
35 | public static void main(String[] args) {
36 |
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/31-java-new-api-features/src/com/in28minutes/api/g/TextBlocksRunner.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.api.g;
2 |
3 | public class TextBlocksRunner {
4 |
5 | public static void main(String[] args) {
6 | String str1 = """
7 | fsadfjklasjf""";
8 | String str = """
9 | "Line 1"
10 | "Line 2"
11 | Line 3
12 | Line 4
13 | Line 5
14 | Line 6""";
15 |
16 | String textBlock = """
17 | Line 1: %s
18 | Line 2: %s
19 | Line 3
20 | Line 4
21 | """.formatted("Some Value", "Some Other Value");
22 |
23 | System.out.print(textBlock);
24 |
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/31-java-new-api-features/src/com/in28minutes/api/h/RecordsRunner.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.api.h;
2 |
3 | public class RecordsRunner {
4 |
5 | record Person(String name, String email, String phoneNumber) {
6 | Person {
7 | if(name == null)
8 | throw new IllegalArgumentException("name is null");
9 | }
10 |
11 | public String name() {
12 | System.out.println("Do Something");
13 | return name;
14 | }
15 |
16 | }
17 |
18 | public static void main(String[] args) {
19 | Person person = new Person("Ranga", "ranga@in28minutes.com","123-456-7890");
20 | System.out.println(person.name());
21 |
22 |
23 | // Person person1 = new Person("Ranga", "ranga@in28minutes.com","123-456-7890");
24 | // Person person2 = new Person("Ranga1", "ranga@in28minutes.com","123-456-7890");
25 | // System.out.println(person.equals(person1));
26 | // System.out.println(person.equals(person2));
27 |
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/51-learn-spring-framework/.gitignore:
--------------------------------------------------------------------------------
1 | HELP.md
2 | target/
3 | !.mvn/wrapper/maven-wrapper.jar
4 | !**/src/main/**/target/
5 | !**/src/test/**/target/
6 |
7 | ### STS ###
8 | .apt_generated
9 | .classpath
10 | .factorypath
11 | .project
12 | .settings
13 | .springBeans
14 | .sts4-cache
15 |
16 | ### IntelliJ IDEA ###
17 | .idea
18 | *.iws
19 | *.iml
20 | *.ipr
21 |
22 | ### NetBeans ###
23 | /nbproject/private/
24 | /nbbuild/
25 | /dist/
26 | /nbdist/
27 | /.nb-gradle/
28 | build/
29 | !**/src/main/**/build/
30 | !**/src/test/**/build/
31 |
32 | ### VS Code ###
33 | .vscode/
34 |
--------------------------------------------------------------------------------
/51-learn-spring-framework/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.boot
7 | spring-boot-starter-parent
8 | 2.4.4
9 |
10 |
11 | com.in28minutes
12 | learn-spring-framework
13 | 0.0.1-SNAPSHOT
14 | learn-spring-framework
15 | Demo project for Spring Boot
16 |
17 | 11
18 |
19 |
20 |
21 |
22 | org.springframework.boot
23 | spring-boot-starter
24 |
25 |
26 |
27 | org.springframework.boot
28 | spring-boot-starter-web
29 |
30 |
31 |
32 | org.springframework.boot
33 | spring-boot-starter-test
34 | test
35 |
36 |
37 |
38 |
39 |
40 |
41 | org.springframework.boot
42 | spring-boot-maven-plugin
43 |
44 |
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/51-learn-spring-framework/src/main/java/com/in28minutes/learnspringframework/LearnSpringFrameworkApplication.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.learnspringframework;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.context.ConfigurableApplicationContext;
6 |
7 | import com.in28minutes.learnspringframework.game.GameRunner;
8 |
9 | @SpringBootApplication
10 | //@ComponentScan({"com.in28minutes.learnspringframework", "com.in28minutes.dummy"})
11 | public class LearnSpringFrameworkApplication {
12 |
13 | public static void main(String[] args) {
14 |
15 | ConfigurableApplicationContext context =
16 | SpringApplication.run(LearnSpringFrameworkApplication.class, args);
17 |
18 | //MarioGame,GameRunner
19 | GameRunner runner = context.getBean(GameRunner.class);
20 |
21 | // MarioGame game = new MarioGame();
22 | //SuperContraGame game = new SuperContraGame();
23 | // GameRunner runner = new GameRunner(game);
24 |
25 | runner.runGame();
26 |
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/51-learn-spring-framework/src/main/java/com/in28minutes/learnspringframework/game/GameRunner.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.learnspringframework.game;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.stereotype.Component;
5 |
6 | @Component
7 | public class GameRunner {
8 |
9 | @Autowired
10 | private GamingConsole game;
11 |
12 | public GameRunner(GamingConsole game) {
13 | System.out.println("Using Constructor");
14 | this.game = game;
15 | }
16 |
17 |
18 | // public void setGame(GamingConsole game) {
19 | // System.out.println("Using Setter");
20 | // this.game = game;
21 | // }
22 |
23 |
24 |
25 | public void runGame() {
26 | game.up();
27 | game.down();
28 | game.left();
29 | game.right();
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/51-learn-spring-framework/src/main/java/com/in28minutes/learnspringframework/game/GamingConsole.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.learnspringframework.game;
2 |
3 | public interface GamingConsole {
4 |
5 | void up();
6 |
7 | void down();
8 |
9 | void left();
10 |
11 | void right();
12 |
13 | }
--------------------------------------------------------------------------------
/51-learn-spring-framework/src/main/java/com/in28minutes/learnspringframework/game/MarioGame.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.learnspringframework.game;
2 |
3 | import org.springframework.stereotype.Component;
4 |
5 | @Component
6 | public class MarioGame implements GamingConsole {
7 |
8 | @Override
9 | public void up() {
10 | System.out.println("jump");
11 | }
12 |
13 | @Override
14 | public void down() {
15 | System.out.println("go into a hole");
16 | }
17 |
18 | @Override
19 | public void left() {
20 | System.out.println("stop");
21 | }
22 |
23 | @Override
24 | public void right() {
25 | System.out.println("go faster");
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/51-learn-spring-framework/src/main/java/com/in28minutes/learnspringframework/game/PacManGame.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.learnspringframework.game;
2 |
3 | import org.springframework.context.annotation.Primary;
4 | import org.springframework.stereotype.Component;
5 |
6 | @Component
7 | @Primary
8 | public class PacManGame implements GamingConsole{
9 |
10 | public void up() {
11 | System.out.println("PacManGame up");
12 | }
13 |
14 | public void down() {
15 | System.out.println("down");
16 | }
17 |
18 | public void left() {
19 | System.out.println("left");
20 | }
21 |
22 | public void right() {
23 | System.out.println("right");
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/51-learn-spring-framework/src/main/java/com/in28minutes/learnspringframework/game/SuperContraGame.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.learnspringframework.game;
2 |
3 | import org.springframework.stereotype.Component;
4 |
5 | @Component
6 | //@Primary
7 | public class SuperContraGame implements GamingConsole{
8 |
9 | public void up() {
10 | System.out.println("SuperContraGame up");
11 | }
12 |
13 | public void down() {
14 | System.out.println("down");
15 | }
16 |
17 | public void left() {
18 | System.out.println("left");
19 | }
20 |
21 | public void right() {
22 | System.out.println("right");
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/51-learn-spring-framework/src/main/java/com/in28minutes/learnspringframework/sample/enterprise/flow/business/BusinessService.java:
--------------------------------------------------------------------------------
1 | //Business Logic
2 | package com.in28minutes.learnspringframework.sample.enterprise.flow.business;
3 |
4 | import java.util.List;
5 |
6 | import org.springframework.beans.factory.annotation.Autowired;
7 | import org.springframework.stereotype.Component;
8 |
9 | import com.in28minutes.learnspringframework.sample.enterprise.flow.data.DataService;
10 |
11 | @Component
12 | public class BusinessService {
13 |
14 | @Autowired
15 | private DataService dataService;
16 |
17 | public long calculateSum() {
18 | List data = dataService.retrieveData();
19 | return data.stream().reduce(Integer::sum).get();
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/51-learn-spring-framework/src/main/java/com/in28minutes/learnspringframework/sample/enterprise/flow/data/DataService.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.learnspringframework.sample.enterprise.flow.data;
2 |
3 | import java.util.Arrays;
4 | import java.util.List;
5 |
6 | import org.springframework.stereotype.Component;
7 |
8 | @Component
9 | public class DataService {
10 | public List retrieveData() {
11 | return Arrays.asList(12,34,56,78,90);
12 | }
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/51-learn-spring-framework/src/main/java/com/in28minutes/learnspringframework/sample/enterprise/flow/web/Controller.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.learnspringframework.sample.enterprise.flow.web;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.web.bind.annotation.GetMapping;
5 | import org.springframework.web.bind.annotation.RestController;
6 |
7 | import com.in28minutes.learnspringframework.sample.enterprise.flow.business.BusinessService;
8 |
9 | //Sending response in the right format
10 | @RestController
11 | public class Controller {
12 |
13 | @Autowired
14 | private BusinessService businessService;
15 |
16 | //"/sum" => 100
17 | @GetMapping("/sum")
18 | public long displaySum() {
19 | return businessService.calculateSum();
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/51-learn-spring-framework/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | # logging.level.org.springframework=DEBUG
2 |
--------------------------------------------------------------------------------
/51-learn-spring-framework/src/test/java/com/in28minutes/learnspringframework/LearnSpringFrameworkApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.learnspringframework;
2 |
3 | import org.junit.jupiter.api.Test;
4 | import org.springframework.boot.test.context.SpringBootTest;
5 |
6 | @SpringBootTest
7 | class LearnSpringFrameworkApplicationTests {
8 |
9 | @Test
10 | void contextLoads() {
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/52-learn-spring-boot/.gitignore:
--------------------------------------------------------------------------------
1 | HELP.md
2 | target/
3 | !.mvn/wrapper/maven-wrapper.jar
4 | !**/src/main/**/target/
5 | !**/src/test/**/target/
6 |
7 | ### STS ###
8 | .apt_generated
9 | .classpath
10 | .factorypath
11 | .project
12 | .settings
13 | .springBeans
14 | .sts4-cache
15 |
16 | ### IntelliJ IDEA ###
17 | .idea
18 | *.iws
19 | *.iml
20 | *.ipr
21 |
22 | ### NetBeans ###
23 | /nbproject/private/
24 | /nbbuild/
25 | /dist/
26 | /nbdist/
27 | /.nb-gradle/
28 | build/
29 | !**/src/main/**/build/
30 | !**/src/test/**/build/
31 |
32 | ### VS Code ###
33 | .vscode/
34 |
--------------------------------------------------------------------------------
/52-learn-spring-boot/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.boot
7 | spring-boot-starter-parent
8 | 2.4.4
9 |
10 |
11 | com.in28minutes
12 | learn-spring-boot
13 | 0.0.1-SNAPSHOT
14 | learn-spring-boot
15 | Demo project for Spring Boot
16 |
17 | 11
18 |
19 |
20 |
21 |
22 | org.springframework.boot
23 | spring-boot-starter-web
24 |
25 |
26 |
27 | org.springframework.boot
28 | spring-boot-starter-data-jpa
29 |
30 |
31 |
37 |
38 |
39 | mysql
40 | mysql-connector-java
41 |
42 |
43 |
44 | org.springframework.boot
45 | spring-boot-starter-actuator
46 |
47 |
48 |
49 | org.springframework.boot
50 | spring-boot-devtools
51 | runtime
52 |
53 |
54 |
55 |
56 | org.springframework.boot
57 | spring-boot-starter-test
58 | test
59 |
60 |
61 |
62 |
63 |
64 |
65 | org.springframework.boot
66 | spring-boot-maven-plugin
67 |
68 |
69 |
70 |
71 |
72 |
--------------------------------------------------------------------------------
/52-learn-spring-boot/src/main/java/com/in28minutes/learnspringboot/LearnSpringBootApplication.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.learnspringboot;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | //@SpringBootConfiguration
8 | //@EnableAutoConfiguration
9 | //@ComponentScan
10 | public class LearnSpringBootApplication {
11 |
12 | public static void main(String[] args) {
13 | SpringApplication.run(LearnSpringBootApplication.class, args);
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/52-learn-spring-boot/src/main/java/com/in28minutes/learnspringboot/courses/bean/Course.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.learnspringboot.courses.bean;
2 |
3 | import javax.persistence.Column;
4 | import javax.persistence.Entity;
5 | import javax.persistence.GeneratedValue;
6 | import javax.persistence.Id;
7 |
8 | @Entity
9 | public class Course {
10 |
11 | @Id
12 | @GeneratedValue
13 | private long id;
14 |
15 | //@Column(name="course_name")
16 | private String name;
17 |
18 | private String author;
19 |
20 | public Course() {
21 | }
22 |
23 | public Course(long id, String name, String author) {
24 | super();
25 | this.id = id;
26 | this.name = name;
27 | this.author = author;
28 | }
29 |
30 | public long getId() {
31 | return id;
32 | }
33 |
34 | public String getName() {
35 | return name;
36 | }
37 |
38 | public String getAuthor() {
39 | return author;
40 | }
41 |
42 | @Override
43 | public String toString() {
44 | return "Course [id=" + id + ", name=" + name + ", author=" + author + "]";
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/52-learn-spring-boot/src/main/java/com/in28minutes/learnspringboot/courses/controller/CourseController.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.learnspringboot.courses.controller;
2 |
3 | import java.util.List;
4 | import java.util.Optional;
5 |
6 | import org.springframework.beans.factory.annotation.Autowired;
7 | import org.springframework.web.bind.annotation.DeleteMapping;
8 | import org.springframework.web.bind.annotation.GetMapping;
9 | import org.springframework.web.bind.annotation.PathVariable;
10 | import org.springframework.web.bind.annotation.PostMapping;
11 | import org.springframework.web.bind.annotation.PutMapping;
12 | import org.springframework.web.bind.annotation.RequestBody;
13 | import org.springframework.web.bind.annotation.RestController;
14 |
15 | import com.in28minutes.learnspringboot.courses.bean.Course;
16 | import com.in28minutes.learnspringboot.courses.repository.CourseRepository;
17 |
18 | @RestController
19 | public class CourseController {
20 |
21 | @Autowired
22 | private CourseRepository repository;
23 |
24 | // http://localhost:8080/courses
25 | @GetMapping("/courses")
26 | public List getAllCourses() {
27 | return repository.findAll();
28 | }
29 |
30 | //// http://localhost:8080/courses/1
31 | @GetMapping("/courses/{id}")
32 | public Course getCourseDetails(@PathVariable long id) {
33 |
34 | Optional course = repository.findById(id);
35 |
36 | if(course.isEmpty()) {
37 | throw new RuntimeException("Course not found with id " + id);
38 | }
39 |
40 | return course.get();
41 | }
42 |
43 | /*
44 | POST http://localhost:8080/courses
45 | {
46 | "name": "Learn DevOps",
47 | "author": "in28minutes"
48 | }*/
49 |
50 | //POST - Create a new resource (/courses)
51 | @PostMapping("/courses")
52 | public void createCourse(@RequestBody Course course){
53 | repository.save(course);
54 | }
55 |
56 | /*
57 | PUT - http://localhost:8080/courses/100001
58 | {
59 | "id": 100001,
60 | "name": "Learn Microservices 2",
61 | "author": "in28minutes"
62 | }
63 | */
64 |
65 | //PUT - Update/Replace a resource (/courses/1)
66 | @PutMapping("/courses/{id}")
67 | public void updateCourse(@PathVariable long id, @RequestBody Course course){
68 | repository.save(course);
69 | }
70 |
71 |
72 | //DELETE - Delete a resource (/courses/1)
73 | @DeleteMapping("/courses/{id}")
74 | public void deleteCourse(@PathVariable long id){
75 | repository.deleteById(id);
76 | }
77 |
78 |
79 | // docker run --detach
80 | // --env MYSQL_ROOT_PASSWORD=dummypassword
81 | // --env MYSQL_USER=courses-user
82 | // --env MYSQL_PASSWORD=dummycourses
83 | // --env MYSQL_DATABASE=courses
84 | // --name mysql
85 | // --publish 3306:3306 mysql:5.7
86 | }
87 |
--------------------------------------------------------------------------------
/52-learn-spring-boot/src/main/java/com/in28minutes/learnspringboot/courses/repository/CourseRepository.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.learnspringboot.courses.repository;
2 |
3 | import org.springframework.data.jpa.repository.JpaRepository;
4 |
5 | import com.in28minutes.learnspringboot.courses.bean.Course;
6 |
7 | public interface CourseRepository extends JpaRepository {
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/52-learn-spring-boot/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | #logging.level.org.springframework=DEBUG
2 | #management.endpoints.web.exposure.include=*
3 | management.endpoints.web.exposure.include=health,metrics
4 | #spring.datasource.url=jdbc:h2:mem:testdb
5 |
6 | spring.jpa.hibernate.ddl-auto=update
7 | spring.datasource.url=jdbc:mysql://localhost:3306/courses
8 | spring.datasource.username=courses-user
9 | spring.datasource.password=dummycourses
10 | spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL57Dialect
11 |
12 | #courses-user@localhost:3306
--------------------------------------------------------------------------------
/52-learn-spring-boot/src/main/resources/data.sql:
--------------------------------------------------------------------------------
1 | insert into COURSE (ID, AUTHOR, NAME)
2 | values (100001, 'in28minutes', 'Learn Microservices');
3 | insert into COURSE (ID, AUTHOR, NAME)
4 | values (100002, 'in28minutes', 'Learn FullStack with React and Angular');
5 | insert into COURSE (ID, AUTHOR, NAME)
6 | values (100003, 'in28minutes', 'Learn AWS, GCP and Azure');
--------------------------------------------------------------------------------
/52-learn-spring-boot/src/test/java/com/in28minutes/learnspringboot/LearnSpringBootApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.learnspringboot;
2 |
3 | import org.junit.jupiter.api.Test;
4 | import org.springframework.boot.test.context.SpringBootTest;
5 |
6 | @SpringBootTest
7 | class LearnSpringBootApplicationTests {
8 |
9 | @Test
10 | void contextLoads() {
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/99-TipsAndTricks/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/99-TipsAndTricks/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | tips-and-tricks
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/99-TipsAndTricks/src/com/in28minutes/tips/access/package1/ClassAccessModifiers.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.tips.access.package1;
2 |
3 |
4 | //public, protected, (default), private
5 | public class ClassAccessModifiers {
6 |
7 | public static void main(String[] args) {
8 | // TODO Auto-generated method stub
9 | ClassAccessModifiers c = new ClassAccessModifiers();
10 |
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/99-TipsAndTricks/src/com/in28minutes/tips/access/package1/ExampleClass.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.tips.access.package1;
2 |
3 | public class ExampleClass {
4 | public void publicMethod() {}
5 | protected void protectedMethod() {}
6 | private void privateMethod() {}
7 | void defaultMethod() {}
8 |
9 | public static void main(String[] args) {
10 | ExampleClass exampleClass = new ExampleClass();
11 | exampleClass.privateMethod();
12 | exampleClass.protectedMethod();
13 | exampleClass.publicMethod();
14 | exampleClass.defaultMethod();
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/99-TipsAndTricks/src/com/in28minutes/tips/access/package1/MethodAccessRunnerInsideSamePackage.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.tips.access.package1;
2 |
3 | public class MethodAccessRunnerInsideSamePackage {
4 |
5 | public static void main(String[] args) {
6 | // TODO Auto-generated method stub
7 | ExampleClass exampleClass = new ExampleClass();
8 | //exampleClass.privateMethod();
9 | exampleClass.protectedMethod();
10 | exampleClass.publicMethod();
11 | exampleClass.defaultMethod();
12 |
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/99-TipsAndTricks/src/com/in28minutes/tips/access/package2/ClassAccessModifiersRunnerInOtherPackage.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.tips.access.package2;
2 |
3 | import com.in28minutes.tips.access.package1.ClassAccessModifiers;
4 |
5 | //public, protected, (default), private
6 | public class ClassAccessModifiersRunnerInOtherPackage {
7 |
8 | public static void main(String[] args) {
9 | ClassAccessModifiers c = new ClassAccessModifiers();
10 | }
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/99-TipsAndTricks/src/com/in28minutes/tips/access/package2/MethodAccessRunnerInDifferentPackage.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.tips.access.package2;
2 |
3 | import com.in28minutes.tips.access.package1.ExampleClass;
4 |
5 | public class MethodAccessRunnerInDifferentPackage {
6 |
7 | public static void main(String[] args) {
8 | // TODO Auto-generated method stub
9 | ExampleClass exampleClass = new ExampleClass();
10 |
11 | //exampleClass.privateMethod();
12 | //exampleClass.protectedMethod();
13 | exampleClass.publicMethod();
14 | //exampleClass.defaultMethod();
15 |
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/99-TipsAndTricks/src/com/in28minutes/tips/anonymous/AnonymousClassRunner.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.tips.anonymous;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Collections;
5 | import java.util.Comparator;
6 | import java.util.List;
7 |
8 | public class AnonymousClassRunner {
9 |
10 | public static void main(String[] args) {
11 | List animals = new ArrayList(
12 | List.of("Ant", "Cat", "Ball", "Elephant"));
13 |
14 | Comparator lengthComparator = new Comparator() {
15 | @Override
16 | public int compare(String str1, String str2) {
17 | return Integer.compare(str1.length(), str2.length());
18 | }
19 | };
20 |
21 | Collections.sort(animals,
22 | lengthComparator
23 | );
24 | System.out.println(animals);
25 |
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/99-TipsAndTricks/src/com/in28minutes/tips/blocks/BlocksRunner.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.tips.blocks;
2 |
3 | public class BlocksRunner {
4 | public static final int SECONDS_IN_MINUTE = 60;
5 | public static final int MINUTES_IN_HOUR = 60;
6 | public static final int HOURS_IN_DAY = 24;
7 | public static final int SECONDS_IN_DAY
8 | = SECONDS_IN_MINUTE * MINUTES_IN_HOUR * HOURS_IN_DAY;
9 |
10 | public static void main(String[] args) {
11 | //System.out.print(Integer.MIN_VALUE);
12 | System.out.print(SECONDS_IN_DAY);
13 |
14 | //System.out.print("main");
15 |
16 | {
17 | int i;
18 | //System.out.print("3>2");
19 | //System.out.print("3>2");
20 | }
21 |
22 | //System.out.print(i);
23 |
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/99-TipsAndTricks/src/com/in28minutes/tips/eclipse/DummyForTest.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.tips.eclipse;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | public class DummyForTest {
7 |
8 | public void doSomething() {
9 | List list = new ArrayList();
10 | }
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/99-TipsAndTricks/src/com/in28minutes/tips/eclipse/EclipseTipsAndTricks.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.tips.eclipse;
2 |
3 | import java.math.BigDecimal;
4 |
5 | //PAIR PROGRAMMING
6 |
7 | class TestBean {
8 | private int i; //i is awesome
9 | private String str;
10 |
11 |
12 |
13 | public TestBean() {
14 | /*
15 | fsadjflkas
16 | fskljdfalsk
17 | */
18 | super();
19 | }
20 |
21 | public TestBean(int i, String str) {
22 | super();
23 | this.i = i;
24 | this.str = str;
25 | }
26 | /* (non-Javadoc)
27 | * @see java.lang.Object#hashCode()
28 | */
29 | @Override
30 | public int hashCode() {
31 | final int prime = 31;
32 | int result = 1;
33 | result = prime * result + i;
34 | return result;
35 | }
36 | /* (non-Javadoc)
37 | * @see java.lang.Object#equals(java.lang.Object)
38 | */
39 | @Override
40 | public boolean equals(Object obj) {
41 | if (this == obj) {
42 | return true;
43 | }
44 | if (obj == null) {
45 | return false;
46 | }
47 | if (getClass() != obj.getClass()) {
48 | return false;
49 | }
50 | TestBean other = (TestBean) obj;
51 | if (i != other.i) {
52 | return false;
53 | }
54 | return true;
55 | }
56 | /**
57 | * @return the i
58 | */
59 | public int getI() {
60 | return i;
61 | }
62 | /**
63 | * @param i the i to set
64 | */
65 | public void setI(int i) {
66 | this.i = i;
67 | }
68 | /**
69 | * @return the str
70 | */
71 | public String getStr() {
72 | return str;
73 | }
74 | /**
75 | * @param str the str to set
76 | */
77 | public void setStr(String str) {
78 | this.str = str;
79 | }
80 |
81 |
82 |
83 | }
84 |
85 | class Test implements Comparable {
86 |
87 | @Override
88 | public int compareTo(String arg0) {
89 | return 0;
90 | }
91 |
92 | }
93 |
94 | public class EclipseTipsAndTricks {
95 |
96 | public static void main(String[] args) throws InterruptedException {
97 |
98 | DummyForTest dt = new DummyForTest();
99 | dt.doSomething();
100 | BigDecimal bd = new BigDecimal(25);
101 | Thread.sleep(returnSomething());
102 | }
103 |
104 | private static int returnSomething() {
105 | return 1000 * 45 * 456;
106 | }
107 |
108 | }
109 |
--------------------------------------------------------------------------------
/99-TipsAndTricks/src/com/in28minutes/tips/enums/EnumRunner.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.tips.enums;
2 |
3 | import java.util.Arrays;
4 |
5 | public class EnumRunner {
6 |
7 | public static void main(String[] args) {
8 | Season season = Season.FALL;
9 |
10 | Season season1 = Season.valueOf("WINTER");
11 | System.out.println(season1);
12 | System.out.println(Season.SPRING.ordinal());
13 | System.out.println(Season.SPRING.getValue());
14 |
15 | System.out
16 | .println(Arrays.toString(Season.values()));
17 |
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/99-TipsAndTricks/src/com/in28minutes/tips/enums/Season.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.tips.enums;
2 | public enum Season {
3 | SPRING(4), SUMMER(1), WINTER(2), FALL(3) ;
4 |
5 | private int value;
6 |
7 | private Season(int value) {
8 | this.value = value;
9 | }
10 |
11 | public int getValue() {
12 | return value;
13 | }
14 |
15 |
16 | //0,1,2,3
17 | }
18 |
--------------------------------------------------------------------------------
/99-TipsAndTricks/src/com/in28minutes/tips/equals/EqualsRunner.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.tips.equals;
2 |
3 | class Client {
4 | private int id;
5 |
6 | public Client(int id) {
7 | super();
8 | this.id = id;
9 | }
10 |
11 | @Override
12 | public int hashCode() {
13 | final int prime = 31;
14 | int result = 1;
15 | result = prime * result + id;
16 | return result;
17 | }
18 |
19 | @Override
20 | public boolean equals(Object that) {
21 | if (this == that)
22 | return true;
23 |
24 | if (that == null)
25 | return false;
26 | if (getClass() != that.getClass())
27 | return false;
28 | Client other = (Client) that;
29 | if (id != other.id)
30 | return false;
31 | return true;
32 | }
33 |
34 | //equals
35 | //hashcode
36 |
37 |
38 |
39 | }
40 |
41 | public class EqualsRunner {
42 |
43 | public static void main(String[] args) {
44 | Client c1 = new Client(1);
45 | Client c2 = new Client(1);
46 | Client c3 = new Client(2);
47 | System.out.println(c1.equals(c2));
48 | System.out.println(c1.equals(c3));
49 |
50 |
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/99-TipsAndTricks/src/com/in28minutes/tips/imports/ImportsRunner.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.tips.imports;
2 |
3 | //import java.lang.*; //DEFAULT
4 | import java.math.BigDecimal;
5 | import java.util.ArrayList;
6 | //import java.util.Collections;
7 |
8 | import static java.lang.System.out;
9 | import static java.util.Collections.*;
10 |
11 | public class ImportsRunner {
12 |
13 | public static void main(String[] args) {
14 |
15 | out.println("IMports");
16 | out.println("Static Imports");
17 |
18 | sort(new ArrayList());
19 |
20 | BigDecimal db = null;
21 |
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/99-TipsAndTricks/src/com/in28minutes/tips/nestedclass/NestedClassRunner.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.tips.nestedclass;
2 |
3 | class DefaultClass {
4 |
5 | }
6 |
7 | public class NestedClassRunner {
8 |
9 | int i;
10 |
11 | class InnerClass {
12 | public void method() {
13 | i = 5;
14 | }
15 | }
16 |
17 | static class StaticNestedClass {
18 | public void method() {
19 | //i = 5;
20 | }
21 |
22 | }
23 |
24 | public static void main(String[] args) {
25 | //InnerClass innerClass = new InnerClass();
26 | StaticNestedClass staticNestedClass = new StaticNestedClass();
27 |
28 | NestedClassRunner nestedClassRunner = new NestedClassRunner();
29 | InnerClass innerClass = nestedClassRunner.new InnerClass();
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/99-TipsAndTricks/src/com/in28minutes/tips/nonaccess/package1/FinalNonAccessModifierRunner.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.tips.nonaccess.package1;
2 |
3 | final class FinalClass {
4 |
5 | }
6 |
7 | //class SomeClass extends FinalClass{
8 | //}
9 |
10 | class SomeClass {
11 | final public void doSomething() {}
12 | public void doSomethingElse(final int arg) {
13 | //arg = 6;
14 |
15 | }
16 | }
17 |
18 | class ExtendingClass extends SomeClass {
19 | //public void doSomething() {}
20 | }
21 |
22 | public class FinalNonAccessModifierRunner {
23 |
24 | public static void main(String[] args) {
25 | final int i;
26 | i=5;
27 |
28 | //i = 7;
29 |
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/99-TipsAndTricks/src/com/in28minutes/tips/nonaccess/package1/StaticModifierRunner.java:
--------------------------------------------------------------------------------
1 | package com.in28minutes.tips.nonaccess.package1;
2 |
3 | class Player{
4 | private String name;
5 |
6 | private static int count = 0;
7 |
8 | public Player(String name) {
9 | super();
10 | this.name = name;
11 | count++;
12 | }
13 |
14 | static public int getCount() {
15 | return count;
16 | }
17 |
18 | public String getName() {
19 | System.out.println(count);
20 | return name;
21 | }
22 |
23 | public void setName(String name) {
24 | this.name = name;
25 | }
26 |
27 |
28 | }
29 |
30 | public class StaticModifierRunner {
31 |
32 | public static void main(String[] args) {
33 | Player player1 = new Player("Ronaldo");
34 |
35 | System.out.println(Player.getCount());
36 |
37 | Player player2 = new Player("Federer");
38 |
39 | System.out.println(Player.getCount());
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/Addition of two matrices and defining its process together:
--------------------------------------------------------------------------------
1 | public class Main {
2 | public static void main(String[] args) {
3 | // Addition of two matrices and defining its process together
4 | // @ Author: SAMIR PAUL
5 | int [][] mat1 = {{1,2,3},
6 | {3,5,7}};
7 | int [][] mat2 = {{3,4,6},
8 | {5,6,1}};
9 | int [][] result = {{0,0,0},
10 | {0,0,0}};
11 | for (int i =0;i l1 = new ArrayList<>();
9 | ArrayList l2 = new ArrayList<>(5);
10 | l2.add(15);
11 | l2.add(18);
12 | l2.add(19);
13 |
14 | l1.add(6);
15 | l1.add(7);
16 | l1.add(4);
17 | l1.add(6);
18 | l1.add(0, 5);
19 | l1.add(0, 1);
20 | l1.addAll(0, l2);
21 | System.out.println(l1.contains(27));
22 | System.out.println(l1.indexOf(6));
23 | System.out.println(l1.lastIndexOf(6));
24 | //l1.clear();
25 | l1.set(1, 566);
26 | for(int i=0; i xM) {
34 | xM = heap[i];
35 | posM = i;
36 | }
37 | }
38 | return new int[] {posm, posM};
39 | }
40 |
41 | public void sort(int n, int dir) {
42 | if (n == 0) return;
43 |
44 | int[] mM = minmax(n);
45 | int bestXPos = mM[dir];
46 | int altXPos = mM[1-dir];
47 | boolean flipped = false;
48 |
49 | if (bestXPos == n-1) {
50 | --n;
51 | }
52 | else if (bestXPos == 0) {
53 | flip(n-1);
54 | --n;
55 | }
56 | else if (altXPos == n-1) {
57 | dir = 1-dir;
58 | --n;
59 | flipped = true;
60 | }
61 | else {
62 | flip(bestXPos); }
63 | sort(n, dir);
64 |
65 | if (flipped) {
66 | flip(n);
67 | }
68 | }
69 |
70 | PancakeSort(int[] numbers) {
71 | heap = numbers;
72 | sort(numbers.length, 1);
73 | }
74 |
75 | public static void main(String[] args) {
76 | int numbers[] = {7, -5, 3, 2, 1, 0, 45};
77 | System.out.println("Original Array:");
78 | System.out.println(Arrays.toString(numbers));
79 | PancakeSort pancakes = new PancakeSort(numbers);
80 | System.out.println("Sorted Array:");
81 | System.out.println(Arrays.toString(numbers));
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/Java Thread Methods1:
--------------------------------------------------------------------------------
1 | package com.company;
2 |
3 | class MyNewThr1 extends Thread{
4 | public void run(){
5 | int i = 0;
6 | while(true){
7 | // System.out.println("I am a thread");
8 | System.out.println("Thank you: ");
9 | try {
10 | Thread.sleep(455);
11 | } catch (InterruptedException e) {
12 | e.printStackTrace();
13 | }
14 | i++;
15 | }
16 | }
17 | }
18 |
19 | class MyNewThr2 extends Thread{
20 |
21 | public void run(){
22 | while(true){
23 | // System.out.println("I am a thread");
24 | System.out.println("My Thank you: ");
25 | }
26 | }
27 | }
28 |
29 | public class cwh_75_thread_methods {
30 | public static void main(String[] args){
31 | MyNewThr1 t1 = new MyNewThr1();
32 | MyNewThr2 t2 = new MyNewThr2();
33 | t1.start();
34 | // try{
35 | // t1.join();
36 | // }
37 | // catch(Exception e){
38 | // System.out.println(e);
39 | // }
40 |
41 | t2.start();
42 |
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/Java program to break an integer into a sequence of individual digits.:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 | public class Exercise11 {
3 |
4 | public static void main(String[] args)
5 | {
6 | Scanner in = new Scanner(System.in);
7 | System.out.print("Input six non-negative digits: ");
8 | int input = in.nextInt();
9 | int n1 = input / 100000 % 10;
10 | int n2 = input / 10000 % 10;
11 | int n3 = input / 1000 % 10;
12 | int n4 = input / 100 % 10;
13 | int n5 = input / 10 % 10;
14 | int n6 = input % 10;
15 | System.out.println(n1 + " " + n2 + " " + n3 + " " + n4 + " " + n5 + " " + n6);
16 |
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/Method to repeat:
--------------------------------------------------------------------------------
1 | package tesr.java;
2 | public class Practice {
3 | public static void main(String[] args) {
4 |
5 | // Method to repeat
6 | myFirstMethod();
7 | myFirstMethod();
8 | myFirstMethod();
9 | myFirstMethod();
10 | myFirstMethod();
11 | myFirstMethod();
12 | myFirstMethod();
13 | myFirstMethod();
14 |
15 | }
16 | public static void myFirstMethod() {
17 | System.out.println("Samir Paul");
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/Multiple array and loops together:
--------------------------------------------------------------------------------
1 | public class Main { //Multiple array and loops together
2 | public static void main(String[] args) {
3 | int [][]flats = new int [2][3];
4 | flats [0][0]=101;
5 | flats [0][1]=102;
6 | flats [0][2]=103;
7 | flats [1][0]=201;
8 | flats [1][1]=202;
9 | flats [1][2]=203;
10 | for(int i=0;i0; i--){
8 | // for(int j=0;j=1;i--){
35 | // System.out.printf("%d X %d = %d\n", n, i, n*i);
36 | // }
37 |
38 | // Practice Problem 6
39 | // int n = 5;
40 | // // What is factorial n = n * n-1 * n-2 ..... 1
41 | // // 5! = 5*4*3*2*1 = 120
42 | // int i = 1;
43 | // int factorial = 1;
44 | // while(i<=n){
45 | // factorial *= i;
46 | // i++;
47 | // }
48 | // System.out.println(factorial);
49 |
50 | // Practice Problem 9
51 | // int n = 8;
52 | // int sum = 0;
53 | // //for(int i=0; i<10; i++) - Goes from i=0 to i=9
54 | // for(int i=1;i<=10;i++){
55 | // sum += n*i;
56 | // }
57 | // System.out.println(sum);
58 |
59 | }
60 | }
61 |
62 |
--------------------------------------------------------------------------------
/Practice Problems in ARRAYS:
--------------------------------------------------------------------------------
1 | package com.company;
2 |
3 | public class cwh_27_arrays {
4 | public static void main(String[] args) {
5 |
6 | /*
7 | float [] marks = {98.5f, 45.5f, 79.5f, 99.5f, 80.5f};
8 | String [] students ={"Harry", "Rohan", "Shubham", "Lovish"};
9 | System.out.println(students.length);
10 | System.out.println(students[2]);
11 | */
12 |
13 | int [] marks = {98, 45, 79, 99, 80};
14 | // System.out.println(marks.length);
15 |
16 |
17 |
18 | // Displaying the Array (Naive way)
19 | System.out.println("Printing using Naive way");
20 | System.out.println(marks[0]);
21 | System.out.println(marks[1]);
22 | System.out.println(marks[2]);
23 | System.out.println(marks[3]);
24 | System.out.println(marks[4]);
25 |
26 |
27 |
28 | // Displaying the Array (for loop)
29 | System.out.println("Printing using for loop");
30 | for(int i=0;i=0;i--){
39 | System.out.println(marks[i]);
40 | }
41 |
42 |
43 |
44 | // Quick Quiz: Displaying the Array (for-each loop)
45 | System.out.println("Printing using for-each loop");
46 | for(int element: marks){
47 | System.out.println(element);
48 | }
49 |
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/PrintSemiPyramid.java:
--------------------------------------------------------------------------------
1 | //This Code Prints stars in the below order
2 | //*
3 | //**
4 | //***
5 | public class PrintSemiPyramid {
6 | public static void main(String[] args) {
7 | int n = 3;
8 | for(int i=0; i=0; j--) {
10 | System.out.print("*");
11 | }
12 | System.out.println();
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/PrintStart.java:
--------------------------------------------------------------------------------
1 | //This Code Prints stars in the below order
2 | //***
3 | //**
4 | //*
5 | public class PrintStar {
6 | public static void main(String[] args) {
7 | int n = 3;
8 | for (int i=n; i>0; i--){
9 | for(int j=0; j e) {
9 | a = (a + b) / 2;
10 | b = num / a;
11 | }
12 | return a;
13 | }
14 |
15 | public static void main(String[] args) {
16 | Scanner scan = new Scanner(System.in);
17 | System.out.print("Input an integer: ");
18 | int num = scan.nextInt();
19 | scan.close();
20 | System.out.println("Square root of a number using Babylonian method: "+square_Root(num));
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/convert Roman number to an integer number.:
--------------------------------------------------------------------------------
1 | public class Example7 {
2 | public static void main(String[] args) {
3 | String str = "DCCVII";
4 | int len = str.length();
5 |
6 | str = str + " ";
7 | int result = 0;
8 | for (int i = 0; i < len; i++) {
9 | char ch = str.charAt(i);
10 | char next_char = str.charAt(i+1);
11 |
12 | if (ch == 'M') {
13 | result += 1000;
14 | } else if (ch == 'C') {
15 | if (next_char == 'M') {
16 | result += 900;
17 | i++;
18 | } else if (next_char == 'D') {
19 | result += 400;
20 | i++;
21 | } else {
22 | result += 100;
23 | }
24 | } else if (ch == 'D') {
25 | result += 500;
26 | } else if (ch == 'X') {
27 | if (next_char == 'C') {
28 | result += 90;
29 | i++;
30 | } else if (next_char == 'L') {
31 | result += 40;
32 | i++;
33 | } else {
34 | result += 10;
35 | }
36 | } else if (ch == 'L') {
37 | result += 50;
38 | } else if (ch == 'I') {
39 | if (next_char == 'X') {
40 | result += 9;
41 | i++;
42 | } else if (next_char == 'V') {
43 | result += 4;
44 | i++;
45 | } else {
46 | result++;
47 | }
48 | } else { // if (ch == 'V')
49 | result += 5;
50 | }
51 | }
52 | System.out.println("\nRoman Number: "+str);
53 | System.out.println("Equivalent Integer: "+result+"\n");
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/do while loop practice:
--------------------------------------------------------------------------------
1 | package com.company;
2 |
3 | public class cwh_22_ch4_do_while {
4 | public static void main(String[] args) {
5 | // int a = 0;
6 | // while(a<5){
7 | // System.out.println(a);
8 | // a++;
9 | // }
10 | int b = 10;
11 | do {
12 | System.out.println(b);
13 | b++;
14 | }while(b<5);
15 |
16 | int c = 1;
17 | do{
18 | System.out.println(c);
19 | c++;
20 | }while(c<=45);
21 |
--------------------------------------------------------------------------------
/googleb3ec120995e10cda.html:
--------------------------------------------------------------------------------
1 | google-site-verification: googleb3ec120995e10cda.html
--------------------------------------------------------------------------------