Skip to content

Commit b757e00

Browse files
harshharsh
authored andcommitted
commit
1 parent 8abd648 commit b757e00

7 files changed

Lines changed: 159 additions & 8 deletions

File tree

Hello World/.classpath

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
<classpath>
33
<classpathentry kind="src" path="src"/>
44
<classpathentry exported="true" kind="con" path="org.eclipse.jdt.USER_LIBRARY/postgres"/>
5-
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jre1.8.0_66"/>
5+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/CDC-1.0%Foundation-1.0"/>
66
<classpathentry kind="output" path="bin"/>
77
</classpath>
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
eclipse.preferences.version=1
22
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3-
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
4-
org.eclipse.jdt.core.compiler.compliance=1.8
5-
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
6-
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
7-
org.eclipse.jdt.core.compiler.source=1.8
3+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.1
4+
org.eclipse.jdt.core.compiler.compliance=1.3
5+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=ignore
6+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=ignore
7+
org.eclipse.jdt.core.compiler.release=disabled
8+
org.eclipse.jdt.core.compiler.source=1.3

Hello World/src/harshit/CheckPrimeNo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public static void main(String[] args) {
99

1010
Scanner sc=new Scanner(System.in);
1111

12-
System.out.println("Enter th No:- ");
12+
System.out.println("Enter the No:- ");
1313
int n=sc.nextInt();
1414
boolean flag=true;
1515

PracticeCoreJava/src/java8features/EmployeeStreamApplication.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import java.util.Set;
1111
import java.util.stream.Collectors;
1212

13-
//https://www.youtube.com/watch?v=4qnT-ya9HGk
13+
//https://www.youtube.com/watch?v=AFmyV43UBgc&list=PLuG8qHUzicYFKh6QWSN5TQBsclJLWsBZb&index=4
1414

1515
public class EmployeeStreamApplication {
1616
static List<Employee> employeeList = new ArrayList<Employee>();
@@ -111,6 +111,7 @@ public static void method4() {
111111
Optional<Employee> highestPaidEmployeeWrapper = employeeList.stream()
112112
.collect(Collectors.maxBy(Comparator.comparingDouble(Employee::getSalary)));
113113
System.out.println(highestPaidEmployeeWrapper.get().getName());
114+
114115
}
115116

116117
public static void method5() {
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
package multithreading;
2+
3+
//Java program to implement solution of producer
4+
//consumer problem.
5+
6+
import java.util.LinkedList;
7+
8+
public class Threadexample {
9+
public static void main(String[] args)
10+
throws InterruptedException
11+
{
12+
// Object of a class that has both produce()
13+
// and consume() methods
14+
final PC pc = new PC();
15+
16+
// Create producer thread
17+
Thread t1 = new Thread(new Runnable() {
18+
@Override
19+
public void run()
20+
{
21+
try {
22+
pc.produce();
23+
}
24+
catch (InterruptedException e) {
25+
e.printStackTrace();
26+
}
27+
}
28+
});
29+
30+
// Create consumer thread
31+
Thread t2 = new Thread(new Runnable() {
32+
@Override
33+
public void run()
34+
{
35+
try {
36+
pc.consume();
37+
}
38+
catch (InterruptedException e) {
39+
e.printStackTrace();
40+
}
41+
}
42+
});
43+
44+
// Start both threads
45+
t1.start();
46+
t2.start();
47+
48+
// t1 finishes before t2
49+
t1.join();
50+
t2.join();
51+
}
52+
53+
// This class has a list, producer (adds items to list
54+
// and consumer (removes items).
55+
public static class PC {
56+
57+
// Create a list shared by producer and consumer
58+
// Size of list is 2.
59+
LinkedList<Integer> list = new LinkedList<>();
60+
int capacity = 2;
61+
62+
// Function called by producer thread
63+
public void produce() throws InterruptedException
64+
{
65+
int value = 0;
66+
while (true) {
67+
synchronized (this)
68+
{
69+
// producer thread waits while list
70+
// is full
71+
while (list.size() == capacity)
72+
wait();
73+
74+
System.out.println("Producer produced-"
75+
+ value);
76+
77+
// to insert the jobs in the list
78+
list.add(value++);
79+
80+
// notifies the consumer thread that
81+
// now it can start consuming
82+
notify();
83+
84+
// makes the working of program easier
85+
// to understand
86+
Thread.sleep(1000);
87+
}
88+
}
89+
}
90+
91+
// Function called by consumer thread
92+
public void consume() throws InterruptedException
93+
{
94+
while (true) {
95+
synchronized (this)
96+
{
97+
// consumer thread waits while list
98+
// is empty
99+
while (list.size() == 0)
100+
wait();
101+
102+
// to retrieve the first job in the list
103+
int val = list.removeFirst();
104+
105+
System.out.println("Consumer consumed-"
106+
+ val);
107+
108+
// Wake up producer thread
109+
notify();
110+
111+
// and sleep
112+
Thread.sleep(1000);
113+
}
114+
}
115+
}
116+
}
117+
}
118+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package serialization;
2+
3+
import java.io.File;
4+
import java.io.FileInputStream;
5+
import java.io.ObjectInputStream;
6+
import java.io.ObjectOutputStream;
7+
8+
public class DeSerializationDemo {
9+
10+
public static void main(String[] args) {
11+
12+
File file = new File("C:\\Users\\harsh\\git\\CoreJava\\PracticeCoreJava\\src\\serialization\\data.txt");
13+
14+
try {
15+
FileInputStream fis = new FileInputStream(file);
16+
ObjectInputStream ois = new ObjectInputStream(fis);
17+
Student s = (Student) ois.readObject();
18+
19+
System.out.println(s.getName() + "--" + s.getRoll());
20+
21+
}catch(Exception e) {
22+
e.printStackTrace();
23+
}
24+
}
25+
26+
}

PracticeCoreJava/src/test/Demo.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ public static void main(String[] args) {
1717
//
1818
// System.out.println(employees);
1919

20+
Set<Integer> s = new HashSet<>();
21+
s.add(null);
22+
s.add(23);
23+
System.out.println(s);
24+
2025

2126
}
2227

0 commit comments

Comments
 (0)