From 743ec21591ab6f5fd447a60a60de8b8e8c81fb3e Mon Sep 17 00:00:00 2001 From: luoamin <2293121112@qq.com> Date: Sun, 26 Feb 2017 09:54:53 +0800 Subject: [PATCH 1/2] =?UTF-8?q?testJava=E6=8F=90=E4=BA=A4=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E5=88=B0github?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .classpath | 7 + .gitignore | 181 ++++++++++++++++++ .project | 17 ++ .settings/org.eclipse.jdt.core.prefs | 11 ++ src/com/luoamin/array/ListArray.java | 44 +++++ src/com/luoamin/basic/GetResource.java | 10 + src/com/luoamin/basic/TestData.java | 25 +++ src/com/luoamin/basic/TestReturn.java | 20 ++ src/com/luoamin/basic/TestWei.java | 20 ++ src/com/luoamin/datastruct/List.java | 11 ++ src/com/luoamin/datastruct/Queue.java | 10 + src/com/luoamin/datastruct/QueueList.java | 67 +++++++ src/com/luoamin/datastruct/SeqStack.java | 47 +++++ src/com/luoamin/datastruct/SequenList.java | 83 ++++++++ src/com/luoamin/datastruct/Stack.java | 11 ++ .../luoamin/datastruct/TestSequenList.java | 25 +++ src/com/luoamin/datastruct/TestStackList.java | 23 +++ src/com/luoamin/date/GetResource.java | 10 + src/com/luoamin/date/TestDare2.java | 12 ++ src/com/luoamin/date/TestData.java | 17 ++ .../luoamin/date/TestSimpleDateFormat.java | 30 +++ .../factorymethod/BuildCreator.java | 10 + .../factorymethod/BuildLight.java | 15 ++ .../designtemplete/factorymethod/Creator.java | 5 + .../designtemplete/factorymethod/Light.java | 7 + .../designtemplete/factorymethod/Test.java | 28 +++ .../factorymethod/TubeCreator.java | 10 + .../factorymethod/TubeLight.java | 15 ++ .../factorymethod/test1/Creator.java | 9 + .../factorymethod/test1/Dianbinxiang.java | 7 + .../factorymethod/test1/Geli.java | 17 ++ .../factorymethod/test1/GeliCreator.java | 10 + .../factorymethod/test1/Haier.java | 15 ++ .../factorymethod/test1/HaierCreator.java | 10 + .../factorymethod/test1/Test.java | 20 ++ .../designtemplete/singon/Singon2.java | 12 ++ .../designtemplete/singon/Sington1.java | 14 ++ .../luoamin/designtemplete/singon/Testq.java | 25 +++ src/com/luoamin/excel/OutPutExcelData.java | 69 +++++++ src/com/luoamin/exception/Test.java | 43 +++++ src/com/luoamin/exception/TestException.java | 19 ++ .../factory/abstractfactoty/Factory.java | 12 ++ .../factory/abstractfactoty/FactoryA.java | 15 ++ .../factory/abstractfactoty/FactoryB.java | 13 ++ .../factory/abstractfactoty/IceBoxB.java | 7 + .../factory/abstractfactoty/Icebox.java | 9 + .../factory/abstractfactoty/IceboxA.java | 7 + .../luoamin/factory/abstractfactoty/Test.java | 11 ++ .../factory/abstractfactoty/Washer.java | 10 + .../factory/abstractfactoty/WasherA.java | 13 ++ .../factory/abstractfactoty/WasherB.java | 14 ++ .../abstractfactoty/test1/ClouseA.java | 5 + .../abstractfactoty/test1/ClouseA1.java | 10 + .../abstractfactoty/test1/ClouseA2.java | 10 + .../abstractfactoty/test1/ClouseB.java | 5 + .../abstractfactoty/test1/ClouseB1.java | 10 + .../abstractfactoty/test1/ClouseB2.java | 10 + .../abstractfactoty/test1/Factory.java | 10 + .../abstractfactoty/test1/Factory1.java | 15 ++ .../abstractfactoty/test1/Factory2.java | 15 ++ .../factory/abstractfactoty/test1/Test.java | 19 ++ .../luoamin/factory/simplefactory/Audi.java | 8 + .../luoamin/factory/simplefactory/Baoma.java | 10 + .../luoamin/factory/simplefactory/Benchi.java | 9 + .../luoamin/factory/simplefactory/Car.java | 9 + .../luoamin/factory/simplefactory/Driver.java | 20 ++ .../luoamin/factory/simplefactory/Test.java | 15 ++ src/com/luoamin/interfaces/DaoInteferce.java | 11 ++ src/com/luoamin/interfaces/DaoOperation.java | 5 + .../luoamin/interfaces/DaoOtherInterface.java | 7 + src/com/luoamin/interfaces/Linl.java | 10 + src/com/luoamin/interfaces/Student.java | 42 ++++ src/com/luoamin/interfaces/TestStudent.java | 40 ++++ src/com/luoamin/io/FileInputTestByMe.java | 90 +++++++++ src/com/luoamin/io/FileOperator.java | 74 +++++++ src/com/luoamin/io/FileSeparate.java | 22 +++ src/com/luoamin/io/FolderOperator.java | 71 +++++++ src/com/luoamin/io/InputStreamTest.java | 55 ++++++ src/com/luoamin/io/OutputStreamTest.java | 68 +++++++ src/com/luoamin/io/TTT.java | 20 ++ src/com/luoamin/io/TestBuffered.java | 48 +++++ src/com/luoamin/io/TextRead.java | 51 +++++ src/com/luoamin/io/ZipOutputStreamDemo2.java | 21 ++ src/com/luoamin/io/test/Test3.java | 51 +++++ .../io/test/TestConCurrentHashMap.java | 24 +++ src/com/luoamin/io/test/TestDubug.java | 30 +++ src/com/luoamin/io/test/TestFile.java | 35 ++++ src/com/luoamin/io/test/TestPlay.java | 15 ++ src/com/luoamin/io/test/TestReturn.java | 41 ++++ src/com/luoamin/io/test/TestStack.java | 31 +++ src/com/luoamin/manythreadandworks/Test.java | 23 +++ .../threadlocal/TestThreadLocal.java | 24 +++ .../TestThreadLocalConnection.java | 29 +++ .../net/inetsddress/InetAddressDemo.java | 23 +++ src/com/luoamin/net/socket/Client.java | 43 +++++ src/com/luoamin/net/socket/ManyClient.java | 36 ++++ .../luoamin/net/socket/ManyClientServer.java | 50 +++++ src/com/luoamin/net/socket/Server.java | 42 ++++ src/com/luoamin/net/socket/SocketThread.java | 46 +++++ src/com/luoamin/observer/Client.java | 13 ++ src/com/luoamin/observer/Oberservable.java | 26 +++ src/com/luoamin/observer/Observer.java | 9 + src/com/luoamin/observer/Observer1.java | 14 ++ src/com/luoamin/observer/Observer2.java | 14 ++ .../test1/JdkObserverSupportParse.java | 106 ++++++++++ src/com/luoamin/oop/Benchi.java | 26 +++ src/com/luoamin/oop/Car.java | 14 ++ .../properties/ReadPropertiesFile.java | 86 +++++++++ src/com/luoamin/properties/luoamin.properties | 3 + src/com/luoamin/proxy/Moveable.java | 8 + src/com/luoamin/proxy/Test.java | 15 ++ src/com/luoamin/proxy/Tunk.java | 25 +++ src/com/luoamin/proxy/TunkLogProxy.java | 19 ++ src/com/luoamin/proxy/TunkProxyTime.java | 22 +++ .../proxy/dynamicproxy/DynmicProxy.java | 25 +++ src/com/luoamin/proxy/dynamicproxy/Test.java | 18 ++ src/com/luoamin/proxy/dynamicproxy/Test1.java | 18 ++ .../proxy/dynamicproxy/test/DynmicProxy.java | 22 +++ .../luoamin/proxy/dynamicproxy/test/Test.java | 16 ++ src/com/luoamin/proxy/test/Car.java | 15 ++ src/com/luoamin/proxy/test/DynamicProxy.java | 20 ++ src/com/luoamin/proxy/test/LogProy.java | 15 ++ src/com/luoamin/proxy/test/Moveable.java | 5 + src/com/luoamin/proxy/test/Test1.java | 15 ++ src/com/luoamin/proxy/test/TestDymicProy.java | 14 ++ src/com/luoamin/proxy/test/TimeProy.java | 18 ++ src/com/luoamin/proxy/test/Tunk.java | 5 + src/com/luoamin/proxy/test1/Gaotie.java | 10 + src/com/luoamin/proxy/test1/Go.java | 6 + src/com/luoamin/proxy/test1/LogGo.java | 15 ++ .../luoamin/proxy/test1/TestStaticProxy.java | 13 ++ src/com/luoamin/proxy/test1/TimeGaoTie.java | 15 ++ src/com/luoamin/reflect/Person.java | 113 +++++++++++ src/com/luoamin/reflect/TestReflect.java | 10 + src/com/luoamin/reflect/test/TestPerson.java | 39 ++++ src/com/luoamin/runable/GetFile.java | 26 +++ src/com/luoamin/sorted/BulbleSorted.java | 29 +++ src/com/luoamin/sql/TestSql.java | 73 +++++++ src/com/luoamin/test/Dfff.java | 16 ++ src/com/luoamin/test/Fkkk.java | 21 ++ src/com/luoamin/test/HelloWord.java | 11 ++ src/com/luoamin/test/HellowordTest.java | 21 ++ src/com/luoamin/test/JavanTiger.java | 32 ++++ src/com/luoamin/test/Sub.java | 14 ++ src/com/luoamin/test/Tbbbb.java | 26 +++ src/com/luoamin/test/Test1.java | 39 ++++ src/com/luoamin/test/TestBoolean.java | 17 ++ src/com/luoamin/test/TestClass.java | 34 ++++ src/com/luoamin/test/TestClass2.java | 26 +++ src/com/luoamin/test/TestEquals.java | 28 +++ src/com/luoamin/test/TestHashMap.java | 72 +++++++ src/com/luoamin/test/TestInterface.java | 10 + src/com/luoamin/test/TestMap.java | 22 +++ src/com/luoamin/thread/DieSynchronized.java | 51 +++++ src/com/luoamin/thread/MyThreadDemo.java | 42 ++++ .../luoamin/thread/ProducerAndConsumer.java | 80 ++++++++ .../luoamin/thread/TestConCurrentHashMap.java | 47 +++++ src/com/luoamin/thread/TestSington.java | 16 ++ src/com/luoamin/thread/Thread2.java | 62 ++++++ .../luoamin/thread/ThreadCommunication.java | 94 +++++++++ src/com/luoamin/thread/ThreadMethod.java | 40 ++++ src/com/luoamin/thread/ThreadSington.java | 18 ++ src/com/luoamin/thread/test/DeadThread.java | 43 +++++ src/com/luoamin/thread/test/People.java | 6 + src/com/luoamin/thread/test/Test1.java | 49 +++++ src/com/luoamin/thread/test/Test3.java | 11 ++ src/com/luoamin/thread/test/Test5.java | 5 + .../thread/test/TestConCurrentHashMap.java | 61 ++++++ .../thread/test/TestProducerAndConsumer.java | 79 ++++++++ src/com/luoamin/thread/test/Yaan.java | 5 + src/com/luoamin/thread/test1/DieThread.java | 40 ++++ src/com/luoamin/thread/test1/MyThread.java | 21 ++ src/com/luoamin/thread/test1/Resource.java | 70 +++++++ src/com/luoamin/thread/test1/TestSinoton.java | 31 +++ .../thread/threadpool/BlockingQuences.java | 70 +++++++ .../thread/threadpool/FinalThreadPool.java | 46 +++++ .../thread/threadpool/MyThreadPool.java | 46 +++++ .../thread/threadpool/SuspendQuene.java | 50 +++++ src/com/luoamin/thread/threadpool/Test.java | 75 ++++++++ .../thread/threadpool/VariableThredPool.java | 80 ++++++++ src/com/luoamin/util/TestBeanUtil.java | 5 + src/com/luoamin/util/TestString.java | 10 + src/com/luoamin/util/TestUtil.java | 5 + src/com/luoamin/xml/dom/XML.java | 140 ++++++++++++++ src/com/luoamin/xml/log4j/TestDom4j.java | 101 ++++++++++ src/com/luoamin/xml/sax/Hander.java | 53 +++++ src/com/luoamin/xml/sax/SaxXmlParse.java | 43 +++++ src/testJva/Sub.java | 26 +++ src/testJva/Super.java | 5 + src/testJva/Test.java | 7 + src/testJva/TestArry.java | 44 +++++ src/testJva/TestInt.java | 25 +++ src/testJva/TestKK.java | 21 ++ src/testJva/TestTwoClass.java | 22 +++ 194 files changed, 5599 insertions(+) create mode 100644 .classpath create mode 100644 .gitignore create mode 100644 .project create mode 100644 .settings/org.eclipse.jdt.core.prefs create mode 100644 src/com/luoamin/array/ListArray.java create mode 100644 src/com/luoamin/basic/GetResource.java create mode 100644 src/com/luoamin/basic/TestData.java create mode 100644 src/com/luoamin/basic/TestReturn.java create mode 100644 src/com/luoamin/basic/TestWei.java create mode 100644 src/com/luoamin/datastruct/List.java create mode 100644 src/com/luoamin/datastruct/Queue.java create mode 100644 src/com/luoamin/datastruct/QueueList.java create mode 100644 src/com/luoamin/datastruct/SeqStack.java create mode 100644 src/com/luoamin/datastruct/SequenList.java create mode 100644 src/com/luoamin/datastruct/Stack.java create mode 100644 src/com/luoamin/datastruct/TestSequenList.java create mode 100644 src/com/luoamin/datastruct/TestStackList.java create mode 100644 src/com/luoamin/date/GetResource.java create mode 100644 src/com/luoamin/date/TestDare2.java create mode 100644 src/com/luoamin/date/TestData.java create mode 100644 src/com/luoamin/date/TestSimpleDateFormat.java create mode 100644 src/com/luoamin/designtemplete/factorymethod/BuildCreator.java create mode 100644 src/com/luoamin/designtemplete/factorymethod/BuildLight.java create mode 100644 src/com/luoamin/designtemplete/factorymethod/Creator.java create mode 100644 src/com/luoamin/designtemplete/factorymethod/Light.java create mode 100644 src/com/luoamin/designtemplete/factorymethod/Test.java create mode 100644 src/com/luoamin/designtemplete/factorymethod/TubeCreator.java create mode 100644 src/com/luoamin/designtemplete/factorymethod/TubeLight.java create mode 100644 src/com/luoamin/designtemplete/factorymethod/test1/Creator.java create mode 100644 src/com/luoamin/designtemplete/factorymethod/test1/Dianbinxiang.java create mode 100644 src/com/luoamin/designtemplete/factorymethod/test1/Geli.java create mode 100644 src/com/luoamin/designtemplete/factorymethod/test1/GeliCreator.java create mode 100644 src/com/luoamin/designtemplete/factorymethod/test1/Haier.java create mode 100644 src/com/luoamin/designtemplete/factorymethod/test1/HaierCreator.java create mode 100644 src/com/luoamin/designtemplete/factorymethod/test1/Test.java create mode 100644 src/com/luoamin/designtemplete/singon/Singon2.java create mode 100644 src/com/luoamin/designtemplete/singon/Sington1.java create mode 100644 src/com/luoamin/designtemplete/singon/Testq.java create mode 100644 src/com/luoamin/excel/OutPutExcelData.java create mode 100644 src/com/luoamin/exception/Test.java create mode 100644 src/com/luoamin/exception/TestException.java create mode 100644 src/com/luoamin/factory/abstractfactoty/Factory.java create mode 100644 src/com/luoamin/factory/abstractfactoty/FactoryA.java create mode 100644 src/com/luoamin/factory/abstractfactoty/FactoryB.java create mode 100644 src/com/luoamin/factory/abstractfactoty/IceBoxB.java create mode 100644 src/com/luoamin/factory/abstractfactoty/Icebox.java create mode 100644 src/com/luoamin/factory/abstractfactoty/IceboxA.java create mode 100644 src/com/luoamin/factory/abstractfactoty/Test.java create mode 100644 src/com/luoamin/factory/abstractfactoty/Washer.java create mode 100644 src/com/luoamin/factory/abstractfactoty/WasherA.java create mode 100644 src/com/luoamin/factory/abstractfactoty/WasherB.java create mode 100644 src/com/luoamin/factory/abstractfactoty/test1/ClouseA.java create mode 100644 src/com/luoamin/factory/abstractfactoty/test1/ClouseA1.java create mode 100644 src/com/luoamin/factory/abstractfactoty/test1/ClouseA2.java create mode 100644 src/com/luoamin/factory/abstractfactoty/test1/ClouseB.java create mode 100644 src/com/luoamin/factory/abstractfactoty/test1/ClouseB1.java create mode 100644 src/com/luoamin/factory/abstractfactoty/test1/ClouseB2.java create mode 100644 src/com/luoamin/factory/abstractfactoty/test1/Factory.java create mode 100644 src/com/luoamin/factory/abstractfactoty/test1/Factory1.java create mode 100644 src/com/luoamin/factory/abstractfactoty/test1/Factory2.java create mode 100644 src/com/luoamin/factory/abstractfactoty/test1/Test.java create mode 100644 src/com/luoamin/factory/simplefactory/Audi.java create mode 100644 src/com/luoamin/factory/simplefactory/Baoma.java create mode 100644 src/com/luoamin/factory/simplefactory/Benchi.java create mode 100644 src/com/luoamin/factory/simplefactory/Car.java create mode 100644 src/com/luoamin/factory/simplefactory/Driver.java create mode 100644 src/com/luoamin/factory/simplefactory/Test.java create mode 100644 src/com/luoamin/interfaces/DaoInteferce.java create mode 100644 src/com/luoamin/interfaces/DaoOperation.java create mode 100644 src/com/luoamin/interfaces/DaoOtherInterface.java create mode 100644 src/com/luoamin/interfaces/Linl.java create mode 100644 src/com/luoamin/interfaces/Student.java create mode 100644 src/com/luoamin/interfaces/TestStudent.java create mode 100644 src/com/luoamin/io/FileInputTestByMe.java create mode 100644 src/com/luoamin/io/FileOperator.java create mode 100644 src/com/luoamin/io/FileSeparate.java create mode 100644 src/com/luoamin/io/FolderOperator.java create mode 100644 src/com/luoamin/io/InputStreamTest.java create mode 100644 src/com/luoamin/io/OutputStreamTest.java create mode 100644 src/com/luoamin/io/TTT.java create mode 100644 src/com/luoamin/io/TestBuffered.java create mode 100644 src/com/luoamin/io/TextRead.java create mode 100644 src/com/luoamin/io/ZipOutputStreamDemo2.java create mode 100644 src/com/luoamin/io/test/Test3.java create mode 100644 src/com/luoamin/io/test/TestConCurrentHashMap.java create mode 100644 src/com/luoamin/io/test/TestDubug.java create mode 100644 src/com/luoamin/io/test/TestFile.java create mode 100644 src/com/luoamin/io/test/TestPlay.java create mode 100644 src/com/luoamin/io/test/TestReturn.java create mode 100644 src/com/luoamin/io/test/TestStack.java create mode 100644 src/com/luoamin/manythreadandworks/Test.java create mode 100644 src/com/luoamin/manythreadandworks/threadlocal/TestThreadLocal.java create mode 100644 src/com/luoamin/manythreadandworks/threadlocal/TestThreadLocalConnection.java create mode 100644 src/com/luoamin/net/inetsddress/InetAddressDemo.java create mode 100644 src/com/luoamin/net/socket/Client.java create mode 100644 src/com/luoamin/net/socket/ManyClient.java create mode 100644 src/com/luoamin/net/socket/ManyClientServer.java create mode 100644 src/com/luoamin/net/socket/Server.java create mode 100644 src/com/luoamin/net/socket/SocketThread.java create mode 100644 src/com/luoamin/observer/Client.java create mode 100644 src/com/luoamin/observer/Oberservable.java create mode 100644 src/com/luoamin/observer/Observer.java create mode 100644 src/com/luoamin/observer/Observer1.java create mode 100644 src/com/luoamin/observer/Observer2.java create mode 100644 src/com/luoamin/observer/test1/JdkObserverSupportParse.java create mode 100644 src/com/luoamin/oop/Benchi.java create mode 100644 src/com/luoamin/oop/Car.java create mode 100644 src/com/luoamin/properties/ReadPropertiesFile.java create mode 100644 src/com/luoamin/properties/luoamin.properties create mode 100644 src/com/luoamin/proxy/Moveable.java create mode 100644 src/com/luoamin/proxy/Test.java create mode 100644 src/com/luoamin/proxy/Tunk.java create mode 100644 src/com/luoamin/proxy/TunkLogProxy.java create mode 100644 src/com/luoamin/proxy/TunkProxyTime.java create mode 100644 src/com/luoamin/proxy/dynamicproxy/DynmicProxy.java create mode 100644 src/com/luoamin/proxy/dynamicproxy/Test.java create mode 100644 src/com/luoamin/proxy/dynamicproxy/Test1.java create mode 100644 src/com/luoamin/proxy/dynamicproxy/test/DynmicProxy.java create mode 100644 src/com/luoamin/proxy/dynamicproxy/test/Test.java create mode 100644 src/com/luoamin/proxy/test/Car.java create mode 100644 src/com/luoamin/proxy/test/DynamicProxy.java create mode 100644 src/com/luoamin/proxy/test/LogProy.java create mode 100644 src/com/luoamin/proxy/test/Moveable.java create mode 100644 src/com/luoamin/proxy/test/Test1.java create mode 100644 src/com/luoamin/proxy/test/TestDymicProy.java create mode 100644 src/com/luoamin/proxy/test/TimeProy.java create mode 100644 src/com/luoamin/proxy/test/Tunk.java create mode 100644 src/com/luoamin/proxy/test1/Gaotie.java create mode 100644 src/com/luoamin/proxy/test1/Go.java create mode 100644 src/com/luoamin/proxy/test1/LogGo.java create mode 100644 src/com/luoamin/proxy/test1/TestStaticProxy.java create mode 100644 src/com/luoamin/proxy/test1/TimeGaoTie.java create mode 100644 src/com/luoamin/reflect/Person.java create mode 100644 src/com/luoamin/reflect/TestReflect.java create mode 100644 src/com/luoamin/reflect/test/TestPerson.java create mode 100644 src/com/luoamin/runable/GetFile.java create mode 100644 src/com/luoamin/sorted/BulbleSorted.java create mode 100644 src/com/luoamin/sql/TestSql.java create mode 100644 src/com/luoamin/test/Dfff.java create mode 100644 src/com/luoamin/test/Fkkk.java create mode 100644 src/com/luoamin/test/HelloWord.java create mode 100644 src/com/luoamin/test/HellowordTest.java create mode 100644 src/com/luoamin/test/JavanTiger.java create mode 100644 src/com/luoamin/test/Sub.java create mode 100644 src/com/luoamin/test/Tbbbb.java create mode 100644 src/com/luoamin/test/Test1.java create mode 100644 src/com/luoamin/test/TestBoolean.java create mode 100644 src/com/luoamin/test/TestClass.java create mode 100644 src/com/luoamin/test/TestClass2.java create mode 100644 src/com/luoamin/test/TestEquals.java create mode 100644 src/com/luoamin/test/TestHashMap.java create mode 100644 src/com/luoamin/test/TestInterface.java create mode 100644 src/com/luoamin/test/TestMap.java create mode 100644 src/com/luoamin/thread/DieSynchronized.java create mode 100644 src/com/luoamin/thread/MyThreadDemo.java create mode 100644 src/com/luoamin/thread/ProducerAndConsumer.java create mode 100644 src/com/luoamin/thread/TestConCurrentHashMap.java create mode 100644 src/com/luoamin/thread/TestSington.java create mode 100644 src/com/luoamin/thread/Thread2.java create mode 100644 src/com/luoamin/thread/ThreadCommunication.java create mode 100644 src/com/luoamin/thread/ThreadMethod.java create mode 100644 src/com/luoamin/thread/ThreadSington.java create mode 100644 src/com/luoamin/thread/test/DeadThread.java create mode 100644 src/com/luoamin/thread/test/People.java create mode 100644 src/com/luoamin/thread/test/Test1.java create mode 100644 src/com/luoamin/thread/test/Test3.java create mode 100644 src/com/luoamin/thread/test/Test5.java create mode 100644 src/com/luoamin/thread/test/TestConCurrentHashMap.java create mode 100644 src/com/luoamin/thread/test/TestProducerAndConsumer.java create mode 100644 src/com/luoamin/thread/test/Yaan.java create mode 100644 src/com/luoamin/thread/test1/DieThread.java create mode 100644 src/com/luoamin/thread/test1/MyThread.java create mode 100644 src/com/luoamin/thread/test1/Resource.java create mode 100644 src/com/luoamin/thread/test1/TestSinoton.java create mode 100644 src/com/luoamin/thread/threadpool/BlockingQuences.java create mode 100644 src/com/luoamin/thread/threadpool/FinalThreadPool.java create mode 100644 src/com/luoamin/thread/threadpool/MyThreadPool.java create mode 100644 src/com/luoamin/thread/threadpool/SuspendQuene.java create mode 100644 src/com/luoamin/thread/threadpool/Test.java create mode 100644 src/com/luoamin/thread/threadpool/VariableThredPool.java create mode 100644 src/com/luoamin/util/TestBeanUtil.java create mode 100644 src/com/luoamin/util/TestString.java create mode 100644 src/com/luoamin/util/TestUtil.java create mode 100644 src/com/luoamin/xml/dom/XML.java create mode 100644 src/com/luoamin/xml/log4j/TestDom4j.java create mode 100644 src/com/luoamin/xml/sax/Hander.java create mode 100644 src/com/luoamin/xml/sax/SaxXmlParse.java create mode 100644 src/testJva/Sub.java create mode 100644 src/testJva/Super.java create mode 100644 src/testJva/Test.java create mode 100644 src/testJva/TestArry.java create mode 100644 src/testJva/TestInt.java create mode 100644 src/testJva/TestKK.java create mode 100644 src/testJva/TestTwoClass.java diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..72c2ba6 --- /dev/null +++ b/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f48790f --- /dev/null +++ b/.gitignore @@ -0,0 +1,181 @@ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ +/bin/ diff --git a/.project b/.project new file mode 100644 index 0000000..116e8bb --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + testJva + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..7341ab1 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.7 +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.7 diff --git a/src/com/luoamin/array/ListArray.java b/src/com/luoamin/array/ListArray.java new file mode 100644 index 0000000..44a6826 --- /dev/null +++ b/src/com/luoamin/array/ListArray.java @@ -0,0 +1,44 @@ +package com.luoamin.array; + +import com.luoamin.date.TestData; + +public class ListArray { + /**线程不安全:多个线程在操作共享数据时,一个线程对资源还没执行完,另一个线程也操作这个资源 + 所以导致数据不一致的问题,解决该问题办法:对于多线程只能让一个线程操作数据,其他线程只能暂时 + * */ + + public static void main(String[] args) { + MyThread ff=new MyThread(); + //多个线程操作同一个资源,即操作同一段代码 + Thread a=new Thread(ff,"thread1"); + Thread b=new Thread(ff,"thread2"); + Thread c=new Thread(ff,"thread3"); + + TestData d=new TestData(); + d.getResource();//能访问其他包的只有public + a.start(); + b.start(); + c.start(); + } +} + + +class MyThread extends Thread{ + private int ticket=100; + Object obj=new Object(); + public void run(){ + /*通过synchronized关键字,给资源加上一把锁,obj就是那把锁,随便一个什么对象都可以*/ + while(true){ + synchronized (obj) { + try { + Thread.sleep(10); + } catch (InterruptedException e) { + e.printStackTrace(); + } + if(ticket>0){ + System.out.println(Thread.currentThread().getName()+"线程买票"+ticket--); + } + } + } + } +} \ No newline at end of file diff --git a/src/com/luoamin/basic/GetResource.java b/src/com/luoamin/basic/GetResource.java new file mode 100644 index 0000000..b19dc54 --- /dev/null +++ b/src/com/luoamin/basic/GetResource.java @@ -0,0 +1,10 @@ +package com.luoamin.basic; + +public class GetResource { + + public void getG(){ + TestData d=new TestData(); + d.getResource();;//不能访问私有的getResource方法 + } + +} diff --git a/src/com/luoamin/basic/TestData.java b/src/com/luoamin/basic/TestData.java new file mode 100644 index 0000000..18ffa4d --- /dev/null +++ b/src/com/luoamin/basic/TestData.java @@ -0,0 +1,25 @@ +package com.luoamin.basic; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import com.luoamin.date.TestSimpleDateFormat; + +public class TestData extends TestSimpleDateFormat{ + + public void getData(){ + super.getCurrentDate();//继承的子类可以访问父类的protected修饰的方法,但是不能访问private的方法 + } + + public void getResource(){ + System.out.println("dsfsdf"); + Math.abs(0); + String ss=new String("KKKK"); + List list=new ArrayList(); + list.add("1"); + Iterator it=list.iterator(); + for(Iterator fg=list.iterator();fg.hasNext();){} + } + +} diff --git a/src/com/luoamin/basic/TestReturn.java b/src/com/luoamin/basic/TestReturn.java new file mode 100644 index 0000000..b1b1ca1 --- /dev/null +++ b/src/com/luoamin/basic/TestReturn.java @@ -0,0 +1,20 @@ +package com.luoamin.basic; + +public class TestReturn { + + public static void main(String[] args) { + System.out.println("当前的数据是:"+add(2,3)); + } + + public static int add(int a,int b){ + try { + return a+b; + } catch (Exception e) { + System.out.println("catch 块"); + }finally{ + System.out.println("finally 块"); + } + return 0; + } + +} diff --git a/src/com/luoamin/basic/TestWei.java b/src/com/luoamin/basic/TestWei.java new file mode 100644 index 0000000..9c10f24 --- /dev/null +++ b/src/com/luoamin/basic/TestWei.java @@ -0,0 +1,20 @@ +package com.luoamin.basic; + +import java.util.Hashtable; + +public class TestWei { + private transient String name; + public static void main(String[] args) { + int a=2; + int b=3; + b=8>>3; + System.out.println(b); + } + + public int getData(){ + float x=1; + int a=3; + return a==2?a:0; + } + +} diff --git a/src/com/luoamin/datastruct/List.java b/src/com/luoamin/datastruct/List.java new file mode 100644 index 0000000..17e4554 --- /dev/null +++ b/src/com/luoamin/datastruct/List.java @@ -0,0 +1,11 @@ +package com.luoamin.datastruct; + +public interface List { + + void insert(int i,Object obj)throws Exception; + Object delete(int i)throws Exception; + void update(int i,Object obj)throws Exception; + Object getData(int i)throws Exception; + boolean isEmpty(int size); + int getSize(); +} diff --git a/src/com/luoamin/datastruct/Queue.java b/src/com/luoamin/datastruct/Queue.java new file mode 100644 index 0000000..4abdc6a --- /dev/null +++ b/src/com/luoamin/datastruct/Queue.java @@ -0,0 +1,10 @@ +package com.luoamin.datastruct; + +public interface Queue { + void insert(Object obj)throws Exception; + Object pop()throws Exception; + Object getHead()throws Exception; + Object getFoot()throws Exception; + boolean isEmpty()throws Exception; + boolean isFull()throws Exception; +} diff --git a/src/com/luoamin/datastruct/QueueList.java b/src/com/luoamin/datastruct/QueueList.java new file mode 100644 index 0000000..da3439a --- /dev/null +++ b/src/com/luoamin/datastruct/QueueList.java @@ -0,0 +1,67 @@ +package com.luoamin.datastruct; +/** + * 利用数组实现队列 + * @author john + * + */ +public class QueueList implements Queue { + public final int defaultSize=10; + public int head;//队列头的位置 + public int foot;//队列尾的位置 + public int maxSize;//队列的最大存储个数 + Object[] queue; + public QueueList(){ + init(defaultSize); + } + public QueueList(int size){ + init(size); + } + public void init(int size){ + maxSize=size; + head=0; + foot=0; + queue=new Object[size]; + } + @Override + /*在队尾插入元素*/ + public void insert(Object obj)throws Exception { + if(foot>maxSize){ + throw new Exception("队列已满!"); + } + queue[foot]=obj; + foot++; + } + @Override + /*在队头删除元素*/ + public Object pop()throws Exception { + if(head==0){ + throw new Exception("队列为空!,不能删除"); + } + head++; + return queue[head]; + } + @Override + //获取队头元素 + public Object getHead()throws Exception { + return queue[head]; + } + @Override + //获取队尾元素 + public Object getFoot() throws Exception { + return queue[foot]; + } + @Override + /*判断队列是否为空*/ + public boolean isEmpty()throws Exception { + return head==0; + } + @Override + /*判断队列是否已满*/ + public boolean isFull() throws Exception { + return foot==maxSize; + } + + + + +} diff --git a/src/com/luoamin/datastruct/SeqStack.java b/src/com/luoamin/datastruct/SeqStack.java new file mode 100644 index 0000000..d164b43 --- /dev/null +++ b/src/com/luoamin/datastruct/SeqStack.java @@ -0,0 +1,47 @@ +package com.luoamin.datastruct; + +public class SeqStack implements Stack { + public final int defaultSize=10; + public int top;//栈的元素个数 + public int maxSize;//栈的最大存储个数 + Object[] stack; + public SeqStack(){ + init(defaultSize); + } + public SeqStack(int size){ + init(size); + } + public void init(int size){ + maxSize=size; + top=0; + stack=new Object[size]; + } + @Override + public void push(Object obj) throws Exception { + if(top>maxSize){ + throw new Exception("堆栈已满!"); + } + stack[top]=obj; + top++; + } + + @Override + public Object pop() throws Exception { + if(top==0){ + throw new Exception("堆栈为空!"); + } + top--; + return stack[top];//元素删除后,将删除的元素返回 + } + + @Override + public Object getTop() throws Exception { + return stack[top]; + } + + @Override + public boolean isEmpty() throws Exception { + return top==0; + } + +} diff --git a/src/com/luoamin/datastruct/SequenList.java b/src/com/luoamin/datastruct/SequenList.java new file mode 100644 index 0000000..30be583 --- /dev/null +++ b/src/com/luoamin/datastruct/SequenList.java @@ -0,0 +1,83 @@ +package com.luoamin.datastruct; +/** + * 线性表的操作 + * @author john + * + */ +public class SequenList implements List{ + public final int defaultSize=10;//默认线性表数据长度 + public int maxSize;//线性表最大长度,也叫线性表能够存储的数据长度 + public int size;//线性表的长度 + public Object[] listArray;//线性表数据,使用数组来实现 + public SequenList(){ + init(defaultSize); + } + public SequenList(int sz){ + init(sz); + } + public void init(int sz){ + maxSize=sz; + size=0; + listArray=new Object[sz]; + } + public void insert(int i, Object obj) throws Exception { + if(size==maxSize){ + throw new Exception("线性表已满,不能插入!"); + } + if(i>size){ + throw new Exception("数组下标越界!"); + } + //插入的时候是将插入之后的数据都向后移动一个位置,所以循环从前往后循环 + for(int j=size;j>i;j--){ + listArray[j]=listArray[j-1]; + } + listArray[i]=obj; + size++; + + } + + @Override + public Object delete(int i) throws Exception { + if(size==0){ + throw new Exception("线性表没有数据,不能删除!"); + } + if(i>size-1){ + throw new Exception("数组下标越界!"); + } + Object obj=listArray[i]; + //删除元素后面的数据每个都要往前移一个单位 + for(int j=i;jsize-1){ + throw new Exception("数组下标越界!"); + } + listArray[i]=obj; + } + + @Override + public Object getData(int i) throws Exception { + return listArray[i]; + } + + @Override + public boolean isEmpty(int size) { + return size==0; + } + + @Override + public int getSize() { + return size; + } + +} diff --git a/src/com/luoamin/datastruct/Stack.java b/src/com/luoamin/datastruct/Stack.java new file mode 100644 index 0000000..f425b75 --- /dev/null +++ b/src/com/luoamin/datastruct/Stack.java @@ -0,0 +1,11 @@ +package com.luoamin.datastruct; + +public interface Stack { + //元素进栈,添加 + void push(Object obj)throws Exception; + //元素出栈,删除 + Object pop()throws Exception; + //获取栈顶元素 + Object getTop()throws Exception; + boolean isEmpty()throws Exception; +} diff --git a/src/com/luoamin/datastruct/TestSequenList.java b/src/com/luoamin/datastruct/TestSequenList.java new file mode 100644 index 0000000..59509e8 --- /dev/null +++ b/src/com/luoamin/datastruct/TestSequenList.java @@ -0,0 +1,25 @@ +package com.luoamin.datastruct; + +public class TestSequenList { + + public static void main(String[] args) { + List list=new SequenList(10); + list.getSize(); + list.isEmpty(list.getSize()); + try { + list.insert(0, new String("dsfsdf")); + list.insert(1, new String("dsfdf")); + list.insert(2, new String("我爱你")); + list.insert(3, new String("大炮")); + list.insert(4, new String("男人")); + list.getSize(); + list.delete(4); + list.update(10, new String("快来啊")); + } catch (Exception e) { + e.printStackTrace(); + } + + + } + +} diff --git a/src/com/luoamin/datastruct/TestStackList.java b/src/com/luoamin/datastruct/TestStackList.java new file mode 100644 index 0000000..f92d7d6 --- /dev/null +++ b/src/com/luoamin/datastruct/TestStackList.java @@ -0,0 +1,23 @@ +package com.luoamin.datastruct; + +public class TestStackList { + + public static void main(String[] args) { + Stack stack=new SeqStack(10); + + try { + stack.getTop(); + boolean is=stack.isEmpty(); + stack.push("sdfsdf"); + stack.getTop(); + is=stack.isEmpty(); + System.out.println(is); + } catch (Exception e) { + e.printStackTrace(); + } + + + + } + +} diff --git a/src/com/luoamin/date/GetResource.java b/src/com/luoamin/date/GetResource.java new file mode 100644 index 0000000..aee1067 --- /dev/null +++ b/src/com/luoamin/date/GetResource.java @@ -0,0 +1,10 @@ +package com.luoamin.date; + +public class GetResource { + + public void getG(){ + TestData d=new TestData(); + d.getResource();;//不能访问私有的getResource方法 + } + +} diff --git a/src/com/luoamin/date/TestDare2.java b/src/com/luoamin/date/TestDare2.java new file mode 100644 index 0000000..87324d3 --- /dev/null +++ b/src/com/luoamin/date/TestDare2.java @@ -0,0 +1,12 @@ +package com.luoamin.date; + +import java.util.regex.Pattern; + +public class TestDare2 { + + public static void main(String[] args) { + Pattern re=Pattern.compile("ddd"); + + } + +} diff --git a/src/com/luoamin/date/TestData.java b/src/com/luoamin/date/TestData.java new file mode 100644 index 0000000..3d0715b --- /dev/null +++ b/src/com/luoamin/date/TestData.java @@ -0,0 +1,17 @@ +package com.luoamin.date; + +import java.io.RandomAccessFile; + +public class TestData extends TestSimpleDateFormat{ + + public void getData(){ + super.getCurrentDate();//继承的子类可以访问父类的protected修饰的方法,但是不能访问private的方法 + } + + public void getResource(){ + System.out.println("dsfsdf"); + Math.abs(0); + + } + +} diff --git a/src/com/luoamin/date/TestSimpleDateFormat.java b/src/com/luoamin/date/TestSimpleDateFormat.java new file mode 100644 index 0000000..c7261a9 --- /dev/null +++ b/src/com/luoamin/date/TestSimpleDateFormat.java @@ -0,0 +1,30 @@ +package com.luoamin.date; + +import java.text.ParsePosition; +import java.text.SimpleDateFormat; +import java.util.Date; + +public class TestSimpleDateFormat { + private String name; + + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + public static void main(String[] args) { + System.out.println(getCurrentDate()); + } + /** + * 将日期类型数据转换为字符串类型数据 + * @return + */ + public static String getCurrentDate(){ + Date date=new Date(); + SimpleDateFormat sim=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + String datex=sim.format(date); + return datex; + } + +} diff --git a/src/com/luoamin/designtemplete/factorymethod/BuildCreator.java b/src/com/luoamin/designtemplete/factorymethod/BuildCreator.java new file mode 100644 index 0000000..a860e77 --- /dev/null +++ b/src/com/luoamin/designtemplete/factorymethod/BuildCreator.java @@ -0,0 +1,10 @@ +package com.luoamin.designtemplete.factorymethod; + +public class BuildCreator implements Creator{ + + @Override + public Light createLight() { + return new BuildLight(); + } + +} diff --git a/src/com/luoamin/designtemplete/factorymethod/BuildLight.java b/src/com/luoamin/designtemplete/factorymethod/BuildLight.java new file mode 100644 index 0000000..564b572 --- /dev/null +++ b/src/com/luoamin/designtemplete/factorymethod/BuildLight.java @@ -0,0 +1,15 @@ +package com.luoamin.designtemplete.factorymethod; + +public class BuildLight implements Light{ + + @Override + public void turnOn() { + System.out.println("BuildLight turn on"); + } + + @Override + public void turnOff() { + System.out.println("BuildLight turn off"); + } + +} diff --git a/src/com/luoamin/designtemplete/factorymethod/Creator.java b/src/com/luoamin/designtemplete/factorymethod/Creator.java new file mode 100644 index 0000000..853d6d0 --- /dev/null +++ b/src/com/luoamin/designtemplete/factorymethod/Creator.java @@ -0,0 +1,5 @@ +package com.luoamin.designtemplete.factorymethod; + +public interface Creator { + Light createLight(); +} diff --git a/src/com/luoamin/designtemplete/factorymethod/Light.java b/src/com/luoamin/designtemplete/factorymethod/Light.java new file mode 100644 index 0000000..c8a8c94 --- /dev/null +++ b/src/com/luoamin/designtemplete/factorymethod/Light.java @@ -0,0 +1,7 @@ +package com.luoamin.designtemplete.factorymethod; + +public interface Light { + + public void turnOn(); + public void turnOff(); +} diff --git a/src/com/luoamin/designtemplete/factorymethod/Test.java b/src/com/luoamin/designtemplete/factorymethod/Test.java new file mode 100644 index 0000000..a995775 --- /dev/null +++ b/src/com/luoamin/designtemplete/factorymethod/Test.java @@ -0,0 +1,28 @@ +package com.luoamin.designtemplete.factorymethod; +/** + * 可以看到,我们使用可以随意的在具体的工厂和产品之间切换,并且不需要修改任何代码,就可以让原来的程序正常运行, + * 这也是工厂方法模式对扩展开放的表现,另外工厂方法模式弥补了简单工厂模式不满足开闭原则的诟病, + * 当我们需要增加产品时,只需要增加相应的产品和工厂类,而不需要修改现有的代码 + * + *客户端调用时不依赖于具体工厂和产品(即到底是mysql驱动,mysql数据库连接还是oracle驱动, + *oracle连接,我们程序猿不需要管的,我们只管使用抽象的driver和connection,对吧?), + *而是依赖于抽象工厂和抽象产品完成工作 + * @author john + * + */ +public class Test { + + public static void main(String[] args) { + Creator cre=new BuildCreator(); + Light li=cre.createLight(); + li.turnOn(); + li.turnOff(); + + Creator cre2=new TubeCreator(); + Light li2=cre2.createLight(); + li2.turnOn(); + li2.turnOff(); + + } + +} diff --git a/src/com/luoamin/designtemplete/factorymethod/TubeCreator.java b/src/com/luoamin/designtemplete/factorymethod/TubeCreator.java new file mode 100644 index 0000000..1b707f9 --- /dev/null +++ b/src/com/luoamin/designtemplete/factorymethod/TubeCreator.java @@ -0,0 +1,10 @@ +package com.luoamin.designtemplete.factorymethod; + +public class TubeCreator implements Creator{ + + @Override + public Light createLight() { + return new TubeLight(); + } + +} diff --git a/src/com/luoamin/designtemplete/factorymethod/TubeLight.java b/src/com/luoamin/designtemplete/factorymethod/TubeLight.java new file mode 100644 index 0000000..b72fddc --- /dev/null +++ b/src/com/luoamin/designtemplete/factorymethod/TubeLight.java @@ -0,0 +1,15 @@ +package com.luoamin.designtemplete.factorymethod; + +public class TubeLight implements Light{ + + @Override + public void turnOn() { + System.out.println("TubeLight turn on"); + } + + @Override + public void turnOff() { + System.out.println("TubeLight turn off"); + } + +} diff --git a/src/com/luoamin/designtemplete/factorymethod/test1/Creator.java b/src/com/luoamin/designtemplete/factorymethod/test1/Creator.java new file mode 100644 index 0000000..e258ad6 --- /dev/null +++ b/src/com/luoamin/designtemplete/factorymethod/test1/Creator.java @@ -0,0 +1,9 @@ +package com.luoamin.designtemplete.factorymethod.test1; +/** + * 将对象放到创建接口来创建,然后在实现了创建接口的工厂类创建对象 + * @author john + * + */ +public interface Creator { + Dianbinxiang create(); +} diff --git a/src/com/luoamin/designtemplete/factorymethod/test1/Dianbinxiang.java b/src/com/luoamin/designtemplete/factorymethod/test1/Dianbinxiang.java new file mode 100644 index 0000000..a270915 --- /dev/null +++ b/src/com/luoamin/designtemplete/factorymethod/test1/Dianbinxiang.java @@ -0,0 +1,7 @@ +package com.luoamin.designtemplete.factorymethod.test1; + +public interface Dianbinxiang { + void bindong(); + void guanbi(); + +} diff --git a/src/com/luoamin/designtemplete/factorymethod/test1/Geli.java b/src/com/luoamin/designtemplete/factorymethod/test1/Geli.java new file mode 100644 index 0000000..fa5ea26 --- /dev/null +++ b/src/com/luoamin/designtemplete/factorymethod/test1/Geli.java @@ -0,0 +1,17 @@ +package com.luoamin.designtemplete.factorymethod.test1; + +public class Geli implements Dianbinxiang{ +/** + * 具体类 + */ + @Override + public void bindong() { + System.out.println("格力电冰箱实现了冰冻功能"); + } + + @Override + public void guanbi() { + + } + +} diff --git a/src/com/luoamin/designtemplete/factorymethod/test1/GeliCreator.java b/src/com/luoamin/designtemplete/factorymethod/test1/GeliCreator.java new file mode 100644 index 0000000..b503df1 --- /dev/null +++ b/src/com/luoamin/designtemplete/factorymethod/test1/GeliCreator.java @@ -0,0 +1,10 @@ +package com.luoamin.designtemplete.factorymethod.test1; + +public class GeliCreator implements Creator { + + @Override + public Dianbinxiang create() { + return new Geli(); + } + +} diff --git a/src/com/luoamin/designtemplete/factorymethod/test1/Haier.java b/src/com/luoamin/designtemplete/factorymethod/test1/Haier.java new file mode 100644 index 0000000..27abe15 --- /dev/null +++ b/src/com/luoamin/designtemplete/factorymethod/test1/Haier.java @@ -0,0 +1,15 @@ +package com.luoamin.designtemplete.factorymethod.test1; + +public class Haier implements Dianbinxiang{ + + @Override + public void bindong() { + System.out.println("海尔电冰箱实现了冰冻功能"); + } + + @Override + public void guanbi() { + System.out.println("海尔电冰箱实现了关闭功能"); + } + +} diff --git a/src/com/luoamin/designtemplete/factorymethod/test1/HaierCreator.java b/src/com/luoamin/designtemplete/factorymethod/test1/HaierCreator.java new file mode 100644 index 0000000..3a433dc --- /dev/null +++ b/src/com/luoamin/designtemplete/factorymethod/test1/HaierCreator.java @@ -0,0 +1,10 @@ +package com.luoamin.designtemplete.factorymethod.test1; + +public class HaierCreator implements Creator { + + @Override + public Dianbinxiang create() { + return new Haier(); + } + +} diff --git a/src/com/luoamin/designtemplete/factorymethod/test1/Test.java b/src/com/luoamin/designtemplete/factorymethod/test1/Test.java new file mode 100644 index 0000000..32e6a11 --- /dev/null +++ b/src/com/luoamin/designtemplete/factorymethod/test1/Test.java @@ -0,0 +1,20 @@ +package com.luoamin.designtemplete.factorymethod.test1; + +public class Test { + + public static void main(String[] args) { + Creator or=new HaierCreator(); + //创建了海尔对象 + Dianbinxiang hi=or.create(); + hi.bindong(); + hi.guanbi(); + + + Creator or1=new GeliCreator(); + //创建了格力对象 + Dianbinxiang hi1=or1.create(); + hi1.bindong(); + hi1.guanbi(); + } + +} diff --git a/src/com/luoamin/designtemplete/singon/Singon2.java b/src/com/luoamin/designtemplete/singon/Singon2.java new file mode 100644 index 0000000..78be26e --- /dev/null +++ b/src/com/luoamin/designtemplete/singon/Singon2.java @@ -0,0 +1,12 @@ +package com.luoamin.designtemplete.singon; + +public class Singon2 { + + + private Singon2(){} + public static final Singon2 instance =new Singon2(); + //在类声明时已经初始化了对象,为恶汉式 + public static Singon2 getInstance(){ + return instance; + } +} diff --git a/src/com/luoamin/designtemplete/singon/Sington1.java b/src/com/luoamin/designtemplete/singon/Sington1.java new file mode 100644 index 0000000..6fc41b5 --- /dev/null +++ b/src/com/luoamin/designtemplete/singon/Sington1.java @@ -0,0 +1,14 @@ +package com.luoamin.designtemplete.singon; + +public class Sington1 { + + private Sington1(){} + public static Sington1 instance=null; + public static Sington1 newInstance(){ + //需要就来拿,懒汉是 + if(instance==null){ + instance=new Sington1(); + } + return instance; + } +} diff --git a/src/com/luoamin/designtemplete/singon/Testq.java b/src/com/luoamin/designtemplete/singon/Testq.java new file mode 100644 index 0000000..1658f1f --- /dev/null +++ b/src/com/luoamin/designtemplete/singon/Testq.java @@ -0,0 +1,25 @@ +package com.luoamin.designtemplete.singon; + +public class Testq { + + public static void main(String[] args) { + Sington1 sin=Sington1.newInstance(); + Sington1 sin1=Sington1.newInstance(); + + Singon2 sin3=Singon2.getInstance(); + Singon2 sin4=Singon2.getInstance(); + if(sin==sin1){ + System.out.println("sin==sin1,他们是同一个对象"); + if(sin3==sin4){ + System.out.println("sin3==sin4,他们是同一个对象"); + } + }else if(sin!=sin1){ + System.out.println("sin==sin1,他们不是同一个对象"); + }else if(sin3==sin4){ + System.out.println("sin3==sin4,他们是同一个对象"); + }else if(sin3!=sin4){ + System.out.println("sin3==sin4,他们不是同一个对象"); + } + } + +} diff --git a/src/com/luoamin/excel/OutPutExcelData.java b/src/com/luoamin/excel/OutPutExcelData.java new file mode 100644 index 0000000..37e7355 --- /dev/null +++ b/src/com/luoamin/excel/OutPutExcelData.java @@ -0,0 +1,69 @@ +package com.luoamin.excel; + +import java.awt.Label; +import java.io.OutputStream; + +public class OutPutExcelData { + public void createExcel(OutputStream os) throws WriteException,IOException { + //创建工作薄 + WritableWorkbook workbook = Workbook.createWorkbook(os); + //创建新的一页 + WritableSheet sheet = workbook.createSheet("First Sheet", 0); + //构造表头 + sheet.mergeCells(0, 0, 4, 0);//添加合并单元格,第一个参数是起始列,第二个参数是起始行,第三个参数是终止列,第四个参数是终止行 + WritableFont bold = new WritableFont(WritableFont.ARIAL,10,WritableFont.BOLD);//设置字体种类和黑体显示,字体为Arial,字号大小为10,采用黑体显示 + WritableCellFormat titleFormate = new WritableCellFormat(bold);//生成一个单元格样式控制对象 + titleFormate.setAlignment(jxl.format.Alignment.CENTRE);//单元格中的内容水平方向居中 + titleFormate.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);//单元格的内容垂直方向居中 + Label title = new Label(0,0,"JExcelApi支持数据类型详细说明",titleFormate); + sheet.setRowView(0, 600, false);//设置第一行的高度 + sheet.addCell(title); + + //创建要显示的具体内容 + WritableFont color = new WritableFont(WritableFont.ARIAL);//选择字体 + color.setColour(Colour.GOLD);//设置字体颜色为金黄色 + WritableCellFormat colorFormat = new WritableCellFormat(color); + Label formate = new Label(0,1,"数据格式",colorFormat); + sheet.addCell(formate); + Label floats = new Label(1,1,"浮点型"); + sheet.addCell(floats); + Label integers = new Label(2,1,"整型"); + sheet.addCell(integers); + Label booleans = new Label(3,1,"布尔型"); + sheet.addCell(booleans); + Label dates = new Label(4,1,"日期格式"); + sheet.addCell(dates); + + Label example = new Label(0,2,"数据示例",colorFormat); + sheet.addCell(example); + //浮点数据 + //设置下划线 + WritableFont underline= new WritableFont(WritableFont.ARIAL,WritableFont.DEFAULT_POINT_SIZE,WritableFont.NO_BOLD,false,UnderlineStyle.SINGLE); + WritableCellFormat greyBackground = new WritableCellFormat(underline); + greyBackground.setBackground(Colour.GRAY_25);//设置背景颜色为灰色 + Number number = new Number(1,2,3.1415926535,greyBackground); + sheet.addCell(number); + //整形数据 + WritableFont boldNumber = new WritableFont(WritableFont.ARIAL,10,WritableFont.BOLD);//黑体 + WritableCellFormat boldNumberFormate = new WritableCellFormat(boldNumber); + Number ints = new Number(2,2,15042699,boldNumberFormate); + sheet.addCell(ints); + //布尔型数据 + Boolean bools = new Boolean(3,2,true); + sheet.addCell(bools); + //日期型数据 + //设置黑体和下划线 + WritableFont boldDate = new WritableFont(WritableFont.ARIAL,WritableFont.DEFAULT_POINT_SIZE,WritableFont.BOLD,false,UnderlineStyle.SINGLE); + WritableCellFormat boldDateFormate = new WritableCellFormat(boldDate,DateFormats.FORMAT1); + Calendar c = Calendar.getInstance(); + Date date = c.getTime(); + DateTime dt = new DateTime(4,2,date,boldDateFormate); + sheet.addCell(dt); + //把创建的内容写入到输出流中,并关闭输出流 + workbook.write(); + workbook.close(); + os.close(); + + } + +} diff --git a/src/com/luoamin/exception/Test.java b/src/com/luoamin/exception/Test.java new file mode 100644 index 0000000..016b4fe --- /dev/null +++ b/src/com/luoamin/exception/Test.java @@ -0,0 +1,43 @@ +package com.luoamin.exception; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; + +public class Test { +/**由测试结果得知finally的代码执行一定是在函数值返回之前,但是不是爱return语句之前,这要看 + * return语句是在try块里面还是在try块之外 + * + * @param args + */ + public static void main(String[] args) { + System.out.println(getG()); + } + + public static String test11() { + try { + System.out.println("try block"); + return test12(); + }finally { + System.out.println("finally block"); + + } + } + + public static String test12() { + System.out.println("return statement"); + + return "after return"; + } + + public static String getG(){ + try { + FileInputStream file=new FileInputStream(new File("d:eee.txt")); + } catch (FileNotFoundException e) { + e.printStackTrace(); + System.out.println("你错了哦"); + } + return "我爱你"; + } + +} diff --git a/src/com/luoamin/exception/TestException.java b/src/com/luoamin/exception/TestException.java new file mode 100644 index 0000000..6ba4880 --- /dev/null +++ b/src/com/luoamin/exception/TestException.java @@ -0,0 +1,19 @@ +package com.luoamin.exception; + +public class TestException { + public static void main(String[] args) { + System.out.println("塔塔是坏人!"); + int a=3; + if(a==3){ + try { + throw new Exception("塔塔不是坏人!"); + } catch (Exception e) { + e.printStackTrace(); + } + }else{ + System.out.println("塔塔是好人!"); + } + + } + +} diff --git a/src/com/luoamin/factory/abstractfactoty/Factory.java b/src/com/luoamin/factory/abstractfactoty/Factory.java new file mode 100644 index 0000000..7731498 --- /dev/null +++ b/src/com/luoamin/factory/abstractfactoty/Factory.java @@ -0,0 +1,12 @@ +package com.luoamin.factory.abstractfactoty; +/** + * 抽象工厂模式,主要是在工厂方法的基础上在对所创建的对象进行分类 + * 好的分类能为具体工厂类的选择调用和以后的扩展提供清晰的思路 + * @author john + * + */ +public interface Factory { + + Washer createWash(); + Icebox createIcebox(); +} diff --git a/src/com/luoamin/factory/abstractfactoty/FactoryA.java b/src/com/luoamin/factory/abstractfactoty/FactoryA.java new file mode 100644 index 0000000..d31166b --- /dev/null +++ b/src/com/luoamin/factory/abstractfactoty/FactoryA.java @@ -0,0 +1,15 @@ +package com.luoamin.factory.abstractfactoty; + +public class FactoryA implements Factory{ + + @Override + public Washer createWash() { + return new WasherA(); + } + + @Override + public Icebox createIcebox() { + return new IceboxA(); + } + +} diff --git a/src/com/luoamin/factory/abstractfactoty/FactoryB.java b/src/com/luoamin/factory/abstractfactoty/FactoryB.java new file mode 100644 index 0000000..9772e1f --- /dev/null +++ b/src/com/luoamin/factory/abstractfactoty/FactoryB.java @@ -0,0 +1,13 @@ +package com.luoamin.factory.abstractfactoty; + +public class FactoryB implements Factory{ + + public Washer createWash() { + return new WasherB(); + } + + public Icebox createIcebox() { + return new IceBoxB(); + } + +} diff --git a/src/com/luoamin/factory/abstractfactoty/IceBoxB.java b/src/com/luoamin/factory/abstractfactoty/IceBoxB.java new file mode 100644 index 0000000..1639a76 --- /dev/null +++ b/src/com/luoamin/factory/abstractfactoty/IceBoxB.java @@ -0,0 +1,7 @@ +package com.luoamin.factory.abstractfactoty; + +public class IceBoxB implements Icebox{ + public IceBoxB(){ + System.out.println("冰箱B被生产出来了"); + } +} diff --git a/src/com/luoamin/factory/abstractfactoty/Icebox.java b/src/com/luoamin/factory/abstractfactoty/Icebox.java new file mode 100644 index 0000000..236bd2a --- /dev/null +++ b/src/com/luoamin/factory/abstractfactoty/Icebox.java @@ -0,0 +1,9 @@ +package com.luoamin.factory.abstractfactoty; +/** + * 冰箱 + * @author john + * + */ +public interface Icebox { + +} diff --git a/src/com/luoamin/factory/abstractfactoty/IceboxA.java b/src/com/luoamin/factory/abstractfactoty/IceboxA.java new file mode 100644 index 0000000..15b3950 --- /dev/null +++ b/src/com/luoamin/factory/abstractfactoty/IceboxA.java @@ -0,0 +1,7 @@ +package com.luoamin.factory.abstractfactoty; + +public class IceboxA implements Icebox{ + public IceboxA(){ + System.out.println("冰箱A生产出来了"); + } +} diff --git a/src/com/luoamin/factory/abstractfactoty/Test.java b/src/com/luoamin/factory/abstractfactoty/Test.java new file mode 100644 index 0000000..26d1268 --- /dev/null +++ b/src/com/luoamin/factory/abstractfactoty/Test.java @@ -0,0 +1,11 @@ +package com.luoamin.factory.abstractfactoty; + +public class Test { + public static void main(String[] args) { + FactoryA a=new FactoryA(); + Icebox ice=a.createIcebox(); + Washer was=a.createWash(); + was.washTrouse(); + } + +} diff --git a/src/com/luoamin/factory/abstractfactoty/Washer.java b/src/com/luoamin/factory/abstractfactoty/Washer.java new file mode 100644 index 0000000..d1915e2 --- /dev/null +++ b/src/com/luoamin/factory/abstractfactoty/Washer.java @@ -0,0 +1,10 @@ +package com.luoamin.factory.abstractfactoty; +/** + * 洗衣机 + * @author john + * + */ +public interface Washer { + void washTrouse(); + +} diff --git a/src/com/luoamin/factory/abstractfactoty/WasherA.java b/src/com/luoamin/factory/abstractfactoty/WasherA.java new file mode 100644 index 0000000..282ddfa --- /dev/null +++ b/src/com/luoamin/factory/abstractfactoty/WasherA.java @@ -0,0 +1,13 @@ +package com.luoamin.factory.abstractfactoty; + +public class WasherA implements Washer{ + + public WasherA(){ + System.out.println("洗衣机A生产出来了"); + } + + @Override + public void washTrouse() { + System.out.println("洗衣机A洗衣服"); + } +} diff --git a/src/com/luoamin/factory/abstractfactoty/WasherB.java b/src/com/luoamin/factory/abstractfactoty/WasherB.java new file mode 100644 index 0000000..afac281 --- /dev/null +++ b/src/com/luoamin/factory/abstractfactoty/WasherB.java @@ -0,0 +1,14 @@ +package com.luoamin.factory.abstractfactoty; + +public class WasherB implements Washer{ + + public WasherB(){ + System.out.println("洗衣机B被生产出来了"); + } + + @Override + public void washTrouse() { + System.out.println("洗衣机B洗衣服"); + + } +} diff --git a/src/com/luoamin/factory/abstractfactoty/test1/ClouseA.java b/src/com/luoamin/factory/abstractfactoty/test1/ClouseA.java new file mode 100644 index 0000000..a3e3e6b --- /dev/null +++ b/src/com/luoamin/factory/abstractfactoty/test1/ClouseA.java @@ -0,0 +1,5 @@ +package com.luoamin.factory.abstractfactoty.test1; + +public interface ClouseA { + void createA(); +} diff --git a/src/com/luoamin/factory/abstractfactoty/test1/ClouseA1.java b/src/com/luoamin/factory/abstractfactoty/test1/ClouseA1.java new file mode 100644 index 0000000..339646f --- /dev/null +++ b/src/com/luoamin/factory/abstractfactoty/test1/ClouseA1.java @@ -0,0 +1,10 @@ +package com.luoamin.factory.abstractfactoty.test1; + +public class ClouseA1 implements ClouseA{ + + @Override + public void createA() { + System.out.println("创建了衣服产品A系列产品第一件"); + } + +} diff --git a/src/com/luoamin/factory/abstractfactoty/test1/ClouseA2.java b/src/com/luoamin/factory/abstractfactoty/test1/ClouseA2.java new file mode 100644 index 0000000..94d7ece --- /dev/null +++ b/src/com/luoamin/factory/abstractfactoty/test1/ClouseA2.java @@ -0,0 +1,10 @@ +package com.luoamin.factory.abstractfactoty.test1; + +public class ClouseA2 implements ClouseA{ + + @Override + public void createA() { + System.out.println("创建了衣服产品A系列产品第二件"); + } + +} diff --git a/src/com/luoamin/factory/abstractfactoty/test1/ClouseB.java b/src/com/luoamin/factory/abstractfactoty/test1/ClouseB.java new file mode 100644 index 0000000..2c3fdfc --- /dev/null +++ b/src/com/luoamin/factory/abstractfactoty/test1/ClouseB.java @@ -0,0 +1,5 @@ +package com.luoamin.factory.abstractfactoty.test1; + +public interface ClouseB { + void creatClouseB(); +} diff --git a/src/com/luoamin/factory/abstractfactoty/test1/ClouseB1.java b/src/com/luoamin/factory/abstractfactoty/test1/ClouseB1.java new file mode 100644 index 0000000..508c537 --- /dev/null +++ b/src/com/luoamin/factory/abstractfactoty/test1/ClouseB1.java @@ -0,0 +1,10 @@ +package com.luoamin.factory.abstractfactoty.test1; + +public class ClouseB1 implements ClouseB{ + + @Override + public void creatClouseB() { + System.out.println("创建了衣服产品B系列产品第一件"); + } + +} diff --git a/src/com/luoamin/factory/abstractfactoty/test1/ClouseB2.java b/src/com/luoamin/factory/abstractfactoty/test1/ClouseB2.java new file mode 100644 index 0000000..53e6c9c --- /dev/null +++ b/src/com/luoamin/factory/abstractfactoty/test1/ClouseB2.java @@ -0,0 +1,10 @@ +package com.luoamin.factory.abstractfactoty.test1; + +public class ClouseB2 implements ClouseB{ + + @Override + public void creatClouseB() { + System.out.println("创建了衣服产品B系列产品第二件"); + } + +} diff --git a/src/com/luoamin/factory/abstractfactoty/test1/Factory.java b/src/com/luoamin/factory/abstractfactoty/test1/Factory.java new file mode 100644 index 0000000..bd652ed --- /dev/null +++ b/src/com/luoamin/factory/abstractfactoty/test1/Factory.java @@ -0,0 +1,10 @@ +package com.luoamin.factory.abstractfactoty.test1; +/** + * 这是与工厂方法不同的地方,就是在创建接口对对象分类 + * @author john + * + */ +public interface Factory { + ClouseA creatorA(); + ClouseB creatorB(); +} diff --git a/src/com/luoamin/factory/abstractfactoty/test1/Factory1.java b/src/com/luoamin/factory/abstractfactoty/test1/Factory1.java new file mode 100644 index 0000000..75f770e --- /dev/null +++ b/src/com/luoamin/factory/abstractfactoty/test1/Factory1.java @@ -0,0 +1,15 @@ +package com.luoamin.factory.abstractfactoty.test1; + +public class Factory1 implements Factory{ + + @Override + public ClouseA creatorA() { + return new ClouseA1(); + } + + @Override + public ClouseB creatorB() { + return new ClouseB1(); + } + +} diff --git a/src/com/luoamin/factory/abstractfactoty/test1/Factory2.java b/src/com/luoamin/factory/abstractfactoty/test1/Factory2.java new file mode 100644 index 0000000..ee29969 --- /dev/null +++ b/src/com/luoamin/factory/abstractfactoty/test1/Factory2.java @@ -0,0 +1,15 @@ +package com.luoamin.factory.abstractfactoty.test1; + +public class Factory2 implements Factory{ + + @Override + public ClouseA creatorA() { + return new ClouseA2(); + } + + @Override + public ClouseB creatorB() { + return new ClouseB2(); + } + +} diff --git a/src/com/luoamin/factory/abstractfactoty/test1/Test.java b/src/com/luoamin/factory/abstractfactoty/test1/Test.java new file mode 100644 index 0000000..6a9f1e0 --- /dev/null +++ b/src/com/luoamin/factory/abstractfactoty/test1/Test.java @@ -0,0 +1,19 @@ +package com.luoamin.factory.abstractfactoty.test1; +/** + * 抽象工厂模式与工厂方法模式的区别是抽象工厂对创建对象的工厂接口进行了分类 + * @author john + * + */ +public class Test { + public static void main(String[] args) { + /*创建1系列产品*/ + Factory fa=new Factory1(); + ClouseA a=fa.creatorA(); + ClouseB b=fa.creatorB(); + a.createA(); + b.creatClouseB(); + + + } + +} diff --git a/src/com/luoamin/factory/simplefactory/Audi.java b/src/com/luoamin/factory/simplefactory/Audi.java new file mode 100644 index 0000000..b656c0e --- /dev/null +++ b/src/com/luoamin/factory/simplefactory/Audi.java @@ -0,0 +1,8 @@ +package com.luoamin.factory.simplefactory; + +public class Audi implements Car{ + public void drive() { + System.out.println("奥迪车开出来了"); + } + +} diff --git a/src/com/luoamin/factory/simplefactory/Baoma.java b/src/com/luoamin/factory/simplefactory/Baoma.java new file mode 100644 index 0000000..cf2dc49 --- /dev/null +++ b/src/com/luoamin/factory/simplefactory/Baoma.java @@ -0,0 +1,10 @@ +package com.luoamin.factory.simplefactory; + +public class Baoma implements Car{ + + public void drive() { + System.out.println("宝马车开出来了"); + } + + +} diff --git a/src/com/luoamin/factory/simplefactory/Benchi.java b/src/com/luoamin/factory/simplefactory/Benchi.java new file mode 100644 index 0000000..c3a9e31 --- /dev/null +++ b/src/com/luoamin/factory/simplefactory/Benchi.java @@ -0,0 +1,9 @@ +package com.luoamin.factory.simplefactory; + +public class Benchi implements Car{ + + public void drive() { + System.out.println("奔驰车开出来了"); + } + +} diff --git a/src/com/luoamin/factory/simplefactory/Car.java b/src/com/luoamin/factory/simplefactory/Car.java new file mode 100644 index 0000000..a018c88 --- /dev/null +++ b/src/com/luoamin/factory/simplefactory/Car.java @@ -0,0 +1,9 @@ +package com.luoamin.factory.simplefactory; +/** + * 抽象角色 + * @author john + * + */ +public interface Car { + void drive(); +} diff --git a/src/com/luoamin/factory/simplefactory/Driver.java b/src/com/luoamin/factory/simplefactory/Driver.java new file mode 100644 index 0000000..1813e6d --- /dev/null +++ b/src/com/luoamin/factory/simplefactory/Driver.java @@ -0,0 +1,20 @@ +package com.luoamin.factory.simplefactory; +/** + * 司机,专门给老板开车的,也是管理车的 + * @author john + * + */ +public class Driver { + public static Car getCar(String carName){ + Car car=null; + if(carName.equals("Baoma")){ + car=new Baoma(); + }else if(carName.equals("Benchi")){ + car=new Benchi(); + }else{ + car=new Audi(); + } + return car; + } + +} diff --git a/src/com/luoamin/factory/simplefactory/Test.java b/src/com/luoamin/factory/simplefactory/Test.java new file mode 100644 index 0000000..941b7d2 --- /dev/null +++ b/src/com/luoamin/factory/simplefactory/Test.java @@ -0,0 +1,15 @@ +package com.luoamin.factory.simplefactory; + +public class Test { + public static void main(String[] args) { + /*简单工厂模式 + * 简单工厂模式有基点要素 + * 1.抽象角色(car,接口),2.具体角色(Benchi,Baoma..),3.管理具体角色的人员(司机,即 factory类) + * 4.客户端,负责运行 + * */ + + Car bao=Driver.getCar("Baoma"); + bao.drive(); + } + +} diff --git a/src/com/luoamin/interfaces/DaoInteferce.java b/src/com/luoamin/interfaces/DaoInteferce.java new file mode 100644 index 0000000..6659b59 --- /dev/null +++ b/src/com/luoamin/interfaces/DaoInteferce.java @@ -0,0 +1,11 @@ +package com.luoamin.interfaces; + +public interface DaoInteferce { + + void add(T t); + void delete(); + void update(); + Student select(); + + +} diff --git a/src/com/luoamin/interfaces/DaoOperation.java b/src/com/luoamin/interfaces/DaoOperation.java new file mode 100644 index 0000000..5eabf9f --- /dev/null +++ b/src/com/luoamin/interfaces/DaoOperation.java @@ -0,0 +1,5 @@ +package com.luoamin.interfaces; + +public interface DaoOperation extends DaoInteferce,DaoOtherInterface{ + +} diff --git a/src/com/luoamin/interfaces/DaoOtherInterface.java b/src/com/luoamin/interfaces/DaoOtherInterface.java new file mode 100644 index 0000000..d2f0f54 --- /dev/null +++ b/src/com/luoamin/interfaces/DaoOtherInterface.java @@ -0,0 +1,7 @@ +package com.luoamin.interfaces; + +public interface DaoOtherInterface { + + void log(); + +} diff --git a/src/com/luoamin/interfaces/Linl.java b/src/com/luoamin/interfaces/Linl.java new file mode 100644 index 0000000..503afba --- /dev/null +++ b/src/com/luoamin/interfaces/Linl.java @@ -0,0 +1,10 @@ +package com.luoamin.interfaces; + +public class Linl extends TestStudent { + + @Override + public void logs() { + + } + +} diff --git a/src/com/luoamin/interfaces/Student.java b/src/com/luoamin/interfaces/Student.java new file mode 100644 index 0000000..399bbf3 --- /dev/null +++ b/src/com/luoamin/interfaces/Student.java @@ -0,0 +1,42 @@ +package com.luoamin.interfaces; + +public class Student { + + private Integer id; + private String name; + private String sex; + private String address; + private String phone; + public Integer getId() { + return id; + } + public void setId(Integer id) { + this.id = id; + } + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + public String getSex() { + return sex; + } + public void setSex(String sex) { + this.sex = sex; + } + public String getAddress() { + return address; + } + public void setAddress(String address) { + this.address = address; + } + public String getPhone() { + return phone; + } + public void setPhone(String phone) { + this.phone = phone; + } + + +} diff --git a/src/com/luoamin/interfaces/TestStudent.java b/src/com/luoamin/interfaces/TestStudent.java new file mode 100644 index 0000000..4972bdb --- /dev/null +++ b/src/com/luoamin/interfaces/TestStudent.java @@ -0,0 +1,40 @@ +package com.luoamin.interfaces; + +import org.junit.Test; + +public abstract class TestStudent implements DaoOperation { + public abstract void logs(); + + @Override + public void add(Student stu) { + // TODO Auto-generated method stub + + } + + @Override + public void delete() { + + } + + @Override + public void update() { + // TODO Auto-generated method stub + + } + + @Override + public Student select() { + // TODO Auto-generated method stub + return null; + } + + @Override + public void log() { + System.out.println("实现了父类的日志"); + } + + @Test + public void tedst(){ + } + +} diff --git a/src/com/luoamin/io/FileInputTestByMe.java b/src/com/luoamin/io/FileInputTestByMe.java new file mode 100644 index 0000000..74387d1 --- /dev/null +++ b/src/com/luoamin/io/FileInputTestByMe.java @@ -0,0 +1,90 @@ +package com.luoamin.io; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintWriter; +/** + * 这里仅仅对文件进行操作 + * @author john + * + */ +public class FileInputTestByMe { + /**字节流和字符流的最终父类是InputStream和OutPutString + * 字符流的最终父类是Reader和Writer + * + * */ + + public static void fileInputstream() throws IOException{ + FileInputStream in=null; + try {//io流路径必须是这种格式D://abc.txt或者是,D:/abc.txt,就是不能是\,还有\\ + in=new FileInputStream(new File("D:/abc.txt")); + byte[] buff=new byte[1024]; + int stream=0; + while((stream=in.read(buff))>0){ + System.out.println(new String(buff,0,stream)); + } + } catch (FileNotFoundException e) { + e.printStackTrace(); + }finally{ + in.close(); + } + + } + public static void fileReader() throws IOException{ + FileReader re=null; + try { + re=new FileReader(new File("D:/applicationContext.xml")); + char[] buff=new char[50]; + int stream=0; + while((stream=re.read(buff))>0){ + System.out.println(new String(buff, 0,stream)); + } + } catch (FileNotFoundException e) { + e.printStackTrace(); + }finally{ + re.close(); + } + } + /** + * 普通的输入输出流是不能操作文件夹的 + */ + + public static void fileInLoaction() throws IOException{ + FileInputStream in =null; + try { + in=new FileInputStream(new File("D:/applicationContext.xml")); + byte[] buff=new byte[1024]; + int stream=0; + while((stream=in.read(buff))>0){ + System.out.println(new String(buff,0,stream)); + } + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + + } + + + + public static void fileIntest(){ + PrintWriter w=null; + + } + + + + public static void main(String[] args) { + try { + fileInLoaction(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + + } +} diff --git a/src/com/luoamin/io/FileOperator.java b/src/com/luoamin/io/FileOperator.java new file mode 100644 index 0000000..ca4322f --- /dev/null +++ b/src/com/luoamin/io/FileOperator.java @@ -0,0 +1,74 @@ +package com.luoamin.io; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +/** + * + * 文件拷贝 + * @author john + * + */ +public class FileOperator { + + public static void fileCopy() { +// FileInputStream in =null; +// FileOutputStream out=null; +// try { +// in=new FileInputStream("D:/abc.txt"); +// out=new FileOutputStream("E:/abc.txt"); +// byte []buff=new byte[1024]; +// int stream=0; +// while((stream=in.read(buff))>0){ +// out.write(buff, 0, stream); +// } +// +// } catch (FileNotFoundException e) { +// // TODO Auto-generated catch block +// e.printStackTrace(); +// } + FileReader in=null; + FileWriter out=null; + try { + in = new FileReader("D:/abc.txt"); + out=new FileWriter("e:/abc.txt"); + char []ff=new char[50]; + int stream =0; + while((stream=in.read(ff))>0){ + out.write(ff, 0, stream); + out.flush();// 最好加上 + } + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + }finally{ + try { + if(out!=null){ + out.close(); + } + if(in!=null){ + in.close(); + } + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + + + } + + + + public static void main(String[] args) { + fileCopy(); + } +} diff --git a/src/com/luoamin/io/FileSeparate.java b/src/com/luoamin/io/FileSeparate.java new file mode 100644 index 0000000..973accb --- /dev/null +++ b/src/com/luoamin/io/FileSeparate.java @@ -0,0 +1,22 @@ +package com.luoamin.io; + +import java.io.File; + +public class FileSeparate { + + public static void main(String[] args) { + //File.separator,文件分隔符,windows下为\,Linux下为/ + String path=File.separator+"name"+File.separator+"user"; + File file=new File("D:/luoamin/测试"); +// System.out.println(path); + //读取某个目录下面的文件或者文件夹 + File []file1=file.listFiles(); + for (File file2 : file1) { + System.out.println(file2.getPath()); + boolean a=file.delete(); + } + + + } + +} diff --git a/src/com/luoamin/io/FolderOperator.java b/src/com/luoamin/io/FolderOperator.java new file mode 100644 index 0000000..ffd8c8e --- /dev/null +++ b/src/com/luoamin/io/FolderOperator.java @@ -0,0 +1,71 @@ +package com.luoamin.io; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; + +public class FolderOperator { + private static void copyDir(String source1, String target1) throws IOException { + File source = new File(source1); + File target = new File(target1); + target.mkdirs(); + File[] files = source.listFiles(); + for(int a=0;a 0){ + //取出字节,将字节数组转化为字符串输出 + System.out.println(new String(bbuf, 0 , hasRead)); + } + }finally{ + //关闭文件输入流 + fis.close(); + } + } + /** + * 使用FileReader读取该类本身 + * */ + public static void FileReaderTest() throws Exception{ + FileReader fr = null; + try{ + //创建字节输入流 + fr = new FileReader("src/xidian/sl/io/InputStreamTest.java"); + //创建一个长度为1024的字节数组来存取 + char[] bbuf = new char[40]; + //用于保存实际读取的字节数 + int hasRead = 0; + //使用循环来进行重复读取 + while((hasRead = fr.read(bbuf))> 0){ + //取出字节,将字节数组转化为字符串输出 + System.out.println(new String(bbuf, 0 , hasRead)); + } + }finally{ + //关闭文件输入流 + fr.close(); + } + } + public static void main(String[] args) throws Exception{ + InputStreamTest.FileInputStreamTest(); + InputStreamTest.FileReaderTest(); + } +} \ No newline at end of file diff --git a/src/com/luoamin/io/OutputStreamTest.java b/src/com/luoamin/io/OutputStreamTest.java new file mode 100644 index 0000000..05ffb54 --- /dev/null +++ b/src/com/luoamin/io/OutputStreamTest.java @@ -0,0 +1,68 @@ +package com.luoamin.io; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.FileWriter; + +public class OutputStreamTest { + /** + * 使用字节流输出 + * */ + public static void FileOutputStreamTest() throws Exception{ + FileInputStream fis = null; + FileOutputStream fos = null; + try{ + //创建字节输入流 + fis = new FileInputStream("src/xidian/sl/io/InputStreamTest.java"); + //创建字节输出流 + fos = new FileOutputStream("src/xidian/sl/io/Output.txt"); + byte[] bt = new byte[40]; + int hasRead = 0; + //循环从输入流中读取数据 + while((hasRead = fis.read(bt))> 0){ + //每读取一个,即写入文件输出流,读了多少就写多少 + fos.write(bt, 0, hasRead); + } + + }catch (Exception e) { + e.printStackTrace(); + }finally{ + /** + * 流在关闭时会自动执行flash,将缓冲中的数据flush到物理节点中 + * 所以关闭时很重要的 + * */ + if(fis != null){ + fis.close(); + } + if(fos != null){ + fos.close(); + } + } + } + /** + * 使用字符流输出字符串会显得比较的方便 + * */ + public static void FileWriteTest() throws Exception{ + FileWriter fw = null; + try{ + //创建字节输出流 + fw = new FileWriter("src/xidian/sl/io/Output.txt"); + fw.write("温州医学院\r\n"); + fw.write("信息与管理专业\r\n"); + fw.write("温州医学院\r\n"); + fw.write("温州医学院\n"); + fw.write("温州医学院"); + }catch (Exception e) { + e.printStackTrace(); + }finally{ + if(fw != null){ + fw.close(); + } + } + } + public static void main(String[] args) throws Exception{ + OutputStreamTest.FileOutputStreamTest(); + OutputStreamTest.FileWriteTest(); + } +} \ No newline at end of file diff --git a/src/com/luoamin/io/TTT.java b/src/com/luoamin/io/TTT.java new file mode 100644 index 0000000..a61571b --- /dev/null +++ b/src/com/luoamin/io/TTT.java @@ -0,0 +1,20 @@ +package com.luoamin.io; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.PrintWriter; + +public class TTT { + + public void print(){ + try { + PrintWriter ww=new PrintWriter("D:/luoamin/测试/aaa.txt"); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + } + + + public static void main(String[] args) throws Exception { + + } +} \ No newline at end of file diff --git a/src/com/luoamin/io/TestBuffered.java b/src/com/luoamin/io/TestBuffered.java new file mode 100644 index 0000000..f14ade1 --- /dev/null +++ b/src/com/luoamin/io/TestBuffered.java @@ -0,0 +1,48 @@ +package com.luoamin.io; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + +public class TestBuffered { + + + public static void fileOperator(){ + BufferedReader re =null; + BufferedWriter w=null; + try { + re=new BufferedReader(new FileReader("d:/abc.txt")); + w=new BufferedWriter(new FileWriter("e:/abc.txt")); + char []buff=new char[50]; + int stream=0; + while((stream=re.read(buff))>0){ + w.write(buff, 0, stream); + w.flush(); + } + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + }finally{ + try { + w.close(); + re.close(); + } catch (IOException e) { + e.printStackTrace(); + } + + } + + + } + + + public static void main(String[] args) { + fileOperator(); + } + +} diff --git a/src/com/luoamin/io/TextRead.java b/src/com/luoamin/io/TextRead.java new file mode 100644 index 0000000..187b0e6 --- /dev/null +++ b/src/com/luoamin/io/TextRead.java @@ -0,0 +1,51 @@ +package com.luoamin.io; +import java.io.*; +public class TextRead{ + + public static void copyfile() throws IOException{ + + + } + + public static void filePrint(){ + File fin,fout; + BufferedReader bf = null; + PrintWriter pw = null; + try{ + fin = new File("D:/abc.txt"); //注意文件与程序都要在同一个文件夹下。zzc.txt为要被复制的文件。 + fout = new File("e:/abc.txt"); //如果没有会自动创建。 + bf = new BufferedReader(new FileReader(fin)); + pw = new PrintWriter(fout); //PrintWriter为打印流,也可以使用BufferedWriter. + String line = bf.readLine(); + while(line!=null){ + pw.println(line); + line = bf.readLine(); + } + }catch(Exception e){ + e.printStackTrace(); + }finally{ + try{ + //关闭 文件。 + if(bf!=null){ + bf.close(); + bf = null; + } + if(pw!=null){ + pw.close(); + pw = null; + } + }catch(Exception e){ + e.printStackTrace(); + } + } + + } + + + +public static void main(String[] args) throws IOException{ + File file=new File("D:/abc.txt"); + String f=File.separator;//系统分隔符,此处运行的结果是\ + System.out.println(f); +} +} \ No newline at end of file diff --git a/src/com/luoamin/io/ZipOutputStreamDemo2.java b/src/com/luoamin/io/ZipOutputStreamDemo2.java new file mode 100644 index 0000000..0985ec9 --- /dev/null +++ b/src/com/luoamin/io/ZipOutputStreamDemo2.java @@ -0,0 +1,21 @@ +package com.luoamin.io; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; +import java.util.zip.ZipOutputStream; + +/** + * 一次性压缩多个文件 + * */ +public class ZipOutputStreamDemo2{ + public static void main(String[] args) throws IOException{ + File file = new File("d:" + File.separator +"hello.zip"); + ZipFile zipFile = new ZipFile(file); + System.out.println("压缩文件的名称为:" + zipFile.getName()); + } + +} \ No newline at end of file diff --git a/src/com/luoamin/io/test/Test3.java b/src/com/luoamin/io/test/Test3.java new file mode 100644 index 0000000..700cc4f --- /dev/null +++ b/src/com/luoamin/io/test/Test3.java @@ -0,0 +1,51 @@ +package com.luoamin.io.test; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + +public class Test3 { + + public static void cpFile()throws IOException{ + //readLine是缓冲流的专用方法 + /*这里注意一点,因为aaa.txt文件是以asni的编码格式保存的,而eclipse的文件是以utf-8的格式 + 保存的,编码格式不一样,所以写出的文件会是乱码,输出的文本会是乱码 + */ + BufferedReader in=null; + BufferedWriter out=null; + try { + in=new BufferedReader(new FileReader("D:/luoamin/测试/aaa.txt")); + out=new BufferedWriter(new FileWriter("D:/luoamin/测试/bbb.txt")); + String b=""; + while((b=in.readLine())!=null){ + out.write(b); + System.out.println(b); + out.flush(); + } + } catch ( IOException e) { + e.printStackTrace(); + }finally{ + out.close(); + in.close(); + } + } + + public static void main(String[] args) { + +// File file=new File("D:/luoamin/测试/ccc.txt"); +// file.mkdir(); + try { + cpFile(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + +} diff --git a/src/com/luoamin/io/test/TestConCurrentHashMap.java b/src/com/luoamin/io/test/TestConCurrentHashMap.java new file mode 100644 index 0000000..af423a0 --- /dev/null +++ b/src/com/luoamin/io/test/TestConCurrentHashMap.java @@ -0,0 +1,24 @@ +package com.luoamin.io.test; + +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; +import java.util.concurrent.ConcurrentHashMap; + +public class TestConCurrentHashMap { + + public static void main(String[] args) { + Map conMap = new HashMap(); + for (long i = 0; i < 15; i++) { + conMap.put(i, i + ""); + } + + for (Entry entry : conMap.entrySet()) { + long key = entry.getKey(); + if (key < 10) { + conMap.remove(key); + } + } + + } +} diff --git a/src/com/luoamin/io/test/TestDubug.java b/src/com/luoamin/io/test/TestDubug.java new file mode 100644 index 0000000..3f58c34 --- /dev/null +++ b/src/com/luoamin/io/test/TestDubug.java @@ -0,0 +1,30 @@ +package com.luoamin.io.test; + +import java.util.Random; + +public class TestDubug { + + public static void main(String[] args) { + getM(0); + } + + private static int value=0; + + public static int getValue() { + return value; + } + + public static void setValue(int value) { + TestDubug.value = value; + } + + public static void getM(int count){ + System.out.println("你们好啊"); + int a=3; + value=new Random().nextInt(10); + int b=a+count; + System.out.println("任务完成!"); + System.out.println(b); + } + +} diff --git a/src/com/luoamin/io/test/TestFile.java b/src/com/luoamin/io/test/TestFile.java new file mode 100644 index 0000000..3024ccb --- /dev/null +++ b/src/com/luoamin/io/test/TestFile.java @@ -0,0 +1,35 @@ +package com.luoamin.io.test; + +import java.io.File; +import java.util.HashMap; +import java.util.Map; + /** + * 该方法是输出文件夹下面所有的文件,不管里面有几层文件夹 + * map可以不要,多余 + * */ +public class TestFile { + public static void listfile(File file,Mapmap){ + //如果file代表的不是一个文件,而是一个目录 + if(!file.isFile()){ + //列出该目录下的所有文件和目录 + File files[] = file.listFiles(); + //遍历files[]数组 + for(File f : files){ + //递归 + listfile(f,map); + } + }else{ + System.out.println(file); + } + + } + + + public static void main(String[] args) { + File file=new File("D:/luoamin/测试"); + Map map=new HashMap(); + listfile(file,map); + + } + +} diff --git a/src/com/luoamin/io/test/TestPlay.java b/src/com/luoamin/io/test/TestPlay.java new file mode 100644 index 0000000..054b93d --- /dev/null +++ b/src/com/luoamin/io/test/TestPlay.java @@ -0,0 +1,15 @@ +package com.luoamin.io.test; + +import java.util.Scanner; + +public class TestPlay { + + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in);// 创建输入流扫描器 + System.out.println("请输入你的身份证号:");// 提示用户输入 + String line = scanner.nextLine();// 获取用户输入的一行文本 + // 打印对输入文本的描述 + System.out.println("原来你身份证号是" + line.length() + "位数字的啊"); + } + +} diff --git a/src/com/luoamin/io/test/TestReturn.java b/src/com/luoamin/io/test/TestReturn.java new file mode 100644 index 0000000..943b23b --- /dev/null +++ b/src/com/luoamin/io/test/TestReturn.java @@ -0,0 +1,41 @@ +package com.luoamin.io.test; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +/** + * try块中如果有一个return语句,那么他是会执行的,但是在finally语句之前 + * 如果try块出现异常,一样会执行finally里面的代码 + * */ +public class TestReturn { + + public static void main(String[] args) { + + Mapmap=new ConcurrentHashMap(); + String sss=getLog(); + System.out.println(sss); + try { + throw new ClassNotFoundException("代码运行"); + } catch (Exception e) { + e.printStackTrace(); + } + } + + + public static String getLog(){ + System.out.println("我爱中国!"); + try{ + Class.forName("com.luoamin.io.test.TestFile"); + System.out.println("程序执行中。。。。。。。"); + System.exit(0);//代码执行到这里 + return "true"; + + }catch(ClassNotFoundException e){ + e.printStackTrace(); + return null; + }finally{ + System.out.println("程序执行完毕!"); + } + } + +} diff --git a/src/com/luoamin/io/test/TestStack.java b/src/com/luoamin/io/test/TestStack.java new file mode 100644 index 0000000..1ef1a34 --- /dev/null +++ b/src/com/luoamin/io/test/TestStack.java @@ -0,0 +1,31 @@ +package com.luoamin.io.test; + +import java.util.LinkedList; +import java.util.List; + +public class TestStack { + + public static void main(String[] args) { + getConnection(); + + } + + public static String getString(){ + String str=null; + String a=""; + if(str.equals("a")){ + System.out.println("此"); + } + System.out.println("dsfdsf"); + a="erew"; + return a; + } + + public static void getConnection(){ + Listlist=new LinkedList(); + list.add("f"); + list.add("b"); + String a=list.remove(0); + } + +} diff --git a/src/com/luoamin/manythreadandworks/Test.java b/src/com/luoamin/manythreadandworks/Test.java new file mode 100644 index 0000000..3d2a9b8 --- /dev/null +++ b/src/com/luoamin/manythreadandworks/Test.java @@ -0,0 +1,23 @@ +package com.luoamin.manythreadandworks; + +public class Test { + volatile int a = 1; + volatile boolean ready; + + public class PrintA extends Thread{ + @Override + public void run() { + while(!ready){ + Thread.yield(); + } + System.out.println(a); + } + } + public static void main(String[] args) throws InterruptedException { + Test t = new Test(); + t.new PrintA().start(); + //下面两行如果不加volatile的话,执行的先后顺序是不可预测的。并且下面两行都是原子操作,但是这两行作为一个整体的话就不是一个原子操作。 + t.a = 48; //这是一个原子操作,但是其结果不一定具有可见性。加上volatile后就具备了可见性。 + t.ready = true;//同理 + } +} diff --git a/src/com/luoamin/manythreadandworks/threadlocal/TestThreadLocal.java b/src/com/luoamin/manythreadandworks/threadlocal/TestThreadLocal.java new file mode 100644 index 0000000..15c5786 --- /dev/null +++ b/src/com/luoamin/manythreadandworks/threadlocal/TestThreadLocal.java @@ -0,0 +1,24 @@ +package com.luoamin.manythreadandworks.threadlocal; + +import java.sql.Connection; +/** + * ThreadLocal解决线程安全问题 + * 因为下面的Connection对象在有的时候就不创建了,就是想一个单利的对象 + * 然后实现对象共享 + * @author john + *ThreadLocal直接放在DAO只能做到本DAO的多个方法共享Connection时不发生线程安全问题 + *,但无法和其它DAO共用同一个Connection,要做到同一事务多DAO共享同一Connection, + *必须在一个共同的外部类使用ThreadLocal保存Connection + */ +public class TestThreadLocal { + private static ThreadLocal local=new ThreadLocal(); + public static Connection getConnection(){ + if(local.get()==null){ + Connection con=getConnection(); + local.set(con); + return con; + }else{ + return local.get(); + } + } +} diff --git a/src/com/luoamin/manythreadandworks/threadlocal/TestThreadLocalConnection.java b/src/com/luoamin/manythreadandworks/threadlocal/TestThreadLocalConnection.java new file mode 100644 index 0000000..d685f1d --- /dev/null +++ b/src/com/luoamin/manythreadandworks/threadlocal/TestThreadLocalConnection.java @@ -0,0 +1,29 @@ +package com.luoamin.manythreadandworks.threadlocal; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; + +public class TestThreadLocalConnection { + private static ThreadLocallocal=new ThreadLocal(); + + /*重写ThreadLocal的initialValue方法,他的返回值为Object对象*/ + public static Connection initialValue(){ + Connection con=null; + try { + con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root"); + } catch (SQLException e) { + e.printStackTrace(); + } + return con; + } + + /*获取数据库连接*/ + public static Connection getConnection(){ + return local.get(); + } + public static void setConnection(Connection con){ + local.set(con); + } + +} diff --git a/src/com/luoamin/net/inetsddress/InetAddressDemo.java b/src/com/luoamin/net/inetsddress/InetAddressDemo.java new file mode 100644 index 0000000..31052b6 --- /dev/null +++ b/src/com/luoamin/net/inetsddress/InetAddressDemo.java @@ -0,0 +1,23 @@ +package com.luoamin.net.inetsddress; + +import java.net.InetAddress; +import java.net.UnknownHostException; + +public class InetAddressDemo { + + public static void main(String[] args) { + try { + //通过网络主机域名,获取InetAddress对象,[B@2d205042 + InetAddress add=InetAddress.getByName("www.baidu.com"); + //通过byte[]的原始IP来InetAddress对象 + InetAddress.getByAddress(new byte[205042]); + //返回本地主机 + InetAddress ff=InetAddress.getLocalHost(); + /*获取InetAddress对象后可以获取主机名,和IP地址*/ + System.out.println(add.getAddress()); + } catch (UnknownHostException e) { + e.printStackTrace(); + } + } + +} diff --git a/src/com/luoamin/net/socket/Client.java b/src/com/luoamin/net/socket/Client.java new file mode 100644 index 0000000..229c8c5 --- /dev/null +++ b/src/com/luoamin/net/socket/Client.java @@ -0,0 +1,43 @@ +package com.luoamin.net.socket; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.Socket; +import java.net.UnknownHostException; + +public class Client { + public static void main(String[] args) { + Socket socket=null; + OutputStream out=null; + InputStream in=null; + try { + /* 我们的服务端处理客户端的连接请求是同步进行的, 每次接收到来自客户端的连接请求后, + * 都要先跟当前的客户端通信完之后才能再处理下一个连接请求。 这在并发比较多的情况下会严重影响程序的性能, + * 为此,我们可以把它改为如下这种异步处理与客户端通信的方式 + */ + socket =new Socket("127.0.0.1", 8888); + socket.setSoTimeout(6000);//设置socket超时时间 + out=socket.getOutputStream(); + out.write("服务器,你好,我是客户端JOJO".getBytes()); + in=socket.getInputStream(); + byte[] b=new byte[1024]; + int num=0; + while((num=in.read(b))!=-1){ + System.out.println("客户端收到答复"+new String(b,0,num)); + } + } catch (UnknownHostException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + }finally{ + try { + socket.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + } + +} diff --git a/src/com/luoamin/net/socket/ManyClient.java b/src/com/luoamin/net/socket/ManyClient.java new file mode 100644 index 0000000..a8cbf0e --- /dev/null +++ b/src/com/luoamin/net/socket/ManyClient.java @@ -0,0 +1,36 @@ +package com.luoamin.net.socket; +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.net.Socket; +/** * Socket客户端 +* 功能说明: * * @author 大智若愚的小懂 * +* @Date 2016年8月30日 * @version 1.0 +* */ +public class ManyClient { + public static void main(String[] args) { + Socket sk = null; + BufferedReader br = null; + try { + sk = new Socket("localhost", 8899); + + br = new BufferedReader(new InputStreamReader(sk.getInputStream())); + String line = null; + while((line = br.readLine()) != null){ + System.out.println("我来了:"+line); //服务器端打印客户端发送的信息数据 + } + } catch (Exception ex) { + System.out.println(ex.getMessage()); + } finally { + try { + if (sk != null) { + sk.close(); + } + if (br != null) { + br.close(); + } + } catch (Exception ex) { + System.out.println(ex.getMessage()); + } + } + } +} diff --git a/src/com/luoamin/net/socket/ManyClientServer.java b/src/com/luoamin/net/socket/ManyClientServer.java new file mode 100644 index 0000000..c3a9eb4 --- /dev/null +++ b/src/com/luoamin/net/socket/ManyClientServer.java @@ -0,0 +1,50 @@ +package com.luoamin.net.socket; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.io.Writer; +import java.net.ServerSocket; +import java.net.Socket; +/** + * 多次启动客户端就可以实现多个客户端连接服务器 + * @author john + * + */ +public class ManyClientServer { + public static void main(String [] args){ + ServerSocket ss = null; + Socket sk = null; + int count=0; + try{ + System.out.println("create server socket...."); + ss = new ServerSocket(8899); + System.out.println("wait for a connection...."); + while(true) //服务器端一直监听这个端口,等待客户端的连接 + { + sk = ss.accept(); //当有客户端连接时,产生阻塞 + System.out.println("get a socket object..."); + new SocketThread(sk).start();//新建一个socketThread处理这个客户端的socket连接 + count++; + System.out.println("客户端数量"+count); + } + } + catch(Exception ex){ + System.out.println(ex.getMessage()); + } + finally{ + try{ + if(ss != null){ + ss.close(); + } + if(sk != null){ + sk.close(); + } + } + catch(Exception ex){ + System.out.println(ex.getMessage()); + } + } + } +} diff --git a/src/com/luoamin/net/socket/Server.java b/src/com/luoamin/net/socket/Server.java new file mode 100644 index 0000000..8a9dfe2 --- /dev/null +++ b/src/com/luoamin/net/socket/Server.java @@ -0,0 +1,42 @@ +package com.luoamin.net.socket; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.ServerSocket; +import java.net.Socket; + +public class Server { + + public static void main(String[] args) { + ServerSocket ss=null; + Socket socket=null; + + InputStream in=null; + OutputStream out=null; + try { + ss=new ServerSocket(8888); + socket=ss.accept(); + byte[]b=new byte[1024]; + int len=0; + in=socket.getInputStream(); + while((len=in.read(b))!=-1){ + System.out.println("服务器收到客户端"+socket.getInetAddress().getHostAddress()+"的信息"+new String(b,0,len)); + } + + out=socket.getOutputStream(); + out.write("客户端你好,我已经收到你的信息".getBytes()); + } catch (IOException e) { + e.printStackTrace(); + }finally{ + try { + socket.close(); + ss.close(); + } catch (IOException e) { + e.printStackTrace(); + } + + } + } + +} diff --git a/src/com/luoamin/net/socket/SocketThread.java b/src/com/luoamin/net/socket/SocketThread.java new file mode 100644 index 0000000..eb0c7c1 --- /dev/null +++ b/src/com/luoamin/net/socket/SocketThread.java @@ -0,0 +1,46 @@ +package com.luoamin.net.socket; + +import java.io.BufferedWriter; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; +import java.net.Socket; +import java.util.Calendar; + +public class SocketThread extends Thread{ + public Socket socket; + + public SocketThread(Socket socket) { + this.socket = socket; + } + + public void run() { + PrintWriter pw = null; + Calendar c; + + try { + pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()))); + while(true)//服务器每隔3秒向客户端发送当前时间信息 + { + Thread.sleep(3000); + c = Calendar.getInstance(); //获取当前时间 + pw.println("Server Time:"+c.getTime().toString()); + pw.flush(); + } + + } catch (Exception ex) { + System.out.println(ex.getMessage()); + } finally { + try { + if (pw != null) { + pw.close(); + } + if (socket != null) { + socket.close(); + } + } catch (Exception ex) { + System.out.println(ex.getMessage()); + } + } + } + +} diff --git a/src/com/luoamin/observer/Client.java b/src/com/luoamin/observer/Client.java new file mode 100644 index 0000000..61a7938 --- /dev/null +++ b/src/com/luoamin/observer/Client.java @@ -0,0 +1,13 @@ +package com.luoamin.observer; +/*jdk有现成的观察者被观察者接口*/ +import java.util.Observable; + +public class Client { + public static void main(String[] args) { + Oberservable able=new Oberservable(); + able.addObservers(new Observer1()); + able.addObservers(new Observer2()); + able.changed(); + } + +} diff --git a/src/com/luoamin/observer/Oberservable.java b/src/com/luoamin/observer/Oberservable.java new file mode 100644 index 0000000..c66330d --- /dev/null +++ b/src/com/luoamin/observer/Oberservable.java @@ -0,0 +1,26 @@ +package com.luoamin.observer; +/** + * 具体的被观察者,他有两个方法,一个是change方法(用于自身改变),然后通知观察者 + * 一个是addObservers,用来供客户端访问 + */ +import java.util.ArrayList; +import java.util.List; + +public class Oberservable { + + Listlist=new ArrayList(); + public void addObservers(Observer o){ + list.add(o); + } + + public void changed(){ + System.out.println("我是被观察者,我发生变化了"); + notifyObserver(); + } + + public void notifyObserver(){ + for (Observer observer : list) { + observer.update(this); + } + } +} diff --git a/src/com/luoamin/observer/Observer.java b/src/com/luoamin/observer/Observer.java new file mode 100644 index 0000000..5c53f68 --- /dev/null +++ b/src/com/luoamin/observer/Observer.java @@ -0,0 +1,9 @@ +package com.luoamin.observer; +/** + * 观察者接口 + * @author john + * + */ +public interface Observer { + void update(Oberservable o); +} diff --git a/src/com/luoamin/observer/Observer1.java b/src/com/luoamin/observer/Observer1.java new file mode 100644 index 0000000..a8f8924 --- /dev/null +++ b/src/com/luoamin/observer/Observer1.java @@ -0,0 +1,14 @@ +package com.luoamin.observer; +/** + * 具体的观察者 + * @author john + * + */ +public class Observer1 implements Observer{ + + @Override + public void update(Oberservable o) { + System.out.println("我是Observer1,我观察到了"+o.getClass().getSimpleName()+"发生了变化"); + } + +} diff --git a/src/com/luoamin/observer/Observer2.java b/src/com/luoamin/observer/Observer2.java new file mode 100644 index 0000000..3cbbdfa --- /dev/null +++ b/src/com/luoamin/observer/Observer2.java @@ -0,0 +1,14 @@ +package com.luoamin.observer; +/** + * 具体的观察者 + * @author john + * + */ +public class Observer2 implements Observer{ + + @Override + public void update(Oberservable o) { + System.out.println("我是Observer2,我观察到了"+o.getClass().getName()+"发生了变化"); + } + +} diff --git a/src/com/luoamin/observer/test1/JdkObserverSupportParse.java b/src/com/luoamin/observer/test1/JdkObserverSupportParse.java new file mode 100644 index 0000000..4f0eca6 --- /dev/null +++ b/src/com/luoamin/observer/test1/JdkObserverSupportParse.java @@ -0,0 +1,106 @@ +package com.luoamin.observer.test1; +/** + * jdk支持观察者模式的代码,有观察者和被观察者。 + * @author john + * + */ +public class JdkObserverSupportParse { + /* + //观察者接口,每一个观察者都必须实现这个接口 + public interface Observer { + //这个方法是观察者在观察对象产生变化时所做的响应动作,从中传入了观察的对象和一个预留参数 + void update(Observable o, Object arg); + +} + + import java.util.Vector; + +//被观察者类 +public class Observable { + //这是一个改变标识,来标记该被观察者有没有改变 + private boolean changed = false; + //持有一个观察者列表 + private Vector obs; + + public Observable() { + obs = new Vector(); + } + //添加观察者,添加时会去重 + public synchronized void addObserver(Observer o) { + if (o == null) + throw new NullPointerException(); + if (!obs.contains(o)) { + obs.addElement(o); + } + } + //删除观察者 + public synchronized void deleteObserver(Observer o) { + obs.removeElement(o); + } + //notifyObservers(Object arg)的重载方法 + public void notifyObservers() { + notifyObservers(null); + } + //通知所有观察者,被观察者改变了,你可以执行你的update方法了。 + public void notifyObservers(Object arg) { + //一个临时的数组,用于并发访问被观察者时,留住观察者列表的当前状态,这种处理方式其实也算是一种设计模式,即备忘录模式。 + Object[] arrLocal; + //注意这个同步块,它表示在获取观察者列表时,该对象是被锁定的 + //也就是说,在我获取到观察者列表之前,不允许其他线程改变观察者列表 + synchronized (this) { + //如果没变化直接返回 + if (!changed) + return; + //这里将当前的观察者列表放入临时数组 + arrLocal = obs.toArray(); + //将改变标识重新置回未改变 + clearChanged(); + } + //注意这个for循环没有在同步块,此时已经释放了被观察者的锁,其他线程可以改变观察者列表 + //但是这并不影响我们当前进行的操作,因为我们已经将观察者列表复制到临时数组 + //在通知时我们只通知数组中的观察者,当前删除和添加观察者,都不会影响我们通知的对象 + for (int i = arrLocal.length-1; i>=0; i--) + ((Observer)arrLocal[i]).update(this, arg); + } + + //删除所有观察者 + public synchronized void deleteObservers() { + obs.removeAllElements(); + } + + //标识被观察者被改变过了 + protected synchronized void setChanged() { + changed = true; + } + //标识被观察者没改变 + protected synchronized void clearChanged() { + changed = false; + } + //返回被观察者是否改变 + public synchronized boolean hasChanged() { + return changed; + } + //返回观察者数量 + public synchronized int countObservers() { + return obs.size(); + } +} + + + 当然,这样做还有问题,就是jdk没有做好观察者的update方法的异常处理问题,比如: + for (int i = arrLocal.length-1; i>=0; i--) + ((Observer)arrLocal[i]).update(this, arg); + 如果一个update方法执行抛出异常,就会导致其他观察者无法被通知,所以保险的处理方式就是在for循环里面 + 加上try catch块对他进行异常处理,即使一个update方法抛出异常,也不会影响其他观察者被通知,就如: + for (int i = arrLocal.length-1; i>=0; i--){ + try { + ((Observer)arrLocal[i]).update(this, arg); + } catch (Throwable e) {e.printStackTrace();} + } + + + + + * */ + +} diff --git a/src/com/luoamin/oop/Benchi.java b/src/com/luoamin/oop/Benchi.java new file mode 100644 index 0000000..039f145 --- /dev/null +++ b/src/com/luoamin/oop/Benchi.java @@ -0,0 +1,26 @@ +package com.luoamin.oop; +/** + * super("父亲的轿车")方法表示调用父类的构造方法,其实也可以不用写,因为 + * 不写会默认调用继承关系的super()方法,如果写了,可以调用父类不同的构造方法 + * 以便进行一些变量的初始化 + * @author john + * + */ +public class Benchi extends Car{ + + public Benchi(){ + super("父亲的轿车"); + System.out.println("方法调用完毕!"); + } + public void getBenchi(){ + System.out.println("这是一辆奔驰轿车!"); + super.getCar(); + } + + public static void main(String[] args) { + Benchi ben=new Benchi(); + ben.getCar(); + + ben.getBenchi(); + } +} diff --git a/src/com/luoamin/oop/Car.java b/src/com/luoamin/oop/Car.java new file mode 100644 index 0000000..7d34328 --- /dev/null +++ b/src/com/luoamin/oop/Car.java @@ -0,0 +1,14 @@ +package com.luoamin.oop; + +public class Car { + private String carName; + public Car(){} + public Car(String carName){ + this.carName=carName; + System.out.println(carName); + } + public void getCar(){ + System.out.println("这是父类car!"); + } + +} diff --git a/src/com/luoamin/properties/ReadPropertiesFile.java b/src/com/luoamin/properties/ReadPropertiesFile.java new file mode 100644 index 0000000..686ca58 --- /dev/null +++ b/src/com/luoamin/properties/ReadPropertiesFile.java @@ -0,0 +1,86 @@ +package com.luoamin.properties; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.util.Enumeration; +import java.util.Properties; + +public class ReadPropertiesFile { + + /** + * 读取配置文件的数据,getResourceAsStream其实就是输入流luoamin.propertiess + * 但是文件路径里面的/表示classpath路径,即程序编译后的bin目录,如果没有/,那么就是代表和源 + * 文件(当前java类)是统一路径,注意getResourceAsStream方法不能完全按照简单输入流来用, + * 因为这个输入流是用来解析工程里面的资源文件的,ServletContext. getResourceAsStream(String path): + * 默认从WebAPP根目录下取资源 + + */ + public static void loadFile(){ + Properties pro=new Properties(); + try { +// pro.load(new FileInputStream("D:/luoamin/luoamin.ini")); + pro.load(ReadPropertiesFile.class.getResourceAsStream("luoamin.properties")); + Enumeration enu=pro.propertyNames(); + System.out.println(pro); + while(enu.hasMoreElements()){ + String key=(String)enu.nextElement(); + String value=pro.getProperty(key); + System.out.println(key+"+++++++++++"+value); + } + } catch (IOException e) { + e.printStackTrace(); + } + + } + + + /** + * 获取jvm的系统属性 + * @param args + */ + public static void getProperties(){ + Properties pro=System.getProperties(); + pro.list(System.out); + } + + /** + * 往配置文件写入数据 + * @param args + */ + public static void writeData(String key,String value){ + Properties pro=new Properties(); +// InputStream in=null; + OutputStream out=null; + try { +// in=new FileInputStream("D:/luoamin/luoamin.ini"); + out=new FileOutputStream("D:/luoamin/luoamin1.ini"); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + + pro.setProperty("one-two", "buckle my shoe"); + pro.setProperty("three-four", "shut the door"); + try { + pro.store(out, key); + } catch (IOException e) { + e.printStackTrace(); + } + // 返回属性列表中所有键的枚举 + Enumeration enu =pro.propertyNames(); + while(enu.hasMoreElements()){ + String key1=(String)enu.nextElement(); + String value1=pro.getProperty(key1); + System.out.println(key1+"============="+value1); + } + } + + public static void main(String[] args) { + loadFile(); + } + +} diff --git a/src/com/luoamin/properties/luoamin.properties b/src/com/luoamin/properties/luoamin.properties new file mode 100644 index 0000000..33654cf --- /dev/null +++ b/src/com/luoamin/properties/luoamin.properties @@ -0,0 +1,3 @@ +name=luoamin +age=26 +hobby=swing,sing \ No newline at end of file diff --git a/src/com/luoamin/proxy/Moveable.java b/src/com/luoamin/proxy/Moveable.java new file mode 100644 index 0000000..1c4e904 --- /dev/null +++ b/src/com/luoamin/proxy/Moveable.java @@ -0,0 +1,8 @@ +package com.luoamin.proxy; + +public interface Moveable { + //代理模式可以用来记录一些日志,时间等一些和业务分离的事情 + public void move(); + public void go(); + +} diff --git a/src/com/luoamin/proxy/Test.java b/src/com/luoamin/proxy/Test.java new file mode 100644 index 0000000..f21193c --- /dev/null +++ b/src/com/luoamin/proxy/Test.java @@ -0,0 +1,15 @@ +package com.luoamin.proxy; + +public class Test { + + public static void main(String[] args) { + Tunk t=new Tunk(); + TunkProxyTime ttt=new TunkProxyTime(t); + //ttt.move();此种方法能实现tunk对时间的代理 + + + TunkLogProxy log=new TunkLogProxy(ttt); + log.move();//这种方式就会先记录日志,后记录时间 + } + +} diff --git a/src/com/luoamin/proxy/Tunk.java b/src/com/luoamin/proxy/Tunk.java new file mode 100644 index 0000000..bf0c9e5 --- /dev/null +++ b/src/com/luoamin/proxy/Tunk.java @@ -0,0 +1,25 @@ +package com.luoamin.proxy; + +import java.util.Random; + +public class Tunk implements Moveable{ + + @Override + public void move() { + System.out.println("坦克移动中"); + /**生成随机数有两种方法,1是使用Math类的random方法 + * ,另外一种是使用Random类Random.nextInt(100),0-100之间的随机数 + * */ + try { + Thread.sleep(new Random().nextInt(10000)); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + @Override + public void go() { + System.out.println("去哪里,坦克"); + } + +} diff --git a/src/com/luoamin/proxy/TunkLogProxy.java b/src/com/luoamin/proxy/TunkLogProxy.java new file mode 100644 index 0000000..117960f --- /dev/null +++ b/src/com/luoamin/proxy/TunkLogProxy.java @@ -0,0 +1,19 @@ +package com.luoamin.proxy; + +public class TunkLogProxy implements Moveable { + private Moveable mo; + public TunkLogProxy(Moveable m){ + this.mo=m; + }; + @Override + public void move() { + System.out.println("日志开始"); + mo.move(); + System.out.println("日志结束"); + } + @Override + public void go() { + + } + +} diff --git a/src/com/luoamin/proxy/TunkProxyTime.java b/src/com/luoamin/proxy/TunkProxyTime.java new file mode 100644 index 0000000..818877b --- /dev/null +++ b/src/com/luoamin/proxy/TunkProxyTime.java @@ -0,0 +1,22 @@ +package com.luoamin.proxy; + +public class TunkProxyTime implements Moveable{ + private Moveable mo;//聚合的方式 + public TunkProxyTime(Moveable m){ + this.mo=m;//将代理对象指向要代理的对象Moveable m=new Tunk(); + //相当于在初始化代理对象的时候传一个实体对象,可以调用实体对象的方法 + } + @Override + public void move() { + long start=System.currentTimeMillis(); + mo.move(); + long end= System.currentTimeMillis(); + System.out.println("坦克行驶时间为"+(end-start)); + } + @Override + public void go() { + // TODO Auto-generated method stub + + } + +} diff --git a/src/com/luoamin/proxy/dynamicproxy/DynmicProxy.java b/src/com/luoamin/proxy/dynamicproxy/DynmicProxy.java new file mode 100644 index 0000000..5592708 --- /dev/null +++ b/src/com/luoamin/proxy/dynamicproxy/DynmicProxy.java @@ -0,0 +1,25 @@ +package com.luoamin.proxy.dynamicproxy; + +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; + +public class DynmicProxy implements InvocationHandler{ + /*target,被代理对象,表示要对那种对象进行代理*/ + private Object target; + public DynmicProxy(Object target1){ + this.target=target1; + } + //这样就实现了不同对象的代理内容,只需要在动态代理类添加业务逻辑,就可以实现想要的代理功能 + public Object invoke(Object proxy, Method method, Object[] args) + throws Throwable { + System.out.println("日志开始"); + long start =System.currentTimeMillis(); + System.out.println(proxy.getClass()+"++++++"+method.getName()+"+++++"+args); + Object obj=method.invoke(target, args); + long end=System.currentTimeMillis(); + System.out.println("坦克行驶时间为"+(end-start)); + System.out.println("日志结束"); + return obj; + } + +} diff --git a/src/com/luoamin/proxy/dynamicproxy/Test.java b/src/com/luoamin/proxy/dynamicproxy/Test.java new file mode 100644 index 0000000..066ed70 --- /dev/null +++ b/src/com/luoamin/proxy/dynamicproxy/Test.java @@ -0,0 +1,18 @@ +package com.luoamin.proxy.dynamicproxy; + +import java.lang.reflect.Proxy; +import com.luoamin.proxy.Moveable; +import com.luoamin.proxy.Tunk; + +public class Test { + + public static void main(String[] args) { + //这样就实现了不同对象的代理内容。 + Tunk tunk=new Tunk(); + DynmicProxy dy=new DynmicProxy(tunk); + Moveable mo=(Moveable)Proxy.newProxyInstance(tunk.getClass().getClassLoader(), new Class[]{Moveable.class}, dy); + mo.move();//最后调用接口的方法 + } + + +} diff --git a/src/com/luoamin/proxy/dynamicproxy/Test1.java b/src/com/luoamin/proxy/dynamicproxy/Test1.java new file mode 100644 index 0000000..037133e --- /dev/null +++ b/src/com/luoamin/proxy/dynamicproxy/Test1.java @@ -0,0 +1,18 @@ +package com.luoamin.proxy.dynamicproxy; + +import com.luoamin.proxy.Moveable; + +public class Test1 { + + public static void main(String[] args) { + Class load=Moveable.class; + Integer a=0; + int []aaa=new int[10]; + aaa.clone(); + + Class load1=aaa.getClass(); + System.out.println(load); + System.out.println(load1); + } + +} diff --git a/src/com/luoamin/proxy/dynamicproxy/test/DynmicProxy.java b/src/com/luoamin/proxy/dynamicproxy/test/DynmicProxy.java new file mode 100644 index 0000000..20354e1 --- /dev/null +++ b/src/com/luoamin/proxy/dynamicproxy/test/DynmicProxy.java @@ -0,0 +1,22 @@ +package com.luoamin.proxy.dynamicproxy.test; + +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; + +public class DynmicProxy implements InvocationHandler{ + private Object obj; + public DynmicProxy(Object obj){ + this.obj=obj; + } + @Override + public Object invoke(Object proxy, Method method, Object[] args) + throws Throwable { + System.out.println("日志开始。。。"); + System.out.println("计时开始。。。"); + Object ee=method.invoke(obj, args); + System.out.println("计时结束"); + System.out.println("日志结束。。。"); + return ee; + } + +} diff --git a/src/com/luoamin/proxy/dynamicproxy/test/Test.java b/src/com/luoamin/proxy/dynamicproxy/test/Test.java new file mode 100644 index 0000000..e4125ca --- /dev/null +++ b/src/com/luoamin/proxy/dynamicproxy/test/Test.java @@ -0,0 +1,16 @@ +package com.luoamin.proxy.dynamicproxy.test; + +import java.lang.reflect.Proxy; + +import com.luoamin.proxy.Moveable; +import com.luoamin.proxy.Tunk; + +public class Test { + public static void main(String[] args) { + Tunk t=new Tunk(); + DynmicProxy dy=new DynmicProxy(t); + Moveable mo=(Moveable)Proxy.newProxyInstance(t.getClass().getClassLoader(), new Class[]{Moveable.class}, dy); + mo.move(); + } + +} diff --git a/src/com/luoamin/proxy/test/Car.java b/src/com/luoamin/proxy/test/Car.java new file mode 100644 index 0000000..52dc566 --- /dev/null +++ b/src/com/luoamin/proxy/test/Car.java @@ -0,0 +1,15 @@ +package com.luoamin.proxy.test; + +public class Car implements Moveable{ + + @Override + public void move() { + System.out.println("汽车行驶中。。。"); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + +} diff --git a/src/com/luoamin/proxy/test/DynamicProxy.java b/src/com/luoamin/proxy/test/DynamicProxy.java new file mode 100644 index 0000000..f87eedf --- /dev/null +++ b/src/com/luoamin/proxy/test/DynamicProxy.java @@ -0,0 +1,20 @@ +package com.luoamin.proxy.test; + +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; + +public class DynamicProxy implements InvocationHandler{ + private Object target; + public DynamicProxy(Object target){ + this.target=target; + } + public Object invoke(Object proxy, Method method, Object[] args) + throws Throwable { + System.out.println("日志开始"); + System.out.println(proxy.getClass().getName()); + Object jjj= method.invoke(target, args); + System.out.println("日志结束"); + return jjj; + } + +} diff --git a/src/com/luoamin/proxy/test/LogProy.java b/src/com/luoamin/proxy/test/LogProy.java new file mode 100644 index 0000000..298b733 --- /dev/null +++ b/src/com/luoamin/proxy/test/LogProy.java @@ -0,0 +1,15 @@ +package com.luoamin.proxy.test; + +public class LogProy implements Moveable{ + + private Moveable move; + public LogProy(Moveable move){ + this.move=move; + } + public void move() { + System.out.println("日志开始"); + move.move(); + System.out.println("日志结束"); + } + +} diff --git a/src/com/luoamin/proxy/test/Moveable.java b/src/com/luoamin/proxy/test/Moveable.java new file mode 100644 index 0000000..571b8c7 --- /dev/null +++ b/src/com/luoamin/proxy/test/Moveable.java @@ -0,0 +1,5 @@ +package com.luoamin.proxy.test; + +public interface Moveable { + void move(); +} diff --git a/src/com/luoamin/proxy/test/Test1.java b/src/com/luoamin/proxy/test/Test1.java new file mode 100644 index 0000000..b163469 --- /dev/null +++ b/src/com/luoamin/proxy/test/Test1.java @@ -0,0 +1,15 @@ +package com.luoamin.proxy.test; + + +public class Test1 { + public static void main(String[] args) { + /*先时间后日志,如果还要加上一个代理,那么久在添加一个代理类,一直通过implements Moable + * 接口来进行业务的先后代理 + * */ + Car car=new Car(); + LogProy log=new LogProy(car); + TimeProy proxy1=new TimeProy(log); + + proxy1.move(); + } +} diff --git a/src/com/luoamin/proxy/test/TestDymicProy.java b/src/com/luoamin/proxy/test/TestDymicProy.java new file mode 100644 index 0000000..05fc330 --- /dev/null +++ b/src/com/luoamin/proxy/test/TestDymicProy.java @@ -0,0 +1,14 @@ +package com.luoamin.proxy.test; + +import java.lang.reflect.Proxy; + +public class TestDymicProy { + + public static void main(String[] args) { + Car car=new Car(); + DynamicProxy dy=new DynamicProxy(car); + Moveable xd=(Moveable)Proxy.newProxyInstance(Car.class.getClassLoader(), new Class[]{Moveable.class}, dy); + xd.move(); + } + +} diff --git a/src/com/luoamin/proxy/test/TimeProy.java b/src/com/luoamin/proxy/test/TimeProy.java new file mode 100644 index 0000000..5e24e42 --- /dev/null +++ b/src/com/luoamin/proxy/test/TimeProy.java @@ -0,0 +1,18 @@ +package com.luoamin.proxy.test; + +public class TimeProy implements Moveable{ + + private Moveable move; + public TimeProy(Moveable move){ + this.move=move; + } + + public void move(){ + System.out.println("汽车开始行驶。。。"); + long starttime=System.currentTimeMillis(); + move.move(); + long endtime=System.currentTimeMillis(); + System.out.println("汽车行驶结束。。。"); + System.out.println("汽车行驶"+(endtime-starttime)); + } +} diff --git a/src/com/luoamin/proxy/test/Tunk.java b/src/com/luoamin/proxy/test/Tunk.java new file mode 100644 index 0000000..939b141 --- /dev/null +++ b/src/com/luoamin/proxy/test/Tunk.java @@ -0,0 +1,5 @@ +package com.luoamin.proxy.test; + +public class Tunk { + +} diff --git a/src/com/luoamin/proxy/test1/Gaotie.java b/src/com/luoamin/proxy/test1/Gaotie.java new file mode 100644 index 0000000..dde6d87 --- /dev/null +++ b/src/com/luoamin/proxy/test1/Gaotie.java @@ -0,0 +1,10 @@ +package com.luoamin.proxy.test1; + +public class Gaotie implements Go{ + + @Override + public void go() { + System.out.println("高铁行驶中。。。"); + } + +} diff --git a/src/com/luoamin/proxy/test1/Go.java b/src/com/luoamin/proxy/test1/Go.java new file mode 100644 index 0000000..9a45161 --- /dev/null +++ b/src/com/luoamin/proxy/test1/Go.java @@ -0,0 +1,6 @@ +package com.luoamin.proxy.test1; + +public interface Go { + + void go(); +} diff --git a/src/com/luoamin/proxy/test1/LogGo.java b/src/com/luoamin/proxy/test1/LogGo.java new file mode 100644 index 0000000..283fa5a --- /dev/null +++ b/src/com/luoamin/proxy/test1/LogGo.java @@ -0,0 +1,15 @@ +package com.luoamin.proxy.test1; + +public class LogGo implements Go{ + + private Go go; + public LogGo(Go go){ + this.go=go; + } + public void go() { + System.out.println("日志开始。。。"); + go.go(); + System.out.println("日志结束。。。"); + } + +} diff --git a/src/com/luoamin/proxy/test1/TestStaticProxy.java b/src/com/luoamin/proxy/test1/TestStaticProxy.java new file mode 100644 index 0000000..2a2b693 --- /dev/null +++ b/src/com/luoamin/proxy/test1/TestStaticProxy.java @@ -0,0 +1,13 @@ +package com.luoamin.proxy.test1; + +public class TestStaticProxy { + + public static void main(String[] args) { + //先对日志代理在进行对时间的代理,就后使用 + Gaotie gao=new Gaotie(); + TimeGaoTie time=new TimeGaoTie(gao); + LogGo log=new LogGo(time); + log.go(); + } + +} diff --git a/src/com/luoamin/proxy/test1/TimeGaoTie.java b/src/com/luoamin/proxy/test1/TimeGaoTie.java new file mode 100644 index 0000000..18da2b5 --- /dev/null +++ b/src/com/luoamin/proxy/test1/TimeGaoTie.java @@ -0,0 +1,15 @@ +package com.luoamin.proxy.test1; + +public class TimeGaoTie implements Go{ + private Go go; + public TimeGaoTie(Go go){ + this.go=go; + } + @Override + public void go() { + System.out.println("计时开始。。。"); + go.go(); + System.out.println("及时结束。。。"); + } + +} diff --git a/src/com/luoamin/reflect/Person.java b/src/com/luoamin/reflect/Person.java new file mode 100644 index 0000000..b9b7650 --- /dev/null +++ b/src/com/luoamin/reflect/Person.java @@ -0,0 +1,113 @@ +package com.luoamin.reflect; + +import java.io.InputStreamReader; +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.Properties; + +public class Person { + private String name; + private Integer age; + public Person(){} + private Person(String name,Integer age){ + this.name=name; + this.age=age; + } + + public void fff(String name){ + System.out.println(name+"你好帅!"); + } + + public static void main(String[] args) throws Exception { + /**实例化Class类对象的四种方法*/ + Teacher te=new Teacher(); + Class cc=Teacher.class; + System.out.println(cc);//class com.luoamin.reflect.Teacher + + Class c2=Class.forName("com.luoamin.reflect.Teacher"); + System.out.println(c2); + + Class c3="com.luoamin.reflect.Teacher".getClass();//class java.lang.String + System.out.println(c3); + + Class c4=te.getClass(); + System.out.println(c4); + ClassLoader load=te.getClass().getClassLoader();//getClassLoader是Class对象的方法 + Class c5=load.loadClass("com.luoamin.reflect.Teacher"); + System.out.println(c5); + + + //获取Class对象反射的对象实例,即Teacher对象,这种情况新建的对象有两个条件 + //1.加载的类必须有无参构造方法;2,构造方法有一定的访问权限 + Object obj=cc.newInstance(); + System.out.println(obj);//techer对象 + + + /** + * 另外的class反射对象实例化方法,同样可以实例化Teacher对象 + * getConstructor里面是一个class类型的数组,如果不写泛型 + * 也可以,newInstance方法就得墙纸转换成Teacher类型 + * + * 调用getMethod方法,和getConstructor方法为Class类主要方法 + */ + Constructortea= cc.getConstructor(String.class,Integer.class); + Field ff=cc.getField("name1"); + System.out.println(cc.getName()); + System.out.println(cc.getSuperclass());//返回Class类型的父类,即object类 + Class[] cal= String.class.getInterfaces();//getInterfaces返回String类实现的接口 + for (Class class1 : cal) { + System.out.println(class1); + } + System.out.println(ff); + Teacher tt=tea.newInstance("laoluo",20); + System.out.println(tt); + tt.fly("laile"); + + + + Properties p=new Properties(); + //文件路径里面的/表示classpath路径,即程序编译后的bin目录,如果没有/,那么就是代表和源文件是统一路径 + p.load(new InputStreamReader(Person.class.getResourceAsStream("Amin.properties"), "utf-8")); + System.out.println(p.getProperty("luoamin")); + + //获取反射类的构造函数 + Constructor con=Teacher.class.getDeclaredConstructor(new Class[]{String.class}); + System.out.println(con.getName()+"++++++++"); + con.setAccessible(true); + //newInstance返回的是object类型对象,其实根据反射也就是Teacher对象,即通过反射创建一个对象,参数也可以写成//“airen” + Teacher teacher=(Teacher)con.newInstance(new Object[]{"airen"}); + System.out.println(teacher.name1); + + + + + + Method me=Teacher.class.getDeclaredMethod("fly", new Class[]{String.class}); + //Declared通过这个方法并且这只这个属性为true就可以访问任何权限的方法 + me.setAccessible(true); + //getName获取方法名字,getModifiers获取方法的访问权限的int值 + System.out.println(me.getName()+"++++++"+me.getModifiers()); + //直接调用反射获取过来的方法 + Object vv=me.invoke(new Teacher(), new Object[]{"amin"}); + System.out.println(vv);//输出method里面的内容,包括返回值 + } + +} +class Teacher{ + public String name1; + private Integer age; + public Teacher(){}; + public Teacher(String name){ + this.name1=name; + } + public Teacher(String name,Integer age){ + this.name1=name; + this.age=age; + } + public String fly(String name){ + System.out.println("我要飞得更高"+name); + return "火上房"; + } + +} \ No newline at end of file diff --git a/src/com/luoamin/reflect/TestReflect.java b/src/com/luoamin/reflect/TestReflect.java new file mode 100644 index 0000000..5e5529e --- /dev/null +++ b/src/com/luoamin/reflect/TestReflect.java @@ -0,0 +1,10 @@ +package com.luoamin.reflect; + +public class TestReflect { + + public static void main(String[] args) { + Teacher te=new Teacher(); + + } + +} diff --git a/src/com/luoamin/reflect/test/TestPerson.java b/src/com/luoamin/reflect/test/TestPerson.java new file mode 100644 index 0000000..2fb450f --- /dev/null +++ b/src/com/luoamin/reflect/test/TestPerson.java @@ -0,0 +1,39 @@ +package com.luoamin.reflect.test; + +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.UnsupportedEncodingException; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.Properties; + +import com.luoamin.reflect.Person; + +public class TestPerson { + + public static void main(String[] args) throws NoSuchMethodException, SecurityException, UnsupportedEncodingException, IOException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { + + Class cla=Person.class; + Class[] aa=String.class.getClasses(); + for(Class list:aa){ + System.out.println(list); + } + + cla.newInstance(); + Constructor person=cla.getDeclaredConstructor(new Class[]{String.class,Integer.class}); + System.out.println(person); + person.setAccessible(true); + System.out.println(cla); + Object oo=person.newInstance(new Object[]{"amin",20}); + + + Method me=cla.getDeclaredMethod("fff", new Class[]{String.class}); + me.invoke(new Person(), new Object[]{"amin"}); + + + + } + +} diff --git a/src/com/luoamin/runable/GetFile.java b/src/com/luoamin/runable/GetFile.java new file mode 100644 index 0000000..cb3530f --- /dev/null +++ b/src/com/luoamin/runable/GetFile.java @@ -0,0 +1,26 @@ +package com.luoamin.runable; + +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStreamReader; + +public class GetFile { + + public static void fileDirectory(String directory) { + File file=new File(directory); + File[] list=file.listFiles(); + for(int i=0;ia[j+1]){//只要前面的数据比后面的数据大,就掉换两者的位置 + temp=a[j]; + a[j]=a[j+1]; + a[j+1]=temp; + } + } + } + } + +} diff --git a/src/com/luoamin/sql/TestSql.java b/src/com/luoamin/sql/TestSql.java new file mode 100644 index 0000000..6646f80 --- /dev/null +++ b/src/com/luoamin/sql/TestSql.java @@ -0,0 +1,73 @@ +package com.luoamin.sql; + +public class TestSql { + + + public static void main(String[] args) { + /* + * + * delete from test where id in + * (select id from test group by id having count(id)>1)and + * + * rowid not in + * (select min(rowid) from test group by id having count(id)>1 + * ) + * + * + * + * delete from test where id in (select id from test group by id having count(id)>1) + *and rowid not in (select min(rowid) from test group by id having count(id)>1) ; + * + * s + * create table test2 as select distinct * from test; + * drop table test; + * create table test as select * from test2; + * + * update test set (id,name,account ) = (select id,name,account from test1 where id =1)where id=1 + * + * insert into (id,name,account) select id,name,account from test1 + * + * insert into + * Insert into test select * from test2; + * + * insert into test select * from test2; + * + * insert into test (name,sex,account) select name,sex,account from test1; + * + * insert into test (name,sex,account) select name,sex,account from test1; + * + * + * update test set (name,sex,account)=(select name,sex,account from test1 where id=1) + * + * + * + * + * create sequence test_seq increment by 1 start with 10 maxvalue 999999 nocycle nocache; + * + * + * + * + * create sequence test_seq increment by 1 start with 10 maxvalue 999999 nocycle nocache; + * + * + * create table ttt( + * id number(10,0), + * name varchar2(30) not null , + * sex char(1) + * custId number(10,0), + * constrint + * ); + * + * + * + * + * + * + * + * + * + * + * */ + } + +} diff --git a/src/com/luoamin/test/Dfff.java b/src/com/luoamin/test/Dfff.java new file mode 100644 index 0000000..edb48bf --- /dev/null +++ b/src/com/luoamin/test/Dfff.java @@ -0,0 +1,16 @@ +package com.luoamin.test; + +class A +{ int x,y; + static float f(int a){return 0;} + float g(int x,int y){return 0;} +} +class B +{ public static void main(String args[]) + { A a1=new A(); + A.f(2); //合法。 + a1.f(2); //合法。 + a1.g(2,5); //合法。 + A.g(3,2); //非法。 + } +} \ No newline at end of file diff --git a/src/com/luoamin/test/Fkkk.java b/src/com/luoamin/test/Fkkk.java new file mode 100644 index 0000000..b1173e8 --- /dev/null +++ b/src/com/luoamin/test/Fkkk.java @@ -0,0 +1,21 @@ +package com.luoamin.test; + +public abstract class Fkkk { + + private String jj; + + public String getJj() { + return jj; + } + public void setJj(String jj) { + this.jj = jj; + } + public int gg(){ + System.out.println("++++++++++++++"); + float a=1.0f; + return 1; + } + public void fff(){} + public abstract Integer ggg(); + +} diff --git a/src/com/luoamin/test/HelloWord.java b/src/com/luoamin/test/HelloWord.java new file mode 100644 index 0000000..ceb6123 --- /dev/null +++ b/src/com/luoamin/test/HelloWord.java @@ -0,0 +1,11 @@ +package com.luoamin.test; + +public class HelloWord{ + +public void ggg(String gg){ + + System.out.println(gg+"我是helloWord"); + +} + +} \ No newline at end of file diff --git a/src/com/luoamin/test/HellowordTest.java b/src/com/luoamin/test/HellowordTest.java new file mode 100644 index 0000000..717e42c --- /dev/null +++ b/src/com/luoamin/test/HellowordTest.java @@ -0,0 +1,21 @@ + + +package com.luoamin.test; +import org.junit.*; +public class HellowordTest{ + + @Test + public void hh(){ + + + HelloWord wff=new HelloWord(); + wff.ggg("我是一个ing"); + + +} + + + + + +} \ No newline at end of file diff --git a/src/com/luoamin/test/JavanTiger.java b/src/com/luoamin/test/JavanTiger.java new file mode 100644 index 0000000..43f8bc5 --- /dev/null +++ b/src/com/luoamin/test/JavanTiger.java @@ -0,0 +1,32 @@ +package com.luoamin.test; + public class JavanTiger { + int age; // 年龄 + int hight; // 身体高度 + + public JavanTiger() { + print(); + this.age=2; //这里初始化 age 的值 ,但递归返回的时候,这个值会被覆写 + } + + public JavanTiger(int age) { + this(); // 调用自己的第一个构造函数,下面的两个语句数不执行的 + this.age = age; + print(); + } + + public JavanTiger(int age, int hight) { + this(age); // 调用自己第二个构造函数 ,下面的两个语句数不执行的 + this.hight = hight; + print(); + } + + public void print() { //打印函数 + } + public static void main(String[] args) { + new JavanTiger(3,3); + } + } + //output + //I'am a 0岁 0尺高 tiger! + //I'am a 3岁 0尺高 tiger! + //I'am a 3岁 3尺高 tiger! \ No newline at end of file diff --git a/src/com/luoamin/test/Sub.java b/src/com/luoamin/test/Sub.java new file mode 100644 index 0000000..d332500 --- /dev/null +++ b/src/com/luoamin/test/Sub.java @@ -0,0 +1,14 @@ +package com.luoamin.test; +class Super { +public Integer getLenght() { return new Integer(4); } +} + +public class Sub extends Super { +public Long getLenght() { return new Long(5); } +public static void main(String[] args) { +Super sooper = new Super(); +Sub sub = new Sub(); +System.out.println(sooper.getLenght().toString() + "," + + sub.getLenght().toString() ); +} +} \ No newline at end of file diff --git a/src/com/luoamin/test/Tbbbb.java b/src/com/luoamin/test/Tbbbb.java new file mode 100644 index 0000000..260c9e7 --- /dev/null +++ b/src/com/luoamin/test/Tbbbb.java @@ -0,0 +1,26 @@ +package com.luoamin.test; + +public class Tbbbb extends Fkkk{ + + public Tbbbb(){ + super(); + System.out.println("------------"); + + } + @Override + public Integer ggg() { + System.out.println("********************"); + super.gg(); + return 1; + } + + public static int kkk(){ + System.out.println("))))))))))))))))))"); + return 1; + } + public static void main(String[] args) { + System.out.println(4&7); + System.out.println(new Tbbbb().kkk()); + + } +} diff --git a/src/com/luoamin/test/Test1.java b/src/com/luoamin/test/Test1.java new file mode 100644 index 0000000..d5499a0 --- /dev/null +++ b/src/com/luoamin/test/Test1.java @@ -0,0 +1,39 @@ +package com.luoamin.test; + +public class Test1 { + + /** + * mkdir,新增文件 + * rm -i + * + * vi,查看并修改 + * :set u,ch查看行号 + * wq! + * rm -rf + * :q! + * du -f + * >,覆盖内容,>>追加内容 + * + * + * ps -ef|grep httpd + * df -h,查看磁盘空间 + * pwd,查看当前所在目录 + * + * + * + * + * vlog + * + * + * + * + * + * */ + + + + + + + +} diff --git a/src/com/luoamin/test/TestBoolean.java b/src/com/luoamin/test/TestBoolean.java new file mode 100644 index 0000000..842fdf3 --- /dev/null +++ b/src/com/luoamin/test/TestBoolean.java @@ -0,0 +1,17 @@ +package com.luoamin.test; + +public class TestBoolean { + + public static void main(String[] args) { + Class cla=boolean.class; + Class cla1=Integer.TYPE; + System.out.println(boolean.class); + System.out.println(Integer.class); + System.out.println(cla); + System.out.println(cla1); + Class cla2=Person.class; + } + +} +class Person{} + diff --git a/src/com/luoamin/test/TestClass.java b/src/com/luoamin/test/TestClass.java new file mode 100644 index 0000000..62e063b --- /dev/null +++ b/src/com/luoamin/test/TestClass.java @@ -0,0 +1,34 @@ +package com.luoamin.test; + +public class TestClass { + + public String id; + public static int k; + public static void faxian(){ + TestClass.k=3; + //类方法只能访问类变量 + //id="ee"; + k=2; + mama(); + TestClass ccc=new TestClass(); + ccc.faleng(); + System.out.println("-----------------"); + + } + + public void faleng(){ + k=2; + id=""; + System.out.println(); + } + + public static void mama(){ + System.out.println("jjjjj"); + + } + + public void TestClass(){ + System.out.println("ooo"); + } + +} diff --git a/src/com/luoamin/test/TestClass2.java b/src/com/luoamin/test/TestClass2.java new file mode 100644 index 0000000..4bd4e63 --- /dev/null +++ b/src/com/luoamin/test/TestClass2.java @@ -0,0 +1,26 @@ +package com.luoamin.test; + +public class TestClass2 { + public int ff=3; + public static void main(String[] args) { + //类方法不能访问 + + TestClass ccc=new TestClass(); + ccc.faleng(); + TestClass.faxian(); + TestClass.mama(); + } + + + public void ggg(){ + TestClass.k=2; + ff=5; + TestClass ccc=new TestClass(); + ccc.faleng(); + TestClass.faxian(); + TestClass.mama(); + + } + + +} diff --git a/src/com/luoamin/test/TestEquals.java b/src/com/luoamin/test/TestEquals.java new file mode 100644 index 0000000..a01d7aa --- /dev/null +++ b/src/com/luoamin/test/TestEquals.java @@ -0,0 +1,28 @@ +package com.luoamin.test; + +public class TestEquals extends Tbbbb { + + public long ggg(){ + return new long(3); + } + + + public static void main(String[] args) { + Integer a=2; + + Integer b=new Integer(2); + float g=6; + if(a==b){ + + System.out.println("+++++++++++++++++"); + }else{ + System.out.println("--------------------"); + } + + + System.out.println(g); + + + } + +} diff --git a/src/com/luoamin/test/TestHashMap.java b/src/com/luoamin/test/TestHashMap.java new file mode 100644 index 0000000..e3e382e --- /dev/null +++ b/src/com/luoamin/test/TestHashMap.java @@ -0,0 +1,72 @@ +package com.luoamin.test; + +import java.io.File; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.util.HashMap; +import java.util.Hashtable; +import java.util.Map; +import java.util.Vector; + +public class TestHashMap { + + public static void main(String[] args) { +// Mapmap=new HashMap(); +// Mapmap1=new Hashtable(); +//// map.put("kaixin", null); +//// map1.put("haole", null); +//// System.out.println(map); +// +// +// Vectorlist=new Vector(); +// list.add("amin"); +// list.add("yufeng"); +// for (String string : list) { +// System.out.println(string.toString()); +// } + +// File file =new File("D:/luoamin/测试"); +// getFile(file); + + + + String data="aabcexmkduyruieiopxzkkkasdfjxjdsds"; + String []aaa=data.split(""); + for (int i = 1; i < aaa.length; i++) { + if(data.charAt(i)) + } + + + } + public static void getFile(File file){ + if(file.isDirectory()){ + System.out.println(file.getAbsolutePath()); + File[]files=file.listFiles(); + for(File file1:files){ + getFile(file1); + } + }else{ + System.out.println(file.getAbsolutePath()); + } + + } + + + public static Connection getCon(){ + Connection con=null; + try { + Class.forName("com.jdbc.oursql.Driver"); + con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","test","test"); + + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } catch (SQLException e) { + e.printStackTrace(); + } + return con; + } + + + +} diff --git a/src/com/luoamin/test/TestInterface.java b/src/com/luoamin/test/TestInterface.java new file mode 100644 index 0000000..e4af61b --- /dev/null +++ b/src/com/luoamin/test/TestInterface.java @@ -0,0 +1,10 @@ +package com.luoamin.test; + +import java.util.HashMap; +import java.util.List; + +public interface TestInterface { + + public int b=5; + public void fileFind(HashMap>map); +} diff --git a/src/com/luoamin/test/TestMap.java b/src/com/luoamin/test/TestMap.java new file mode 100644 index 0000000..ba81df3 --- /dev/null +++ b/src/com/luoamin/test/TestMap.java @@ -0,0 +1,22 @@ +package com.luoamin.test; + +import java.util.HashMap; +import java.util.Hashtable; +import java.util.Map; +import java.util.Map.Entry; + +public class TestMap { + + + + + public static void main(String[] args) { + String a="455555555555"; + String b="7777777777"; + + int gg=Integer.parseInt(""); + Integer hh=Integer.valueOf(b); + + + } +} diff --git a/src/com/luoamin/thread/DieSynchronized.java b/src/com/luoamin/thread/DieSynchronized.java new file mode 100644 index 0000000..650130c --- /dev/null +++ b/src/com/luoamin/thread/DieSynchronized.java @@ -0,0 +1,51 @@ +package com.luoamin.thread; + /*死锁*/ +public class DieSynchronized { + + public static void main(String[] args) { + Die dy=new Die(true); + Die dy1=new Die(false); + Thread t1=new Thread(dy); + Thread t2=new Thread(dy1); + t1.start(); + t2.start(); + } +} + +class Die implements Runnable{ + private boolean flag=false; + public Die(){ + } + public Die(boolean flag){ + this.flag=flag; + } + @Override + public void run() { + if(flag){ +/*if和else两个线程中,if里面占用a锁,还要占用b锁,else里面占用b锁,还要占用a锁,资源互相不释放,所以造成死锁 + * 另,如果一个锁被一个对象占用,就不能被另一个对象来占用 + * + * */ + synchronized (MyLock.locka) { + System.out.println("if locka"); + synchronized (MyLock.lockb) { + System.out.println("if lockb"); + } + } + }else{ + synchronized (MyLock.lockb) { + System.out.println("else lockb"); + synchronized (MyLock.locka) { + System.out.println("else locka"); + } + } + } + } + +} + +class MyLock{ + static Object locka=new Object(); + static Object lockb=new Object(); +} + diff --git a/src/com/luoamin/thread/MyThreadDemo.java b/src/com/luoamin/thread/MyThreadDemo.java new file mode 100644 index 0000000..63f2216 --- /dev/null +++ b/src/com/luoamin/thread/MyThreadDemo.java @@ -0,0 +1,42 @@ +package com.luoamin.thread; + + +public class MyThreadDemo { + /**线程不安全:多个线程在操作共享数据时,一个线程对资源还没执行完,另一个线程也操作这个资源 + 所以导致数据不一致的问题,解决该问题办法:对于多线程只能让一个线程操作数据,其他线程只能暂时 + * */ + + public static void main(String[] args) { + MyThread ff=new MyThread(); + //多个线程操作同一个资源,即操作同一段代码,多线程并发 + Thread a=new Thread(ff,"thread1"); + Thread b=new Thread(ff,"thread2"); + Thread c=new Thread(ff,"thread3"); + a.start(); + b.start(); + c.start(); + } +} + + +class MyThread extends Thread{ + private int ticket=100; + Object obj=new Object(); + public void run(){ + /*通过synchronized关键字,给资源加上一把锁,obj就是那把锁,随便一个什么对象都可以, + * 这样就不会出现线程不安全问题 + * */ + while(true){ + synchronized (obj) { + try { + Thread.sleep(10); + } catch (InterruptedException e) { + e.printStackTrace(); + } + if(ticket>0){ + System.out.println(Thread.currentThread().getName()+"线程买票"+ticket--); + } + } + } + } +} \ No newline at end of file diff --git a/src/com/luoamin/thread/ProducerAndConsumer.java b/src/com/luoamin/thread/ProducerAndConsumer.java new file mode 100644 index 0000000..f3182fa --- /dev/null +++ b/src/com/luoamin/thread/ProducerAndConsumer.java @@ -0,0 +1,80 @@ +package com.luoamin.thread; +/** + * 多线程的生产者消费者模式,标准 + * */ +public class ProducerAndConsumer { + + public static void main(String[] args) { + Resources re=new Resources(); + Producer pro=new Producer(re); + Consumer con=new Consumer(re); + Thread t1=new Thread(pro); + Thread t2=new Thread(pro); + Thread t3=new Thread(con); + Thread t4=new Thread(con); + t1.start(); + t2.start(); + t3.start(); + t4.start(); + } +} + +class Resources{ + String name; + boolean flag=false; + public synchronized void set(String name){ + while(true){ + if(this.flag){ + try { + wait();//因为调用该方法是resource锁对象,所以可以写成this.wait(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + }else{ + this.name=name; + System.out.println("生产者生产一条数据"+this.name); + this.flag=true; + notifyAll();//因为调用该方法是resource锁对象,所以可以写成this.wait(); + } + } + } + + public synchronized void cus(){ + while(true){ + if(!this.flag){ + try { + wait(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + }else{ + System.out.println("消费者消费一条数据"+this.name); + this.flag=false; + notifyAll(); + } + } + } +} + + +class Producer implements Runnable{ + //通过聚合的方式将资源注入到生产者对象中 + private Resources re; + public Producer(Resources re){ + this.re=re; + } + public void run(){ + re.set("我爱你"); + } +} + + +class Consumer implements Runnable{ + private Resources re; + public Consumer(Resources re){ + this.re=re; + } + public void run(){ + re.cus(); + } +} diff --git a/src/com/luoamin/thread/TestConCurrentHashMap.java b/src/com/luoamin/thread/TestConCurrentHashMap.java new file mode 100644 index 0000000..ece3d01 --- /dev/null +++ b/src/com/luoamin/thread/TestConCurrentHashMap.java @@ -0,0 +1,47 @@ +package com.luoamin.thread; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Map.Entry; +import java.util.concurrent.ConcurrentHashMap; + +public class TestConCurrentHashMap { + static Map conMap = new ConcurrentHashMap(); + public static void main(String[] args) { + + } + + public static void getCon(){ + /*多线程操作ConCurrentHashMap,即在里面定义多个线程循环操作,而hashmap就不可以;如果不用迭代器,就会 + * 包java.util.ConcurrentModificationException异常,hashmap只要边遍历边删除就会出现 + * + * */ + + for (long i = 0; i < 15; i++) { + conMap.put(i, i + ""); + } + Thread thread = new Thread(new Runnable() { + public void run(){ + conMap.put(100l, "100"); + } + }); + Thread thread2 = new Thread(new Runnable() { + public void run(){ + for(Iterator>iterator=conMap.entrySet().iterator();iterator.hasNext();){ + Entryentry=iterator.next(); + if(entry.getKey()>1){ + conMap.remove(entry.getKey()); + } + } + } + }); + for (Entry entry : conMap.entrySet()) { + long key = entry.getKey(); + if (key < 10) { + conMap.remove(key); + } + } + + } +} diff --git a/src/com/luoamin/thread/TestSington.java b/src/com/luoamin/thread/TestSington.java new file mode 100644 index 0000000..5a38960 --- /dev/null +++ b/src/com/luoamin/thread/TestSington.java @@ -0,0 +1,16 @@ +package com.luoamin.thread; + +public class TestSington { + + + public static void main(String[] args) { + ThreadSington t1=ThreadSington.getInstance(); + ThreadSington t2=ThreadSington.getInstance(); + if(t1==t2){ + System.out.println("t1和t2是同一个对象"); + }else{ + System.out.println("t1和t2不是同一个对象"); + } + } + +} diff --git a/src/com/luoamin/thread/Thread2.java b/src/com/luoamin/thread/Thread2.java new file mode 100644 index 0000000..96812a0 --- /dev/null +++ b/src/com/luoamin/thread/Thread2.java @@ -0,0 +1,62 @@ +package com.luoamin.thread; + +public class Thread2 { + /** + 同步,实现方法有同步代码块和同步函数,同步代码块共用的是自定义对象的锁,同步函数 + 共用的是this锁,只能写this,即当前调用同步函数对象的锁,如果同步函数的synchronized关键字前面加上static关键字 + 那么同步函数此时共用当前对象的Class对象的锁,因为静态方法在没有实例化对象前就已经加载到类里面去了, + 而此时也有对应的Class对象,所以共用当前对象的Class对象的锁 + * */ + public static void main(String[] args) { + MyHread tt=new MyHread(); + Thread a=new Thread(tt,"线程一"); + Thread b=new Thread(tt,"线程二"); + a.start(); + + try { + Thread.sleep(10); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + }//为了让线程一和线程二都能有执行的机会 + tt.flag=false; + b.start(); + } + +} + + +class MyHread implements Runnable{ + private static int ticket=100; + public boolean flag=true; + Object obj=new Object(); + public void run(){ + if(flag){ + while(true){ + synchronized (MyHread.class){ + if(ticket>0){ + try { + Thread.sleep(10);//等待线程一加入 + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + System.out.println(Thread.currentThread().getName()+"同步代码块剩余的票"+ticket--); + } + } + } + }else{ + while(true){ + show(); + } + + } + } + + public static synchronized void show(){ + if(ticket>0){ + System.out.println(Thread.currentThread().getName()+"同步函数剩余的票"+ticket--); + } + } + +} diff --git a/src/com/luoamin/thread/ThreadCommunication.java b/src/com/luoamin/thread/ThreadCommunication.java new file mode 100644 index 0000000..0f4e2ed --- /dev/null +++ b/src/com/luoamin/thread/ThreadCommunication.java @@ -0,0 +1,94 @@ +package com.luoamin.thread; + +public class ThreadCommunication { + /*alt+方向键可以将想要的代码移动到想要的地方*/ + public static void main(String[] args) { + Resource re = new Resource(); + Input in = new Input(re); + Output out = new Output(re); + Thread t1 = new Thread(in); + Thread t2 = new Thread(out); + Thread t3 = new Thread(in);//如果多添加一个线程,那么就要使用resource.notifyAll();,线程通信结束 + t1.start(); + t2.start(); + t3.start(); + } +} + +class Resource { + String name; + String sex; + boolean flag = false; +} +/**多线程通讯(wait(),notify(),notifyAll()),这个歌方法必须在synchronized里面调用 + * 并且这几个方法必须要锁的对象来调用,即resource.notifyAll(),已经给resource对象上锁 + * 多线程安全的两个线程必须持有同一把锁 + * 线程可以给任意对象上锁,例如Object对象 + * + * */ +class Input implements Runnable { + private Resource resource; + + // 构造方法注入可以使得调用两个线程时 可以共用同一资源,resource对象,精彩之处 + public Input(Resource resource) { + this.resource = resource; + } + + public void run() { + int x = 0; + while (true) { + synchronized (resource) { + if (resource.flag) {//如果为true,先让他睡一觉 + try { + resource.wait(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } else { + + if (x == 0) { + resource.name = "楠楠"; + resource.sex = "女"; + } else { + resource.name = "彪彪"; + resource.sex = "男"; + } + x = (x + 1) % 2; + resource.flag = true; + resource.notifyAll(); + } + } + } + } + } + + +class Output implements Runnable { + private Resource resource; + public Output(Resource resource) { + this.resource = resource; + } + public void run() { + while (true) { + /* + * 因为这个线程共用resource这个资源,自由保证他们是同一把锁才能保证多线程输出不会出问题, + * 到这里,就不会出现性别,名称错乱了,但还有一个问题,如果我想两个人的信息交叉输出又该怎么弄 + * wait方法是将手中的执行权利交出,不能和notifyAll方法同时在一个条件快中执行 + */ + synchronized (resource) { + if (!resource.flag) { + try { + resource.wait(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } else { + System.out.println("姓名:" + resource.name + " 性别:" + + resource.sex); + resource.flag = false; + resource.notifyAll(); + } + } + } + } +} \ No newline at end of file diff --git a/src/com/luoamin/thread/ThreadMethod.java b/src/com/luoamin/thread/ThreadMethod.java new file mode 100644 index 0000000..e1ce20c --- /dev/null +++ b/src/com/luoamin/thread/ThreadMethod.java @@ -0,0 +1,40 @@ +package com.luoamin.thread; + +public class ThreadMethod { + public static void main(String[] args) { + MyThreadrun aaa=new MyThreadrun(); + + Thread t1=new Thread(aaa); + MyThreadn t2=new MyThreadn(); + t1.setDaemon(true); + t1.setPriority(Thread.MAX_PRIORITY);//10,最大执行权限 + t1.start(); + + try { + t1.join();//先让t1执行 + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + t2.start(); + + } + +} + +class MyThreadrun implements Runnable { + public void run(){ + + for(int i=0;i<10;i++){ + System.out.println("线程一"+i); + } + } +} + +class MyThreadn extends Thread{ + public void run(){ + for(int i=0;i<10;i++){ + System.out.println("线程二"+i); + } + } +} diff --git a/src/com/luoamin/thread/ThreadSington.java b/src/com/luoamin/thread/ThreadSington.java new file mode 100644 index 0000000..b8b99ef --- /dev/null +++ b/src/com/luoamin/thread/ThreadSington.java @@ -0,0 +1,18 @@ +package com.luoamin.thread; + +public class ThreadSington { + + private ThreadSington(){} + public static ThreadSington instance=null; + //饿汉式不会存在线程安全问题,因为在类加载的时候就已经实例化了,没有判断,所有没有线程安全问题 + public static ThreadSington getInstance(){ + if(instance==null){//这里比运用同步函数要高效 + synchronized (ThreadSington.class){//静态方法的锁是Class对象,写this会报错 + if(instance==null){//懒汉式单例模式由于这里要判断,会存在线程安全问题,加上同步 + instance=new ThreadSington(); + } + } + } + return instance; + } +} diff --git a/src/com/luoamin/thread/test/DeadThread.java b/src/com/luoamin/thread/test/DeadThread.java new file mode 100644 index 0000000..6cd9ab5 --- /dev/null +++ b/src/com/luoamin/thread/test/DeadThread.java @@ -0,0 +1,43 @@ +package com.luoamin.thread.test; + +public class DeadThread { + public static void main(String[] args) { + Dead de=new Dead(false); + Dead de1=new Dead(true); + Thread t1=new Thread(de); + Thread t2=new Thread(de1); + t1.start(); + t2.start(); + } + + +} +class Dead implements Runnable{ + private boolean flag; + public Dead(boolean flag){ + this.flag=flag; + } + @Override + public void run() { + if(flag){ + synchronized (Lock.a){ + System.out.println("锁住资源a"); + synchronized (Lock.b){ + System.out.println("锁住资源b"); + } + } + }else{ + synchronized (Lock.b){ + System.out.println("锁住资源b"); + synchronized (Lock.a){ + System.out.println("锁住资源a"); + } + } + } + } + +} +class Lock{ + static Object a=new Object(); + static Object b=new Object(); +} \ No newline at end of file diff --git a/src/com/luoamin/thread/test/People.java b/src/com/luoamin/thread/test/People.java new file mode 100644 index 0000000..3387e30 --- /dev/null +++ b/src/com/luoamin/thread/test/People.java @@ -0,0 +1,6 @@ +package com.luoamin.thread.test; + +public interface People { + public void run(); + +} diff --git a/src/com/luoamin/thread/test/Test1.java b/src/com/luoamin/thread/test/Test1.java new file mode 100644 index 0000000..9a08dad --- /dev/null +++ b/src/com/luoamin/thread/test/Test1.java @@ -0,0 +1,49 @@ +package com.luoamin.thread.test; + +import java.io.UnsupportedEncodingException; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Test; + +public class Test1 { + + public static void main(String[] args) { + String []aaa={}; + HashMap map=new HashMap(); + map.put("kan", "ain"); + map.put("amin", "laiba"); + + for(int i=0;imap1 :map.entrySet()){ +// System.out.println(map1.toString()); + } + } + + public HashMap> getList(){ + return null; + } + + @Test + public void ggg(){ + System.out.println("我爱你"); + + String aaa="fff"; + try { + //aaa.getBytes("iso8859-1")写成aaa.getBytes()也可以 + String b=new String(aaa.getBytes("iso8859-1"), "utf-8"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + + + + } +} diff --git a/src/com/luoamin/thread/test/Test3.java b/src/com/luoamin/thread/test/Test3.java new file mode 100644 index 0000000..3d2515d --- /dev/null +++ b/src/com/luoamin/thread/test/Test3.java @@ -0,0 +1,11 @@ +package com.luoamin.thread.test; + +public class Test3 implements Yaan{ + + @Override + public void run() { + String d = new String(); + } + + +} diff --git a/src/com/luoamin/thread/test/Test5.java b/src/com/luoamin/thread/test/Test5.java new file mode 100644 index 0000000..a15e1fe --- /dev/null +++ b/src/com/luoamin/thread/test/Test5.java @@ -0,0 +1,5 @@ +package com.luoamin.thread.test; + +public class Test5 extends Test3,Test1{ + +} diff --git a/src/com/luoamin/thread/test/TestConCurrentHashMap.java b/src/com/luoamin/thread/test/TestConCurrentHashMap.java new file mode 100644 index 0000000..a48032c --- /dev/null +++ b/src/com/luoamin/thread/test/TestConCurrentHashMap.java @@ -0,0 +1,61 @@ +package com.luoamin.thread.test; + +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; +import java.util.concurrent.ConcurrentHashMap; + +public class TestConCurrentHashMap { + public volatile int count = 0; + public static void main(String[] args) { + TestConCurrentHashMap a=new TestConCurrentHashMap(); + TestConCurrentHashMap b=new TestConCurrentHashMap(); + String vv="fff"; + //com.luoamin.thread.test.TestConCurrentHashMap@1d209d56对象 + //24ee5d13,1171716823======619601171,101286对象或者字符串、数字的哈希码,他是一个int类型数字 + System.out.println(a+"======"+b.hashCode()); + System.out.println(vv.hashCode()); + } + + public static void testHashMap(){ + /*HashMap或者ArrayList边遍历边删除数据会报java.util.ConcurrentModificationException异常*/ + Map conMap = new HashMap(); + for (long i = 0; i < 15; i++) { + conMap.put(i, i + ""); + } + Thread thread = new Thread(new Runnable() { + public void run(){} + }); + Thread thread2 = new Thread(new Runnable() { + public void run(){} + }); + for (Entry entry : conMap.entrySet()) { + long key = entry.getKey(); + if (key < 10) { + conMap.remove(key); + } + } + } + public static void testConCurrentHashMap(){ + /**对ConcurrentHashMap边遍历边删除或者增加操作不会产生异常(可以不用迭代方式删除元素), + * 因为其内部已经做了维护,遍历的时候都能获得最新的值。即便是多个线程一起删除、添加元素也没问题。 + * */ + + Map conMap = new ConcurrentHashMap(); + for (long i = 0; i < 15; i++) { + conMap.put(i, i + ""); + } + + for (Entry entry : conMap.entrySet()) { + long key = entry.getKey(); + if (key < 10) { + conMap.remove(key); + } + } + + for (Entry entry : conMap.entrySet()) { + System.out.println(entry.getKey() + " " + entry.getValue()); + } + } + +} diff --git a/src/com/luoamin/thread/test/TestProducerAndConsumer.java b/src/com/luoamin/thread/test/TestProducerAndConsumer.java new file mode 100644 index 0000000..99263b6 --- /dev/null +++ b/src/com/luoamin/thread/test/TestProducerAndConsumer.java @@ -0,0 +1,79 @@ +package com.luoamin.thread.test; +/** + * 生产者消费者模式测试 + * @author john + * + */ +public class TestProducerAndConsumer { + public static void main(String[] args) { + Resource re=new Resource(); + Producer pro=new Producer(re); + Consumer con=new Consumer(re); + Thread t1=new Thread(pro); + Thread t2=new Thread(con); + t1.start(); + t2.start(); + } + + +} + +class Resource { + boolean flag=false; + public synchronized void producer(){ + while(true){ + if(this.flag){ + try { + this.wait(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + }else{ + System.out.println("生产者生产了一条数据!"); + this.flag=true; + this.notify(); + } + } + } + + public synchronized void consumer(){ + while(true){ + if(!this.flag){ + try { + this.wait(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + }else{ + System.out.println("消费者消费了一条数据!"); + this.flag=false; + this.notify(); + } + } + } + +} + +class Producer implements Runnable{ + private Resource resource; + public Producer(Resource resource){ + this.resource=resource; + } + @Override + public void run() { + resource.producer(); + } + +} + +class Consumer implements Runnable{ + private Resource resource; + public Consumer(Resource resource){ + this.resource=resource; + } + @Override + public void run() { + resource.consumer(); + } + +} \ No newline at end of file diff --git a/src/com/luoamin/thread/test/Yaan.java b/src/com/luoamin/thread/test/Yaan.java new file mode 100644 index 0000000..2059a57 --- /dev/null +++ b/src/com/luoamin/thread/test/Yaan.java @@ -0,0 +1,5 @@ +package com.luoamin.thread.test; + +public interface Yaan extends People,Runnable{ + String d = new String(); +} diff --git a/src/com/luoamin/thread/test1/DieThread.java b/src/com/luoamin/thread/test1/DieThread.java new file mode 100644 index 0000000..46f2d7f --- /dev/null +++ b/src/com/luoamin/thread/test1/DieThread.java @@ -0,0 +1,40 @@ +package com.luoamin.thread.test1; + +public class DieThread extends Thread{ + private boolean flag;//flag其实没有什么用,关键用在推出线程的标志 + public DieThread(boolean flag){ + this.flag=flag; + } + public static void main(String[] args) { + DieThread t1=new DieThread(true); + DieThread t2=new DieThread(false); + t1.start(); + t2.start(); + } + + public void run(){ + for(int i=0;i<100;i++){ + if(i<50){//flag + synchronized (Resource1.obj1) { + System.out.println("obj1"); + synchronized(Resource1.obj2){ + System.out.println(Thread.currentThread().getName()+"====="+i); + } + } + }else{ + synchronized (Resource1.obj2) { + System.out.println("obj2"); + synchronized(Resource1.obj1){ + System.out.println(Thread.currentThread().getName()+"====="+i); + } + } + } + } + } +} + +class Resource1{ + static Object obj1=new Object(); + static Object obj2=new Object(); +} + diff --git a/src/com/luoamin/thread/test1/MyThread.java b/src/com/luoamin/thread/test1/MyThread.java new file mode 100644 index 0000000..88d5948 --- /dev/null +++ b/src/com/luoamin/thread/test1/MyThread.java @@ -0,0 +1,21 @@ +package com.luoamin.thread.test1; + +public class MyThread extends Thread{ + Object obj=new Object(); + public void run(){ + + for(int i=0;i<100;i++){ + synchronized (obj){ + System.out.println(Thread.currentThread().getName()+"====="+i); + } + } + } + + public static void main(String[] args) { + MyThread th=new MyThread(); + Thread t=new Thread(th, "线程a"); + Thread t1=new Thread(th, "线程b"); + t.start(); + t1.start(); + } +} diff --git a/src/com/luoamin/thread/test1/Resource.java b/src/com/luoamin/thread/test1/Resource.java new file mode 100644 index 0000000..6171a78 --- /dev/null +++ b/src/com/luoamin/thread/test1/Resource.java @@ -0,0 +1,70 @@ +package com.luoamin.thread.test1; + +public class Resource { + private boolean flag=false; + public synchronized void pro(){ + while(true){ + if(flag){ + try { + this.wait(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + }else{ + System.out.println(Thread.currentThread().getName()+"生产者生产了一条数据"); + flag=true; + this.notify(); + } + } + } + public synchronized void cus(){ + while(true){ + if(!flag){ + try { + this.wait(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + }else{ + System.out.println(Thread.currentThread().getName()+"消费者消费了一条数据"); + flag=false; + this.notify(); + } + } + } + + public static void main(String[] args) { + Resource th=new Resource(); + Producer pp=new Producer(th); + Cusstomer cu=new Cusstomer(th); + Thread t1=new Thread(pp,"线程a"); + Thread t2=new Thread(cu,"线程b"); + t1.start(); + t2.start(); + } + +} +class Producer implements Runnable{ + private Resource resource; + public Producer(Resource resource){ + this.resource=resource; + } + public void run() { + resource.pro(); + } +} + +class Cusstomer implements Runnable{ + private Resource resource; + public Cusstomer(Resource resource){ + this.resource=resource; + } + public void run() { + resource.cus(); + } + +} + + + + diff --git a/src/com/luoamin/thread/test1/TestSinoton.java b/src/com/luoamin/thread/test1/TestSinoton.java new file mode 100644 index 0000000..0f39df5 --- /dev/null +++ b/src/com/luoamin/thread/test1/TestSinoton.java @@ -0,0 +1,31 @@ +package com.luoamin.thread.test1; + +import java.util.concurrent.ThreadPoolExecutor; + +public class TestSinoton { + + + private TestSinoton(){}; + private static TestSinoton instance=null; + public static TestSinoton getInstance(){ + if(instance==null){ + instance=new TestSinoton(); + } + return instance; + } + + + public static void main(String[] args) { +// TestSinoton a=TestSinoton.getInstance(); +// TestSinoton b=TestSinoton.getInstance(); +// TestSinoton c=TestSinoton.getInstance(); +// System.out.println(a.hashCode()+"++++++++="+b.hashCode()+"========="+c.hashCode()); + Integer a=5; + int b=5; + String ff=new String("ggg"); + String ff1=new String("ggg"); + System.out.println(); + + + } +} diff --git a/src/com/luoamin/thread/threadpool/BlockingQuences.java b/src/com/luoamin/thread/threadpool/BlockingQuences.java new file mode 100644 index 0000000..f09c3d8 --- /dev/null +++ b/src/com/luoamin/thread/threadpool/BlockingQuences.java @@ -0,0 +1,70 @@ +package com.luoamin.thread.threadpool; + +import java.util.PriorityQueue; +/** + * 使用阻塞队列实现生产者消费者模式比使用非阻塞队列简单 + * @author john + *某个模块负责产生数据,这些数据由另一个模块来负责处理(此处的模块是广义的,可以是类、函数、线程、进程等) + *产生数据的模块,就形象地称为生产者;而处理数据的模块,就称为消费者。 + */ +public class BlockingQuences { + private int size=10; + private PriorityQueuequene=new PriorityQueue(size); + public static void main(String[] args) { + BlockingQuences t1=new BlockingQuences(); + Producer po=t1.new Producer(); + Consumer co=t1.new Consumer(); + po.start(); + co.start(); + } + + class Producer extends Thread{ + public void run(){ + while(true){ + synchronized (quene) { + if(quene.size()==size){ + try { + System.out.println("队列已满,不能继续插入数据!"); + quene.wait(); + } catch (InterruptedException e) { + e.printStackTrace(); + quene.notify(); + } + }else{ + //非阻塞队列推荐使用offer方法添加元素 + quene.offer(1); + System.out.println("队列插入一条数据!"); + quene.notify(); + } + } + } + } + } + + class Consumer extends Thread{ + public void run(){ + + while(true){ + synchronized (quene) { + if(quene.size()==0){ + try { + System.out.println("队列空,不能删除!"); + quene.wait(); + } catch (InterruptedException e) { + e.printStackTrace(); + quene.notify(); + } + }else{ + //非阻塞队列推荐使用poll方法删除元素 + quene.poll(); + System.out.println("队列删除一条数据!"); + quene.notify(); + } + } + } + + } + } +} + + diff --git a/src/com/luoamin/thread/threadpool/FinalThreadPool.java b/src/com/luoamin/thread/threadpool/FinalThreadPool.java new file mode 100644 index 0000000..ddf09a3 --- /dev/null +++ b/src/com/luoamin/thread/threadpool/FinalThreadPool.java @@ -0,0 +1,46 @@ +package com.luoamin.thread.threadpool; + +import java.util.concurrent.Executor; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +/** + * 固定大小线程池 + * 当线程任务的大小超过线程池的尺寸时,其他进入线程池的线程就会处于等待之中 + * @author john + * + */ +public class FinalThreadPool { + + public static void main(String[] args) { + //创建一个固定数量的线程池 + //1的运行结果 +// pool-1-thread-1线程开始+====== +// pool-1-thread-2线程开始+====== +// pool-1-thread-2线程开始+====== +// pool-1-thread-2线程开始+====== +// pool-1-thread-1线程开始+====== + ExecutorService pool=Executors.newFixedThreadPool(10); + + //单任务线程池,这里的线程池只会开一个任务 +// ExecutorService pool = Executors.newSingleThreadExecutor(); + + Thread t1=new MyThread(); + Thread t2=new MyThread(); + Thread t3=new MyThread(); + Thread t4=new MyThread(); + Thread t5=new MyThread(); + //将线程放入池中进行执行 + pool.execute(t1); + pool.execute(t2); + pool.execute(t3); + pool.execute(t4); + pool.execute(t5); + pool.shutdown(); + } + +} +class MyThread extends Thread{ + public void run(){ + System.out.println(Thread.currentThread().getName()+"线程开始+======"); + } +} \ No newline at end of file diff --git a/src/com/luoamin/thread/threadpool/MyThreadPool.java b/src/com/luoamin/thread/threadpool/MyThreadPool.java new file mode 100644 index 0000000..86ffb16 --- /dev/null +++ b/src/com/luoamin/thread/threadpool/MyThreadPool.java @@ -0,0 +1,46 @@ +package com.luoamin.thread.threadpool; + +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +public class MyThreadPool { + /** + * 自定义线程池 + */ + + + public static void main(String[] args) { + muthreadpool(); + System.out.println(System.currentTimeMillis()); + } + + public static void muthreadpool(){ + //ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue) + //创建等待队列 + BlockingQueue quen=new ArrayBlockingQueue(20); + ThreadPoolExecutor pool =new ThreadPoolExecutor(2, 3, 2, TimeUnit.MILLISECONDS, quen); + Thread t1=new MyThread2(); + Thread t2=new MyThread2(); + Thread t3=new MyThread2(); + Thread t4=new MyThread2(); + Thread t5=new MyThread2(); + //将线程加入线程池中执行 + pool.execute(t1); + pool.execute(t2); + pool.execute(t3); + pool.execute(t4); + pool.execute(t5); + pool.shutdown(); +// for(;;){死循环 +// +// } + } +} + +class MyThread2 extends Thread{ + public void run(){ + System.out.println(Thread.currentThread().getName()+"线程进行中。。。"); + } +} \ No newline at end of file diff --git a/src/com/luoamin/thread/threadpool/SuspendQuene.java b/src/com/luoamin/thread/threadpool/SuspendQuene.java new file mode 100644 index 0000000..f3ff906 --- /dev/null +++ b/src/com/luoamin/thread/threadpool/SuspendQuene.java @@ -0,0 +1,50 @@ +package com.luoamin.thread.threadpool; + +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.BlockingQueue; +/** + * 使用阻塞队列实现生产者消费者模式比使用非阻塞队列简单 + * @author john + *某个模块负责产生数据,这些数据由另一个模块来负责处理(此处的模块是广义的,可以是类、函数、线程、进程等) + *产生数据的模块,就形象地称为生产者;而处理数据的模块,就称为消费者。 + */ +public class SuspendQuene { + + private int size=10; + private BlockingQueuequene=new ArrayBlockingQueue(size); + public static void main(String[] args) { + SuspendQuene t1=new SuspendQuene(); + Producer1 po=t1.new Producer1(); + Consumer1 co=t1.new Consumer1(); + po.start(); + co.start(); + } + + class Producer1 extends Thread{ + public void run(){ + while(true){ + synchronized (quene) { + try { + quene.put(1); + } catch (InterruptedException e) { + e.printStackTrace(); + } + System.out.println("队列插入一条数据!"); + } + } + } + } + + class Consumer1 extends Thread{ + public void run(){ + while(true){ + synchronized (quene) { + quene.poll(); + System.out.println("队列删除一条数据!"); + } + } + + } + } + +} diff --git a/src/com/luoamin/thread/threadpool/Test.java b/src/com/luoamin/thread/threadpool/Test.java new file mode 100644 index 0000000..b4f29e6 --- /dev/null +++ b/src/com/luoamin/thread/threadpool/Test.java @@ -0,0 +1,75 @@ +package com.luoamin.thread.threadpool; + +import java.util.PriorityQueue; +/** + * 生产者消费者模式模板,并不是我的代码 + * @author john + * + */ +public class Test { + private int queueSize = 10; + private PriorityQueue queue = new PriorityQueue(queueSize); + + public static void main(String[] args) { + Test test = new Test(); + Producer producer = test.new Producer(); + Consumer consumer = test.new Consumer(); + + producer.start(); + consumer.start(); + } + + class Consumer extends Thread{ + + @Override + public void run() { + consume(); + } + + private void consume() { + while(true){ + synchronized (queue) { + while(queue.size() == 0){ + try { + System.out.println("队列空,等待数据"); + queue.wait(); + } catch (InterruptedException e) { + e.printStackTrace(); + queue.notify(); + } + } + queue.poll(); //每次移走队首元素 + queue.notify(); + System.out.println("从队列取走一个元素,队列剩余"+queue.size()+"个元素"); + } + } + } + } + + class Producer extends Thread{ + + @Override + public void run() { + produce(); + } + + private void produce() { + while(true){ + synchronized (queue) { + while(queue.size() == queueSize){ + try { + System.out.println("队列满,等待有空余空间"); + queue.wait(); + } catch (InterruptedException e) { + e.printStackTrace(); + queue.notify(); + } + } + queue.offer(1); //每次插入一个元素 + queue.notify(); + System.out.println("向队列取中插入一个元素,队列剩余空间:"+(queueSize-queue.size())); + } + } + } + } +} \ No newline at end of file diff --git a/src/com/luoamin/thread/threadpool/VariableThredPool.java b/src/com/luoamin/thread/threadpool/VariableThredPool.java new file mode 100644 index 0000000..a9f0d34 --- /dev/null +++ b/src/com/luoamin/thread/threadpool/VariableThredPool.java @@ -0,0 +1,80 @@ +package com.luoamin.thread.threadpool; + +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + +public class VariableThredPool { + + public static void main(String[] args) { + danrenwu(); + } + + /** + * 可变尺寸的线程池 + */ + public static void variablethreadpool(){ + //创建一个可根据需要创建新线程的线程池,但是在以前构造的线程可用时将重用它们 + ExecutorService pool =Executors.newCachedThreadPool(); + Thread t1=new MyThread1(); + Thread t2=new MyThread1(); + Thread t3=new MyThread1(); + Thread t4=new MyThread1(); + Thread t5=new MyThread1(); + //将线程放入池中进行执行 + pool.execute(t1); + pool.execute(t2); + pool.execute(t3); + pool.execute(t4); + pool.execute(t5); + pool.shutdown(); + } + + /** + * 延迟连接池 + */ + public static void yanchiThreadPool(){ + //创建一个线程池,它可安排在给定延迟后运行命令或者定期地执行。 + ScheduledExecutorService pool =Executors.newScheduledThreadPool(2); + Thread t1=new MyThread1(); + Thread t2=new MyThread1(); + Thread t3=new MyThread1(); + Thread t4=new MyThread1(); + Thread t5=new MyThread1(); + //将线程放入池中进行执行 + pool.execute(t1); + pool.execute(t2); + pool.execute(t3); + pool.schedule(t4, 10, TimeUnit.MILLISECONDS); + pool.schedule(t5, 10, TimeUnit.MILLISECONDS); + pool.shutdown(); + } + + /** + * 单任务延迟连接池 + */ + public static void danrenwu(){ + //创建一个线程池,它可安排在给定延迟后运行命令或者定期地执行。 + ScheduledExecutorService pool =Executors.newSingleThreadScheduledExecutor(); + Thread t1=new MyThread1(); + Thread t2=new MyThread1(); + Thread t3=new MyThread1(); + Thread t4=new MyThread1(); + Thread t5=new MyThread1(); + //将线程放入池中进行执行 + pool.execute(t1); + pool.execute(t2); + pool.execute(t3); + pool.schedule(t4, 10, TimeUnit.MILLISECONDS); + pool.schedule(t5, 10, TimeUnit.MILLISECONDS); + pool.shutdown(); + } + +} + +class MyThread1 extends Thread{ + public void run(){ + System.out.println(Thread.currentThread().getName()+"线程完成!"); + } +} \ No newline at end of file diff --git a/src/com/luoamin/util/TestBeanUtil.java b/src/com/luoamin/util/TestBeanUtil.java new file mode 100644 index 0000000..73cb29f --- /dev/null +++ b/src/com/luoamin/util/TestBeanUtil.java @@ -0,0 +1,5 @@ +package com.luoamin.util; + +public class TestBeanUtil { + +} diff --git a/src/com/luoamin/util/TestString.java b/src/com/luoamin/util/TestString.java new file mode 100644 index 0000000..d55f654 --- /dev/null +++ b/src/com/luoamin/util/TestString.java @@ -0,0 +1,10 @@ +package com.luoamin.util; + +public class TestString { + + public static void main(String[] args) { + String a=new String("我是一个中国人!,我爱我的祖国"); + System.out.println(a.valueOf(10)); + } + +} diff --git a/src/com/luoamin/util/TestUtil.java b/src/com/luoamin/util/TestUtil.java new file mode 100644 index 0000000..d978c3e --- /dev/null +++ b/src/com/luoamin/util/TestUtil.java @@ -0,0 +1,5 @@ +package com.luoamin.util; + +public class TestUtil { + +} diff --git a/src/com/luoamin/xml/dom/XML.java b/src/com/luoamin/xml/dom/XML.java new file mode 100644 index 0000000..e6f5a7e --- /dev/null +++ b/src/com/luoamin/xml/dom/XML.java @@ -0,0 +1,140 @@ +package com.luoamin.xml.dom; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.ArrayList; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +//将XML中的节点以对象的方式进行封装 +class XMLObject{ + private String name,grade,age; + public XMLObject(String name,String grade,String age) { + this.name=name; + this.grade=grade; + this.age=age; + + } + //返回一个XML的节点类Element + public Element getXMLObject(Document doc) throws ParserConfigurationException{ + + //通过Document类的createElement创建一个节点 + Element Name = doc.createElement("name"); + Element Grade= doc.createElement("grade"); + Element Age =doc.createElement("age"); + Element Student=doc.createElement("student"); + //Element类的setTextContent(String textContent)方法设置节点值 + Name.setTextContent(name); + Grade.setTextContent(grade); + Age.setTextContent(age); + Student.appendChild(Name); + Student.appendChild(Grade); + Student.appendChild(Age); + return Student; + } +} + +public class XML{ + + + public static void createXML(String XMLname)throws ParserConfigurationException, TransformerException, IOException{ + //创建一个Document类 + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + Document doc = builder.newDocument(); + //创建一个根节点,并且将根节点添加到Document对象中去 + Element root=doc.createElement("students"); + doc.appendChild(root); + //使用ArryayList,便于添加自己所创建的对象 + ArrayList stu=new ArrayList(); + stu.add(new XMLObject("Jhon","B","12")); + stu.add(new XMLObject("Mary","A","11")); + stu.add(new XMLObject("Simon","A","18")); + //将ArrayList里面的对象全部添加到根节点中去 + for(XMLObject t:stu){ + root.appendChild(t.getXMLObject(doc)); + } + //开始把Document映射到文件 + TransformerFactory transFactory = TransformerFactory.newInstance(); + Transformer transFormer = transFactory.newTransformer(); + //设置输出结果并且生成XML文件 + DOMSource domSource = new DOMSource(doc); + File file = new File(XMLname); + if (!file.exists()) file.createNewFile(); + //设置输入源并且输出XML文件 + FileOutputStream out = new FileOutputStream(file); + StreamResult xmlResult = new StreamResult(out);//设置输入源 + transFormer.transform(domSource, xmlResult);//输出xml文件 + System.out.println(file.getAbsolutePath());//测试文件输出的路径 + } + public static void parseXML(String fileName) { + try { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + DocumentBuilder db = dbf.newDocumentBuilder(); + File file = new File(fileName); + if (file.exists()) { + Document doc = db.parse(file); + Element docEle = doc.getDocumentElement(); + + // Print root element of the document + System.out.println("Root element of the document: " + + docEle.getNodeName()); + + NodeList studentList = docEle.getElementsByTagName("student"); + + // Print total student elements in document + System.out.println("Total students: " + studentList.getLength()); + + if (studentList != null && studentList.getLength() > 0) { + for (int i = 0; i < studentList.getLength(); i++) { + + Node node = studentList.item(i); + + if (node.getNodeType() == Node.ELEMENT_NODE) { + + System.out.println("====================="); + + Element e = (Element) node; + NodeList nodeList = e.getElementsByTagName("name"); + System.out.println("Name: " + + nodeList.item(0).getChildNodes().item(0) + .getNodeValue()); + + nodeList = e.getElementsByTagName("grade"); + System.out.println("Grade: " + + nodeList.item(0).getChildNodes().item(0) + .getNodeValue()); + + nodeList = e.getElementsByTagName("age"); + System.out.println("Age: " + + nodeList.item(0).getChildNodes().item(0) + .getNodeValue()); + } + } + } else { + System.exit(1); + } + } + } catch (Exception e) { + System.out.println(e); + } + } + //测试 + public static void main(String []args) throws ParserConfigurationException, TransformerException, IOException{ + XML.createXML("D:/luoamin/Student.xml"); + XML.parseXML("D:/luoamin/Student.xml"); + } +} \ No newline at end of file diff --git a/src/com/luoamin/xml/log4j/TestDom4j.java b/src/com/luoamin/xml/log4j/TestDom4j.java new file mode 100644 index 0000000..758bd4a --- /dev/null +++ b/src/com/luoamin/xml/log4j/TestDom4j.java @@ -0,0 +1,101 @@ +package com.luoamin.xml.log4j; + +public class TestDom4j { + + public static void main(String[] args) { + read1(); + //read2(); + //write(); + } + + public static void read1() { + try { + SAXReader reader = new SAXReader(); + InputStream in = TestDom4j.class.getClassLoader().getResourceAsStream("test.xml"); + Document doc = reader.read(in); + Element root = doc.getRootElement(); + readNode(root, ""); + } catch (DocumentException e) { + e.printStackTrace(); + } + } + + @SuppressWarnings("unchecked") + public static void readNode(Element root, String prefix) { + if (root == null) return; + // 获取属性 + List attrs = root.attributes(); + if (attrs != null && attrs.size() > 0) { + System.err.print(prefix); + for (Attribute attr : attrs) { + System.err.print(attr.getValue() + " "); + } + System.err.println(); + } + // 获取他的子节点 + List childNodes = root.elements(); + prefix += "\t"; + for (Element e : childNodes) { + readNode(e, prefix); + } + } + + public static void read2() { + try { + SAXReader reader = new SAXReader(); + InputStream in = TestDom4j.class.getClassLoader().getResourceAsStream("test.xml"); + Document doc = reader.read(in); + doc.accept(new MyVistor()); + } catch (DocumentException e) { + e.printStackTrace(); + } + } + + public static void write() { + try { + // 创建一个xml文档 + Document doc = DocumentHelper.createDocument(); + Element university = doc.addElement("university"); + university.addAttribute("name", "tsu"); + // 注释 + university.addComment("这个是根节点"); + Element college = university.addElement("college"); + college.addAttribute("name", "cccccc"); + college.setText("text"); + + File file = new File("src/dom4j-modify.xml"); + if (file.exists()) { + file.delete(); + } + file.createNewFile(); + XMLWriter out = new XMLWriter(new FileWriter(file)); + out.write(doc); + out.flush(); + out.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + class MyVistor extends VisitorSupport { + public void visit(Attribute node) { + System.out.println("Attibute: " + node.getName() + "=" + + node.getValue()); + } + + public void visit(Element node) { + if (node.isTextOnly()) { + System.out.println("Element: " + node.getName() + "=" + + node.getText()); + } else { + System.out.println(node.getName()); + } + } + + @Override + public void visit(ProcessingInstruction node) { + System.out.println("PI:" + node.getTarget() + " " + node.getText()); + } + +} diff --git a/src/com/luoamin/xml/sax/Hander.java b/src/com/luoamin/xml/sax/Hander.java new file mode 100644 index 0000000..3391931 --- /dev/null +++ b/src/com/luoamin/xml/sax/Hander.java @@ -0,0 +1,53 @@ +package com.luoamin.xml.sax; + +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.DefaultHandler; + +public class Hander extends DefaultHandler{ + private boolean isTest = false; + + public Hander() { + } + + + /** + * 开始节点,根据开始节点名建立相关条件或创建相关对象 + * */ + public void startElement(String uri, String localName, String qName, + Attributes attributes) throws SAXException { + super.startElement(uri, localName, qName, attributes); + + if ("tests".equals(qName)) { + isTest = true; + } else if ("test".equals(qName)){ + System.out.println("parser test start"); + } + + } + + /** + * 结束节点,根据结束节点完成相关动作 + * */ + public void endElement(String uri, String localName, String qName) + throws SAXException { + super.endElement(uri, localName, qName); + + if ("tests".equals(qName)) { + isTest = false; + } + System.out.println("parser test end"); + } + + /** + * 节点间的文字信息,可通过stringbuffer收集每一个节点的文字信息, + * 在endElement中清空stringbuffer,收集下一个 + * */ + public void characters(char[] ch, int start, int length) + throws SAXException { + super.characters(ch, start, length); + String content = new String(ch, start, length); + System.out.println("content = " + content); + + } +} diff --git a/src/com/luoamin/xml/sax/SaxXmlParse.java b/src/com/luoamin/xml/sax/SaxXmlParse.java new file mode 100644 index 0000000..6839ca8 --- /dev/null +++ b/src/com/luoamin/xml/sax/SaxXmlParse.java @@ -0,0 +1,43 @@ +package com.luoamin.xml.sax; + +import java.io.File; + +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; + +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.DefaultHandler; + +public class SaxXmlParse { + private static SAXParser mParser; + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + saxParserXml(); + } + + /** + * SAX解析XML文件采用事件驱动的方式进行,SAX是逐行扫描文件, + * 遇到符合条件的设定条件后就会触发特定的事件,回调你写好的事件处理程序(Hanlder) + */ + private static void saxParserXml() { + // TODO Auto-generated method stub + try { + //1.获取sax解析器的工厂对象 + SAXParserFactory mParserFactory = SAXParserFactory.newInstance(); + // 2.通过工厂对象 mParserFactory创建解析器对象mParser + mParser = mParserFactory.newSAXParser(); + //3.创建事件处理器对象mHanlder + Hander mHanlder = new Hander(); + //4.利用指定处理器解析指定文件 + mParser.parse(Constant.PARSER_XML_DIR + File.separator + "test.xml", mHanlder); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} diff --git a/src/testJva/Sub.java b/src/testJva/Sub.java new file mode 100644 index 0000000..8d98e1e --- /dev/null +++ b/src/testJva/Sub.java @@ -0,0 +1,26 @@ +package testJva; + +import java.util.HashMap; +import java.util.Map; + +public class Sub extends Super{ + public static final String SUCCESS="success"; + + public void getNum(){} + + public String jj(){ + String result=js + return SUCCESS; + } + + + //for (Map.Entry entry : map.keySet()) { + + public static void main(String[] args) { + HashMapmap=new HashMap(); + map.put(, 1); + for (Map.Entryentry : map.entrySet()) { + System.out.println(entry.getKey()+"===="+entry.getValue()); + } + } +} diff --git a/src/testJva/Super.java b/src/testJva/Super.java new file mode 100644 index 0000000..43db31e --- /dev/null +++ b/src/testJva/Super.java @@ -0,0 +1,5 @@ +package testJva; + +public class Super { + protected float getNum(){return 3.0f;} +} diff --git a/src/testJva/Test.java b/src/testJva/Test.java new file mode 100644 index 0000000..a4fb9c4 --- /dev/null +++ b/src/testJva/Test.java @@ -0,0 +1,7 @@ +package testJva; + +public interface Test { + int e=3; + void vv(); + +} diff --git a/src/testJva/TestArry.java b/src/testJva/TestArry.java new file mode 100644 index 0000000..e4c57a9 --- /dev/null +++ b/src/testJva/TestArry.java @@ -0,0 +1,44 @@ +package testJva; + +import java.lang.annotation.Annotation; + +public class TestArry { + + public static void main(String[] args) { + try + { + System.out.println("hello,jr"); + System.exit(0); + } + finally + { + System.out.println("88"); + } + } + private TestArry(){ + + } + + + + public void kkk(){ + System.out.println("----------0000"); + } + + + + + + + + + + + + + + + + + +} diff --git a/src/testJva/TestInt.java b/src/testJva/TestInt.java new file mode 100644 index 0000000..d9ab7f7 --- /dev/null +++ b/src/testJva/TestInt.java @@ -0,0 +1,25 @@ +package testJva; + +import java.io.FileOutputStream; +import java.io.PrintWriter; +/** + * 改程序 + * + */ +public class TestInt { + public int count(){ + return 1%9; + } + public static void main(String[]args){ + + try{ + PrintWriter out = + new PrintWriter(new FileOutputStream("d:/abc.txt")); + String name="chen"; + out.print(name); + }catch(Exception e){ + System.out.println("文件没有发现!"); + } + } + +} diff --git a/src/testJva/TestKK.java b/src/testJva/TestKK.java new file mode 100644 index 0000000..e597301 --- /dev/null +++ b/src/testJva/TestKK.java @@ -0,0 +1,21 @@ +package testJva; + +import org.junit.Test; + +public class TestKK { + @Test + public void vvv(){ + int i; + System.out.println(i); + System.out.println("wwwwwwwwwwwwwww"); + } + + + + public static void main(String[] args) { + TestKK gg=new TestKK(); + gg.vvv(); + + } + +} diff --git a/src/testJva/TestTwoClass.java b/src/testJva/TestTwoClass.java new file mode 100644 index 0000000..ba02699 --- /dev/null +++ b/src/testJva/TestTwoClass.java @@ -0,0 +1,22 @@ +package testJva; +/** + * + *一个class文件可以有多个以上的类,但只有一个用public修饰, + */ + class TestTwoClass { + public int getNumber(int a){ + return a+1; + } +} + + +class B extends TestTwoClass{ + public int getNumber(int a, char c){ + return a+2; + } + + public static void main(String[] args) { + B b=new B(); + System.out.println(b.getNumber(0)); + } +} \ No newline at end of file From ca74b4d17c0e3d69d045aab79ac5eedd8268de19 Mon Sep 17 00:00:00 2001 From: luoamin <2293121112@qq.com> Date: Sun, 26 Feb 2017 22:37:38 +0800 Subject: [PATCH 2/2] =?UTF-8?q?Java=E6=B5=8B=E8=AF=95=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 ++ src/com/luoamin/array/TestGithub.java | 7 +++++++ testJava | 1 + 3 files changed, 10 insertions(+) create mode 100644 src/com/luoamin/array/TestGithub.java create mode 160000 testJava diff --git a/.gitignore b/.gitignore index f48790f..99809cd 100644 --- a/.gitignore +++ b/.gitignore @@ -179,3 +179,5 @@ /bin/ /bin/ /bin/ +/bin/ +/bin/ diff --git a/src/com/luoamin/array/TestGithub.java b/src/com/luoamin/array/TestGithub.java new file mode 100644 index 0000000..9a65a7f --- /dev/null +++ b/src/com/luoamin/array/TestGithub.java @@ -0,0 +1,7 @@ +package com.luoamin.array; + +public class TestGithub { + + private String name; + +} diff --git a/testJava b/testJava new file mode 160000 index 0000000..e7ae5c6 --- /dev/null +++ b/testJava @@ -0,0 +1 @@ +Subproject commit e7ae5c660a6e09af4b9f1208117aaab59c2445b7