Skip to content

Commit

Permalink
1.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
jsejee committed Aug 19, 2020
1 parent 723333b commit 4a6e2e9
Show file tree
Hide file tree
Showing 42 changed files with 1,240 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
target/
.idea/workkspace.xml
*.iml
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Packt

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
44 changes: 43 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,44 @@
# my-packt-java-11-and-12-course
Source code for the course made by Vince Zoltán Varga and me

Here you can find the source code for the course made by Vince Zoltán Varga and me: Java Tips, Tricks, and Techniques [Video]

This is the code repository for [Java: Tips, Tricks, and Techniques[Video]]( https://www.packtpub.com/programming/java-tips-tricks-and-techniques-video), published by [Packt](https://www.packtpub.com/?utm_source=github). It contains all the supporting project files necessary to work through the video course from start to finish.

## About the Video Course
Have you been looking for a course to help you cover many aspects of Java programming, some of which you may know and some you probably never knew existed? Or have you been looking for best practices and techniques to speed up your development and increase your output and efficiency? Well, you've come to the right place!

In this course, you will explore wonderful things you can do with Java 11 and 12 to improve your programming skills with proven techniques. With this course, you'll learn to implement some practical and tested techniques to avoid taking longer methods and you'll master a quicker way to develop applications using the Java 12 programming language.

By the end of this course, you will have learned some exciting Java 12 tips, best practices, and techniques. You will be able to perform tasks and get the best out of your code much more easily and rapidly.

<H2>What You Will Learn</H2>
<DIV class>

<UL>
•Explore the latest features of the newest Java Development Kit <br/>
•Build an environment in IntelliJ IDEA to develop Java 11 source code <br/>
•Be more efficient and write your own code in an up-to-date way with far fewer bugs <br/>
•Create a Java runtime environment that only includes the modules you really need for your application <br/>
•Discover new non-developer features, ranging from nest-based access control to garbage collector settings and more <br/>
•Become more confident in developing Java code thanks to the new tips and proven techniques <br/>
</LI></UL></DIV>

## Instructions and Navigation
### Assumed Knowledge
This course is for Java developers seeking to speed up the way they code; use proven techniques to write code more easily; and are looking for best practices to build better applications in Java.<br/>
If you're a CTO or a QA engineer (or are working with previous versions of Java and need an update), you will benefit greatly from this course!

### Technical Requirements <br/>
For successful completion of this course, students will require the computer systems with at least the following:<br/>

Recommended Hardware Requirements:<br/>
For an optimal experience with hands-on and practical activities, we recommend the following configuration:<br/>
• OS: Microsoft Windows 10/8/7/Vista/2003/XP (incl.64-bit), macOS 10.8.3 or higher, GNOME or KDE desktop<br/>
• Processor: Dual core processor<br/>
• Memory: 2 GB RAM minimum, 4 GB RAM recommended<br/>
• Storage: 1.5 GB hard disk space + at least 1 GB for caches<br/>
• Display: 1024x768 minimum screen resolution<br/><br/>

Software Requirements:<br/>
• JDK 12<br/>
• IntelliJ IDEA (Community Edition) <br/>
9 changes: 9 additions & 0 deletions section 2, 3 and 4/.idea/libraries/annotations_16_0_2.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions section 2, 3 and 4/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions section 2, 3 and 4/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
42 changes: 42 additions & 0 deletions section 2, 3 and 4/src/section4/P01CopyOf.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package section4;

import java.util.ArrayList;
import java.util.List;

public class P01CopyOf {
public static void main(String[] args) {
new P01CopyOf().demo();
}

private void demo() {
ArrayList<String> fields = new ArrayList<>() {{
add("Author");
add("Subject");
add("Content");
}};
ArrayList<String> criteria = new ArrayList<>() {{
add("haoyi");
add("mill");
}};
// var found = findFirst(fields, criteria);
var found = findFirst(List.copyOf(fields), criteria);
for (int i = 0; i < found.size(); ++i) {
System.out.println(fields.get(i) + ": " + found.get(i));
}
}

// Suppose this method is implemented inside a jar file,
// and we do not have it's source code.
private List<String> findFirst(List<String> fields, List<String> criteria) {
int used = criteria.size();
while (fields.size() > used) {
fields.remove(fields.size() - 1);
}
// iterate fields and criteria parallel than
return List.of(
"Lee Haoyi",
"Mill - Better Scala Builds",
"Mill is a new build tool for Scala: it compiles your ..."
);
}
}
81 changes: 81 additions & 0 deletions section 2, 3 and 4/src/section4/P02DefectiveLoops.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package section4;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class P02DefectiveLoops {
public static void main(String[] args) {
new P02DefectiveLoops().demo();
}

private void demo() {
int n = 4;
int factorial = 1;
while (n > 1) {
factorial *= n;
--n;
}
System.out.println("factorial = " + factorial);
System.out.println();

System.out.println("Fibonacci until 30: ");
int a = 0;
int b = 1;
while (b < 30) {
int fibonacci = a + b;
a = b;
b = fibonacci;
System.out.println(a);
}
System.out.println();

var people = List.of(
new Person("s1", "c1", "Joe"),
new Person("s1", "c2", "Jane"),
new Person("s2", "c1", "Jenny")
);
var peopleByStateAndCity = new HashMap<String, Map<String, List<Person>>>();
for (Person person : people) {
peopleByStateAndCity
.computeIfAbsent(person.getState(), state -> new HashMap<>())
.computeIfAbsent(person.getCity(), city -> new ArrayList<>())
.add(person);
}
System.out.println("peopleByStateAndCity = " + peopleByStateAndCity);
}

static class Person {
private final String state;
private final String city;
private final String name;

Person(String state, String city, String name) {
this.state = state;
this.city = city;
this.name = name;
}

public String getState() {
return state;
}

public String getCity() {
return city;
}

public String getName() {
return name;
}

@Override
public String toString() {
return "Person{" +
"" + state +
"," + city +
"," + name +
'}';
}
}
}
81 changes: 81 additions & 0 deletions section 2, 3 and 4/src/section4/P03PredefinedLoops.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package section4;

import java.util.List;
import java.util.Map;
import java.util.function.Supplier;
import java.util.stream.IntStream;
import java.util.stream.Stream;

import static java.util.stream.Collectors.groupingBy;

public class P03PredefinedLoops {
public static void main(String[] args) {
new P03PredefinedLoops().demo();
}

private void demo() {
int n = 4;
int factorial = IntStream.rangeClosed(1, n).reduce(1, (fact, x) -> fact * x);
System.out.println("factorial = " + factorial);
System.out.println();

Stream<Integer> fibonacci = Stream.generate(new Supplier<>() {
int a = 0;
int b = 1;

@Override
public Integer get() {
int fib = a + b;
a = b;
b = fib;
return a;
}
});
Stream<Integer> until30 = fibonacci.takeWhile(x -> x < 30);
System.out.println("Fibonacci until 30: ");
until30.forEach(System.out::println);
System.out.println();

var personStream = Stream.of(
new Person("s1", "c1", "Joe"),
new Person("s1", "c2", "Jane"),
new Person("s2", "c1", "Jenny")
);
Map<String, Map<String, List<Person>>> peopleByStateAndCity =
personStream.collect(groupingBy(Person::getState, groupingBy(Person::getCity)));
System.out.println("peopleByStateAndCity = " + peopleByStateAndCity);
}

static class Person {
private final String state;
private final String city;
private final String name;

Person(String state, String city, String name) {
this.state = state;
this.city = city;
this.name = name;
}

public String getState() {
return state;
}

public String getCity() {
return city;
}

public String getName() {
return name;
}

@Override
public String toString() {
return "Person{" +
"" + state +
"," + city +
"," + name +
'}';
}
}
}
86 changes: 86 additions & 0 deletions section 2, 3 and 4/src/section4/P04Predicates.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package section4;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;

@SuppressWarnings("WeakerAccess")
public class P04Predicates {

public static void main(String[] args) {
new P04Predicates().demo();
}

private void demo() {
Db db = new Db(List.of(
new WebPage("https://www.pear.shop/lae/epad/", "epad - pear", "Explore the " +
"newest epad. Featuring epad Pro in two sizes, epad Air, epad, and epad " +
"mini. Visit the pear site to learn, buy, and get support."),
new WebPage("https://www.jam.shop/", "Jam: ebook, epad, ephone, and pear TV " +
"management", "Jamf Pro is comprehensive enterprise management software " +
"for the pear platform, simplifying IT management for ebook, epad, ephone" +
" and pear TV."),
new WebPage("https://www.pear.shop/ca/ephone/compare/", "ephone - Compare Models " +
"- pear", "Compare features and technical specifications for all ephone " +
"models, including ephone X, ephone R and more.")
));
var result = db.search(
(contains("epad").or(contains("ephone")))
.and(contains("pear"))
.and(Predicate.not(urlContains("jam.shop")))
);
System.out.println("Search:\n(epad OR ephone) AND pear -site:jam.shop");
System.out.println("\n\nResult:\n" + result);
}

Predicate<WebPage> contains(String s) {
return textContains(s).or(titleContains(s));
}

Predicate<WebPage> urlContains(String s) {
return wepPage -> wepPage.url.toLowerCase().contains(s.toLowerCase());
}

Predicate<WebPage> titleContains(String s) {
return wepPage -> wepPage.title.toLowerCase().contains(s.toLowerCase());
}

Predicate<WebPage> textContains(String s) {
return wepPage -> wepPage.text.toLowerCase().contains(s.toLowerCase());
}
}

class Db {

private final List<WebPage> webPages;

Db(List<WebPage> db) {
this.webPages = new ArrayList<>(db);
}

List<WebPage> search(Predicate<? super WebPage> predicate) {
return webPages.stream()
.filter(predicate)
.collect(Collectors.toList());
}
}

class WebPage {
final String url;
final String title;
final String text;

WebPage(String url, String title, String text) {
this.url = url;
this.title = title;
this.text = text;
}

@Override
public String toString() {
return "\n" + title + "\n"
+ url + "\n"
+ text + "\n";
}
}
Loading

0 comments on commit 4a6e2e9

Please sign in to comment.