Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
47 changed files
with
1,861 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/> | ||
<classpathentry kind="lib" path="D:/app/Administrator/product/11.2.0/dbhome_1/jdbc/lib/ojdbc6.jar"/> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>MyProject</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 | ||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve | ||
org.eclipse.jdt.core.compiler.compliance=1.8 | ||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate | ||
org.eclipse.jdt.core.compiler.debug.localVariable=generate | ||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate | ||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error | ||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error | ||
org.eclipse.jdt.core.compiler.source=1.8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.cfxyz.demo; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.FileOutputStream; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
|
||
/** 模拟DOS系统中的COPY程序 | ||
* 命令行参数 ( 源文件 目标文件) | ||
*/ | ||
public class CopyDemo { | ||
|
||
public static void main(String[] args) throws Exception{ | ||
long start = System.currentTimeMillis(); | ||
if(args.length != 2) { //初始化参数不足两位 | ||
System.out.println("命令执行错误!"); | ||
System.exit(1); //程序退出执行 | ||
} | ||
// 如果输入参数正确了,那么应该进行文件的验证 | ||
File inFile = new File(args[0]); //第一个为源文件路径 | ||
if (!inFile.exists()) { //源文件不存在 | ||
System.out.println("源文件不存在,请确认执行路径。"); | ||
System.exit(1); //程序退出 | ||
} | ||
// 如果此时源文件正确,那么就需要定义输出文件,同时考虑到输出文件有目录 | ||
File outFile = new File(args[1]); | ||
if (!outFile.getParentFile().exists()) { | ||
outFile.getParentFile().mkdirs(); //创建目录 | ||
} | ||
// 实现文件内容的拷贝 | ||
InputStream input = new FileInputStream(inFile); | ||
OutputStream output = new FileOutputStream(outFile); | ||
// 实现文件拷贝 | ||
int temp = 0; //保存每次读取的个数 | ||
byte data[] = new byte [2048]; // 每次读取2048个字节 | ||
// 将每次读取的数据保存在字节数组里面,并且返回读取的个数 | ||
while((temp = input.read(data)) != -1) { | ||
output.write(data, 0, temp); //输出数组 | ||
} | ||
input.close(); | ||
output.close(); | ||
long end = System.currentTimeMillis(); | ||
System.out.println("拷贝完成!\n花费的时间:" + (end - start) + "毫秒"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.cfxyz.demo; | ||
|
||
import java.io.PrintStream; | ||
import java.net.Socket; | ||
import java.util.Scanner; | ||
|
||
public class EchoClient { | ||
|
||
public static void main(String[] args) throws Exception { | ||
Socket client = new Socket("localhost", 9999); //连接服务端 | ||
Scanner input = new Scanner(System.in); | ||
Scanner scan = new Scanner(client.getInputStream()); | ||
input.useDelimiter("\n"); | ||
scan.useDelimiter("\n"); | ||
PrintStream out = new PrintStream(client.getOutputStream()); | ||
boolean flag = true; | ||
while(flag) { | ||
System.out.print("请输入要发送的数据:"); | ||
if(input.hasNext()) { | ||
String str = input.next().trim(); | ||
out.println(str); //发送服务器端数据 | ||
if(str.equalsIgnoreCase("byebye")) { | ||
flag = false; //结束循环 | ||
} | ||
if(scan.hasNext()) { | ||
System.out.println(scan.next()); | ||
} | ||
} | ||
} | ||
input.close(); | ||
scan.close(); | ||
out.close(); | ||
client.close(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.cfxyz.demo; | ||
|
||
import java.io.PrintStream; | ||
import java.net.ServerSocket; | ||
import java.net.Socket; | ||
import java.util.Scanner; | ||
|
||
class EchoThread implements Runnable { | ||
private Socket client; | ||
public EchoThread(Socket client) { | ||
this.client = client; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
try { | ||
// 得到客户端输入数据以及向客户端输出数据的对象 | ||
Scanner scan = new Scanner(client.getInputStream()); | ||
PrintStream out = new PrintStream(client.getOutputStream()); | ||
boolean flag = true; | ||
while(flag) { | ||
if(scan.hasNext()) { | ||
String str = scan.next().trim(); //得到客户端发送的内容 | ||
if(str.equalsIgnoreCase("byebye")) { | ||
out.println("拜拜,下次再会!"); //程序要结束 | ||
flag = false; | ||
} else { //回应输入信息 | ||
out.println("ECHO : " + str); | ||
} | ||
} | ||
} | ||
System.out.println("客户端关闭连接....."); | ||
scan.close(); | ||
out.close(); | ||
client.close(); | ||
}catch(Exception e){ | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
|
||
public class EchoServer { | ||
|
||
public static void main(String[] args) throws Exception { | ||
ServerSocket server = new ServerSocket(9999); | ||
System.out.println("等待连接....."); | ||
boolean flag = true; | ||
while(flag) { | ||
Socket client = server.accept(); //连接客户端 | ||
new Thread(new EchoThread(client)).start(); | ||
System.out.println("客户端已经连接....."); | ||
} | ||
server.close(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.cfxyz.demo; | ||
|
||
class Foo { | ||
public Foo(Object x) { | ||
System.out.println(x); | ||
} | ||
} | ||
|
||
public class Hello { | ||
|
||
public static void main(String[] args) { | ||
int x = 0 ; | ||
Object y = null; | ||
Integer xxx = new Integer(x); | ||
Foo fx = new Foo(xxx); | ||
Foo fy = new Foo(y); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.cfxyz.demo; | ||
|
||
import java.net.Socket; | ||
import java.util.Scanner; | ||
|
||
public class HelloClient { | ||
|
||
public static void main(String[] args) throws Exception { | ||
Socket client = new Socket("localhost", 9999); //连接服务器端 | ||
//取得客户端的输入数据流对象,表示接收服务器端的输出信息 | ||
Scanner scan = new Scanner(client.getInputStream()); | ||
scan.useDelimiter("\n"); | ||
if(scan.hasNext()) { | ||
System.out.println("【回应数据】" + scan.next()); | ||
} | ||
System.out.println("关闭客户端连接"); | ||
scan.close(); | ||
client.close(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.cfxyz.demo; | ||
|
||
import java.io.PrintStream; | ||
import java.net.ServerSocket; | ||
import java.net.Socket; | ||
|
||
public class HelloServer { | ||
|
||
public static void main(String[] args) throws Exception { | ||
ServerSocket server = new ServerSocket(9999); | ||
System.out.println("等待客户端连接....."); | ||
Socket client = server.accept(); //等待客户端连接 | ||
//利用打印流完成输出 | ||
PrintStream out = new PrintStream(client.getOutputStream()); | ||
out.println("Hello World!"); | ||
System.out.println("关闭服务器端连接"); | ||
out.close(); | ||
client.close(); | ||
server.close(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.cfxyz.demo; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class TestArrayList { | ||
|
||
public static void main(String[] args) { | ||
List<String> all = new ArrayList<String>(); | ||
System.out.println("List长度:" + all.size() + ",是否为空:" + all.isEmpty()); | ||
all.add("Hello!!!"); | ||
all.add("Hello!!!"); | ||
all.add("Hello!!!"); | ||
all.add("World!!!"); | ||
System.out.println("List长度:" + all.size() + ",是否为空:" + all.isEmpty()); | ||
for(int x = 0; x < all.size(); x ++) { | ||
System.out.println(all.get(x)); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.cfxyz.demo; | ||
|
||
import java.util.Arrays; | ||
|
||
class Book implements Comparable<Book>{ //实现比较 | ||
private String title; | ||
private double price; | ||
public Book(String title, double price) { | ||
this.title = title; | ||
this.price = price; | ||
} | ||
@Override | ||
public String toString() { | ||
return "Book [title=" + title + ", price=" + price + "]\n"; | ||
} | ||
@Override | ||
public int compareTo(Book o) { | ||
if(this.price > o.price) { | ||
return 1; | ||
}else if (this.price < o.price) { | ||
return -1; | ||
}else { | ||
return 0; | ||
} | ||
} | ||
|
||
} | ||
|
||
public class TestArrays { | ||
|
||
public static void main(String[] args) { | ||
// int data[] = {1,4,5,6,7,8,9,2,3}; | ||
// java.util.Arrays.sort(data); | ||
// System.out.println(Arrays.binarySearch(data, 8)); | ||
// int dataA[] = new int [] {1,2,3}; | ||
// int dataB[] = new int [] {2,3,1}; | ||
// System.out.println(Arrays.equals(dataA, dataB)); | ||
// int dataC[] = new int [10]; | ||
// Arrays.fill(dataC, 4); | ||
// System.out.println(Arrays.toString(dataC)); | ||
Book books [] = new Book [] { | ||
new Book("java开发", 79.8), | ||
new Book("ocale开发", 239.8), | ||
new Book("android开发", 49.8), | ||
new Book("jsp开发", 34.8) | ||
}; | ||
Arrays.sort(books); | ||
System.out.println(Arrays.toString(books)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.cfxyz.demo; | ||
|
||
import java.sql.Connection; | ||
import java.sql.DriverManager; | ||
import java.sql.Statement; | ||
import java.util.Arrays; | ||
|
||
/* | ||
* Oracle数据库脚本 | ||
DROP TABLE member PURGE ; | ||
DROP SEQUENCE myseq ; | ||
CREATE SEQUENCE myseq ; | ||
CREATE TABLE member ( | ||
mid NUMBER, | ||
name VARCHAR2(20), | ||
birthday DATE DEFAULT SYSDATE , | ||
age NUMBER(3), | ||
note CLOB, | ||
CONSTRAINT pk_mid PRIMARY KEY(mid) | ||
); | ||
*/ | ||
|
||
public class TestBatch { | ||
private static final String DBDRIVER = "oracle.jdbc.driver.OracleDriver"; | ||
private static final String DBURL = "jdbc:oracle:thin:@localhost:1521:orcl"; | ||
private static final String USER = "scott"; | ||
private static final String PASSWORD = "tiger"; | ||
|
||
public static void main(String[] args) throws Exception { | ||
Class.forName(DBDRIVER); | ||
Connection conn = DriverManager.getConnection(DBURL, USER, PASSWORD); | ||
Statement stmt = conn.createStatement(); | ||
conn.setAutoCommit(false); //取消自动提交 | ||
try { | ||
stmt.addBatch("INSERT INTO member(mid,name) VALUES (myseq.nextval, '测试 A')"); | ||
stmt.addBatch("INSERT INTO member(mid,name) VALUES (myseq.nextval, '测试B')"); | ||
stmt.addBatch("INSERT INTO member(mid,name) VALUES (myseq.nextval, '测试 C')"); | ||
stmt.addBatch("INSERT INTO member(mid,name) VALUES (myseq.nextval, '测试 D')"); | ||
stmt.addBatch("INSERT INTO member(mid,name) VALUES (myseq.nextval, '测试 E')"); | ||
int result [] = stmt.executeBatch(); //执行处理 | ||
System.out.println(Arrays.toString(result)); | ||
conn.commit(); //如果没有错误,进行提交 | ||
} catch(Exception e) { | ||
e.printStackTrace(); | ||
conn.rollback(); //如果出现异常则进行回滚 | ||
} | ||
conn.close(); | ||
} | ||
|
||
} |
Oops, something went wrong.