Day 13 HttpClient/JSON Library
Exercise: Convert an JSON into an Array of Objects and vice versa. In a todo app,
do registration by accepting User attributes as a JSON
get a list of tasks as JSON.
Day 14 : IO (Total 3 hrs, Solved: 2, practice: 4)
Solved Examples (2 Questions)
Practice Questions (4 questions)
Serialization
-
Resources
Recommendation: From Day 13 Mini project should starts. Its optional to cover day 13 to 17 day. Folks grabbing things quickly can do day 13 to day 17 and then start Mini project, others who find things difficult can start their mini project and if they have time do day 15 to day 17 topics
Day 15, 16: Latest Features (Total 6 hrs, Solved: 0, practice: 0)
(Some of these can be covered with the related topics covered before)
(Whenever teaching these features, show a previous feature example along with the new feature)
-
JDK 5, 6, 7, 8, till 17
- JDK 5:
- Autoboxing/Unboxing
- Annotations
- ENUM
- Variable arguments
- Enhanced foreach loop
- static import
StringBuilder
- JDK 7:
- Diamond operator
- try with resources
- Catching multiple exceptions (Multi-catch)
- JDK 8:
Functional interfaceLambda expressions- Streams (Can be added on Day 9 if time permits)
- Java Time API ( LocalDate, LocalTime, LocalDateTime)
- JDK 9:
HTTPClient features - JDK 11
- Tasks: Convert code from one version to other
- Resource
- JDK 5:
-
Functional Interface (Java 8)
- Creating a Thread using Functional Interface
-
StreamAPI (Java 8)
- Iterating Collections with Streams
-
Lambda Expressions (Java 8)
-
Resources
Day 17: Threads (Total 3 hrs, Solved: 0, practice: 0)
-
-
Basic Introduction
- What is Thread
- Difference between a process and a thread
- Different means to create a thread
-
Writing thread-safe code
- What is Synchronization?
Exercise for writing code with Synchronization
Given them a sample code and make it thread-safe by using Synchronization
-
Resources:
Functional Interface introduction
-
Annotation
-
Hibernate Validator - Validation using Annotations
-
Log4J
-
Reflection
-
Concurrency
-
Garbage Collection
-
Lombak (Gets the repetitive tasks like getters, setters done; reduces lines of code)
-
Mockito JUnit
-
Variable naming convention from Code Complete book
Certifications
- JDK 17 Certification
- Try Enthuware subscription for JDK 17 Mock problems
Solved 1:File I/O reading CSV
package com.fssa.learnJava.corejava.day10;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
/**
* @author BharathwajSoundarara
*
*/
public class FileReadIODemo {
public static void main(String[] args) throws IOException {
//Various methods to read a file
System.out.println("-------1--------");
Path path = Paths.get("C:\\code\\javaTeaching\\IOTest\\employees.txt");
List<String> lines = Files.readAllLines(path);
for (String line : lines) {
System.out.println(line);
}
System.out.println("------2---------");
List<String> lines2 = Files.readAllLines(path,StandardCharsets.UTF_8);
StringBuilder sb = new StringBuilder();
for (String line : lines2) {
sb.append(line).append("\n");
}
System.out.println(sb);
System.out.println("------3---------");
byte[] bytes = Files.readAllBytes(path);
String content = new String(bytes);
System.out.println(content);
System.out.println("------Printing content organized way---------");
List<String> lines4 = Files.readAllLines(path,StandardCharsets.UTF_8);
ArrayList<String> arrLines = new ArrayList<String>(lines4);
String headerLine = arrLines.get(0);
String[] columns = headerLine.split(",");
System.out.println(columns[0] + "|" + columns[1] +"|" + columns[2]);
//TODO: Assignment to print the remaining of the lines as
//Name:<NAME>
//Title:
//Salary
//TODO: Find the average salary of employees
}
}
Please use this page to add frequent errors that will be shared by students
-
ClassNotFoundException during JDBC connection
-
JUNIT library linking with maven
-
Having issues while running a main method from eclipse
-
Error with the PrepareStatement: PrepareStatement
-
SQLException: Parameter index out of range (0 < 1)
- Description: When the number of question marks in the PreparedStatement and number of parameters is not equal.
Practice
Question#1: Using the ArrayList
sort a list of integers read from the user
Sample Input:
Enter numbers: 8 9 45 12 1
Sample Output:
Sorted list: 1 8 9 12 45
Question#2: Read a list Task(id, name, deadlineDate) and print them in sorted order by deadline
use the below sample class
class Task {
private int id;
private String name;
private Date deadline;
}
Sample Input
3,Coding,20221022
5,Product Design,20221001
1,Software Design, 20221007
3,Coding,20221022
Sample Output
5,Product Design,20221001
1,Software Design, 20221007
3,Coding,20221022
3,Coding,20221022
Question#3 (HOTS): Learn about Comparator and try implementing a logic where we take additional attribute for the Task called “priority” and if two tasks are pending on the same day, the sorting should be able to sort using both deadline and priority