Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit179e12f

Browse files
committed
init java in thinking
0 parents  commit179e12f

File tree

63 files changed

+1988
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+1988
-0
lines changed

‎.gitignore‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
*.swp
2+
*.swo
3+
*.metadata/*
4+
*.RemoteSystemsTempFiles/*
5+
*.recommenders/
6+
*/bin/*
7+
*.classpath
8+
*.project
9+
*/.settings/*
10+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
packagecom.chapter05;
2+
3+
importjava.util.Arrays;
4+
importjava.util.Random;
5+
6+
publicclassArrayClassObj {
7+
8+
publicstaticvoidmain(String[]args) {
9+
// TODO Auto-generated method stub
10+
Randomrand =newRandom(47);
11+
Integer[]a1 =newInteger[rand.nextInt(20)];
12+
13+
for(inti =0;i <a1.length;i++) {
14+
a1[i] =rand.nextInt(500);
15+
}
16+
17+
System.out.println(Arrays.toString(a1));
18+
19+
Integer[]a2 =newInteger[]{
20+
newInteger(1),
21+
newInteger(2),
22+
3,
23+
};
24+
25+
System.out.println(Arrays.toString(a2));
26+
27+
}
28+
29+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
packagecom.chapter05;
2+
3+
importjava.util.Arrays;
4+
importjava.util.Random;
5+
6+
publicclassArrayNew {
7+
8+
publicstaticvoidmain(String[]args) {
9+
// TODO Auto-generated method stub
10+
Randomrand =newRandom(47);
11+
int[]a1 =newint[rand.nextInt(20)];
12+
13+
System.out.println(Arrays.toString(a1));
14+
}
15+
16+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
packagecom.chapter05;
2+
3+
publicclassArraysOfPrimitives {
4+
5+
publicstaticvoidmain(String[]args) {
6+
// TODO Auto-generated method stub
7+
int[]a1 = {1,2,3,4,5};
8+
int[]a2;
9+
a2 =a1;
10+
11+
for(inti=0;i<a2.length;i++) {
12+
a1[i] =a1[i] +3;
13+
}
14+
15+
for(inti=0;i<a1.length;i++) {
16+
System.out.println(a1[i]);
17+
}
18+
}
19+
20+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
packagecom.chapter05;
2+
3+
publicclassDynaticArray {
4+
5+
publicstaticvoidmain(String[]args) {
6+
// TODO Auto-generated method stub
7+
Other.main(newString[]{"hello","fine","ok"});
8+
}
9+
10+
}
11+
12+
classOther{
13+
14+
publicstaticvoidmain(String[]args) {
15+
for(Strings:args) {
16+
System.out.println(s);
17+
}
18+
}
19+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//: concurrentcy/BasicThreads
2+
// The most basic use of the Thread class
3+
4+
packagecom.concurrency21;
5+
6+
publicclassBasicThreads {
7+
8+
publicstaticvoidmain(String[]args) {
9+
// TODO Auto-generated method stub
10+
Threadt =newThread(newLiftOff());
11+
t.start();
12+
System.out.println("Waiting for LiftOff");
13+
}
14+
15+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//: concurrency/CachedThreadPool
2+
3+
packagecom.concurrency21;
4+
5+
importjava.util.concurrent.*;
6+
7+
publicclassCachedThreadPool {
8+
9+
publicstaticvoidmain(String[]args) {
10+
// TODO Auto-generated method stub
11+
ExecutorServiceexec =Executors.newCachedThreadPool();
12+
for(inti =0;i <5;i++)
13+
exec.execute(newLiftOff());
14+
exec.shutdown();
15+
}
16+
17+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//: concunrrency/CallableDemo.java
2+
3+
packagecom.concurrency21;
4+
5+
importjava.util.concurrent.*;
6+
importjava.util.*;
7+
8+
classTaskWithResultimplementsCallable{
9+
10+
privateintid;
11+
publicTaskWithResult(intid) {
12+
this.id =id;
13+
}
14+
15+
@Override
16+
publicStringcall()throwsException {
17+
// TODO Auto-generated method stub
18+
return"Result of TaskWithResult " +this.id;
19+
}
20+
21+
}
22+
23+
24+
publicclassCallableDemo {
25+
26+
publicstaticvoidmain(Stringargs[]) {
27+
ExecutorServiceexec =Executors.newCachedThreadPool();
28+
ArrayList<Future<String>>results =newArrayList<Future<String>>();
29+
for(inti =0;i <10;i++) {
30+
results.add(exec.submit(newTaskWithResult(i)));
31+
}
32+
33+
for(Future<String>fs :results) {
34+
try{
35+
System.out.println(fs.get());
36+
}catch(InterruptedExceptione) {
37+
System.out.println(e);
38+
return;
39+
}catch(ExecutionExceptione) {
40+
System.out.println(e);
41+
return;
42+
}finally {
43+
exec.shutdown();
44+
}
45+
}
46+
}
47+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//: concurrency/FixedThreadPool.java
2+
3+
packagecom.concurrency21;
4+
5+
importjava.util.concurrent.*;
6+
7+
publicclassFixedThreadPool {
8+
9+
publicstaticvoidmain(String[]args) {
10+
// TODO Auto-generated method stub
11+
ExecutorServiceexec =Executors.newFixedThreadPool(5);
12+
for(inti =0;i <5;i++)
13+
exec.execute(newLiftOff());
14+
exec.shutdown();
15+
}
16+
17+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
packagecom.concurrency21;
2+
3+
publicclassLiftOffimplementsRunnable {
4+
5+
protectedintcountDown =10;
6+
privatestaticinttaskCount =0;
7+
privatefinalintid =taskCount++;
8+
9+
publicLiftOff() {}
10+
11+
publicLiftOff(intcountDown) {
12+
this.countDown =countDown;
13+
}
14+
15+
publicStringstatus() {
16+
return"#" +id +"(" + (countDown >0?countDown :"Liftoff!") +"). ";
17+
}
18+
19+
publicvoidrun() {
20+
while(countDown-- >0) {
21+
System.out.print(status());
22+
//Thread.yield();
23+
}
24+
}
25+
26+
publicstaticvoidmain(String[]args) {
27+
// TODO Auto-generated method stub
28+
29+
}
30+
31+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp