From a334a7cb5041a336b65d4761407a111b3dfce253 Mon Sep 17 00:00:00 2001 From: Administrator <18797818311@163.com> Date: Mon, 16 Jul 2018 21:00:21 +0800 Subject: [PATCH] reflect/Xiaobai --- Java-EE/.gitignore | 22 ++ Java-EE/.idea/artifacts/ConnectionAll_war.xml | 8 + .../artifacts/ConnectionAll_war_exploded.xml | 22 ++ Java-EE/.idea/artifacts/Java_EE_war.xml | 8 + .../.idea/artifacts/Java_EE_war_exploded.xml | 29 +++ Java-EE/.idea/compiler.xml | 18 ++ Java-EE/.idea/encodings.xml | 6 + .../inspectionProfiles/Project_Default.xml | 36 ++++ ...aven__commons_codec_commons_codec_1_10.xml | 13 ++ ..._commons_logging_commons_logging_1_1_1.xml | 13 ++ .../libraries/Maven__junit_junit_4_11.xml | 13 ++ .../libraries/Maven__log4j_log4j_1_2_17.xml | 13 ++ ...pache_commons_commons_collections4_4_1.xml | 13 ++ .../Maven__org_apache_poi_poi_3_16.xml | 13 ++ ..._org_apiguardian_apiguardian_api_1_0_0.xml | 13 ++ .../Maven__org_hamcrest_hamcrest_core_1_3.xml | 13 ++ ...nit_jupiter_junit_jupiter_api_5_3_0_M1.xml | 13 ++ ...atform_junit_platform_commons_1_3_0_M1.xml | 13 ++ ...Maven__org_opentest4j_opentest4j_1_1_0.xml | 13 ++ Java-EE/.idea/misc.xml | 16 ++ Java-EE/.idea/modules.xml | 8 + Java-EE/.idea/uiDesigner.xml | 124 ++++++++++++ Java-EE/.idea/vcs.xml | 6 + Java-EE/Java EE.iml | 43 ++++ Java-EE/LICENSE | 191 ++++++++++++++++++ Java-EE/README.md | 37 ++++ Java-EE/pom.xml | 96 +++++++++ .../java/collection/demo/CollectionDemo.java | 72 +++++++ Java-EE/src/main/java/domain/Person.java | 65 ++++++ Java-EE/src/main/java/domain/Student.java | 17 ++ Java-EE/src/main/java/domain/Tool1.java | 14 ++ Java-EE/src/main/java/domain/Tool2.java | 14 ++ Java-EE/src/main/java/domain/Util.java | 14 ++ Java-EE/src/main/java/domain/Worker.java | 17 ++ Java-EE/src/main/java/enumeration/Day.java | 8 + .../src/main/java/enumeration/DayDemo.java | 20 ++ .../java/enumeration/EnumerationDemo.java | 29 +++ .../main/java/enumeration/demo/EnumDemo.java | 15 ++ .../main/java/enumeration/demo1/Gender.java | 11 + .../enumeration/demo1/GenderDescription.java | 11 + .../java/enumeration/demo1/Operation.java | 48 +++++ .../main/java/enumeration/demo1/WeekEnum.java | 34 ++++ .../java/enumeration/demo1/WeekEnum02.java | 27 +++ .../main/java/enumeration/demo1/WeenEnum.java | 8 + .../java/enumeration/test/DemoTest01.java | 108 ++++++++++ .../java/enumeration/test/GenderTest.java | 18 ++ .../java/enumeration/test/OperationTest.java | 16 ++ Java-EE/src/main/java/foreach/ForInTest.java | 52 +++++ .../src/main/java/generic/GenericDemo.java | 39 ++++ .../src/main/java/generic/GenericDemo2.java | 26 +++ .../src/main/java/generic/GenericDemo3.java | 52 +++++ .../src/main/java/generic/GenericDemo4.java | 30 +++ .../src/main/java/generic/GenericDemo5.java | 50 +++++ .../src/main/java/generic/GenericDemo6.java | 30 +++ .../src/main/java/generic/GenericDemo7.java | 41 ++++ .../src/main/java/generic/GenericDemo8.java | 48 +++++ Java-EE/src/main/java/list/demo/ListDemo.java | 56 +++++ .../main/java/list/test/ArrayListTest.java | 36 ++++ .../main/java/list/test/ArrayListTest2.java | 39 ++++ Java-EE/src/main/java/map/MapDemo.java | 35 ++++ Java-EE/src/main/java/poi/ExportExcel.java | 63 ++++++ Java-EE/src/main/java/poi/ExportExcel02.java | 46 +++++ Java-EE/src/main/java/poi/ExportExcel03.java | 45 +++++ Java-EE/src/main/java/reflect/DemoTest01.java | 40 ++++ Java-EE/src/main/java/reflect/Foo.java | 18 ++ Java-EE/src/main/java/reflect/Goo.java | 4 + Java-EE/src/main/java/reflect/demoTest.java | 56 +++++ .../src/main/java/try_catch/Exception01.java | 17 ++ .../src/main/java/try_catch/Exception02.java | 24 +++ .../src/main/java/try_catch/Exception03.java | 24 +++ .../src/main/java/try_catch/Exception04.java | 81 ++++++++ .../main/java/try_catch/TestException.java | 45 +++++ .../src/main/java/try_catch/Try_Catch01.java | 79 ++++++++ Java-EE/src/main/webapp/WEB-INF/web.xml | 7 + Java-EE/src/main/webapp/index.jsp | 5 + 75 files changed, 2467 insertions(+) create mode 100644 Java-EE/.gitignore create mode 100644 Java-EE/.idea/artifacts/ConnectionAll_war.xml create mode 100644 Java-EE/.idea/artifacts/ConnectionAll_war_exploded.xml create mode 100644 Java-EE/.idea/artifacts/Java_EE_war.xml create mode 100644 Java-EE/.idea/artifacts/Java_EE_war_exploded.xml create mode 100644 Java-EE/.idea/compiler.xml create mode 100644 Java-EE/.idea/encodings.xml create mode 100644 Java-EE/.idea/inspectionProfiles/Project_Default.xml create mode 100644 Java-EE/.idea/libraries/Maven__commons_codec_commons_codec_1_10.xml create mode 100644 Java-EE/.idea/libraries/Maven__commons_logging_commons_logging_1_1_1.xml create mode 100644 Java-EE/.idea/libraries/Maven__junit_junit_4_11.xml create mode 100644 Java-EE/.idea/libraries/Maven__log4j_log4j_1_2_17.xml create mode 100644 Java-EE/.idea/libraries/Maven__org_apache_commons_commons_collections4_4_1.xml create mode 100644 Java-EE/.idea/libraries/Maven__org_apache_poi_poi_3_16.xml create mode 100644 Java-EE/.idea/libraries/Maven__org_apiguardian_apiguardian_api_1_0_0.xml create mode 100644 Java-EE/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml create mode 100644 Java-EE/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_api_5_3_0_M1.xml create mode 100644 Java-EE/.idea/libraries/Maven__org_junit_platform_junit_platform_commons_1_3_0_M1.xml create mode 100644 Java-EE/.idea/libraries/Maven__org_opentest4j_opentest4j_1_1_0.xml create mode 100644 Java-EE/.idea/misc.xml create mode 100644 Java-EE/.idea/modules.xml create mode 100644 Java-EE/.idea/uiDesigner.xml create mode 100644 Java-EE/.idea/vcs.xml create mode 100644 Java-EE/Java EE.iml create mode 100644 Java-EE/LICENSE create mode 100644 Java-EE/README.md create mode 100644 Java-EE/pom.xml create mode 100644 Java-EE/src/main/java/collection/demo/CollectionDemo.java create mode 100644 Java-EE/src/main/java/domain/Person.java create mode 100644 Java-EE/src/main/java/domain/Student.java create mode 100644 Java-EE/src/main/java/domain/Tool1.java create mode 100644 Java-EE/src/main/java/domain/Tool2.java create mode 100644 Java-EE/src/main/java/domain/Util.java create mode 100644 Java-EE/src/main/java/domain/Worker.java create mode 100644 Java-EE/src/main/java/enumeration/Day.java create mode 100644 Java-EE/src/main/java/enumeration/DayDemo.java create mode 100644 Java-EE/src/main/java/enumeration/EnumerationDemo.java create mode 100644 Java-EE/src/main/java/enumeration/demo/EnumDemo.java create mode 100644 Java-EE/src/main/java/enumeration/demo1/Gender.java create mode 100644 Java-EE/src/main/java/enumeration/demo1/GenderDescription.java create mode 100644 Java-EE/src/main/java/enumeration/demo1/Operation.java create mode 100644 Java-EE/src/main/java/enumeration/demo1/WeekEnum.java create mode 100644 Java-EE/src/main/java/enumeration/demo1/WeekEnum02.java create mode 100644 Java-EE/src/main/java/enumeration/demo1/WeenEnum.java create mode 100644 Java-EE/src/main/java/enumeration/test/DemoTest01.java create mode 100644 Java-EE/src/main/java/enumeration/test/GenderTest.java create mode 100644 Java-EE/src/main/java/enumeration/test/OperationTest.java create mode 100644 Java-EE/src/main/java/foreach/ForInTest.java create mode 100644 Java-EE/src/main/java/generic/GenericDemo.java create mode 100644 Java-EE/src/main/java/generic/GenericDemo2.java create mode 100644 Java-EE/src/main/java/generic/GenericDemo3.java create mode 100644 Java-EE/src/main/java/generic/GenericDemo4.java create mode 100644 Java-EE/src/main/java/generic/GenericDemo5.java create mode 100644 Java-EE/src/main/java/generic/GenericDemo6.java create mode 100644 Java-EE/src/main/java/generic/GenericDemo7.java create mode 100644 Java-EE/src/main/java/generic/GenericDemo8.java create mode 100644 Java-EE/src/main/java/list/demo/ListDemo.java create mode 100644 Java-EE/src/main/java/list/test/ArrayListTest.java create mode 100644 Java-EE/src/main/java/list/test/ArrayListTest2.java create mode 100644 Java-EE/src/main/java/map/MapDemo.java create mode 100644 Java-EE/src/main/java/poi/ExportExcel.java create mode 100644 Java-EE/src/main/java/poi/ExportExcel02.java create mode 100644 Java-EE/src/main/java/poi/ExportExcel03.java create mode 100644 Java-EE/src/main/java/reflect/DemoTest01.java create mode 100644 Java-EE/src/main/java/reflect/Foo.java create mode 100644 Java-EE/src/main/java/reflect/Goo.java create mode 100644 Java-EE/src/main/java/reflect/demoTest.java create mode 100644 Java-EE/src/main/java/try_catch/Exception01.java create mode 100644 Java-EE/src/main/java/try_catch/Exception02.java create mode 100644 Java-EE/src/main/java/try_catch/Exception03.java create mode 100644 Java-EE/src/main/java/try_catch/Exception04.java create mode 100644 Java-EE/src/main/java/try_catch/TestException.java create mode 100644 Java-EE/src/main/java/try_catch/Try_Catch01.java create mode 100644 Java-EE/src/main/webapp/WEB-INF/web.xml create mode 100644 Java-EE/src/main/webapp/index.jsp diff --git a/Java-EE/.gitignore b/Java-EE/.gitignore new file mode 100644 index 0000000..6143e53 --- /dev/null +++ b/Java-EE/.gitignore @@ -0,0 +1,22 @@ +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* diff --git a/Java-EE/.idea/artifacts/ConnectionAll_war.xml b/Java-EE/.idea/artifacts/ConnectionAll_war.xml new file mode 100644 index 0000000..67f818d --- /dev/null +++ b/Java-EE/.idea/artifacts/ConnectionAll_war.xml @@ -0,0 +1,8 @@ + + + $PROJECT_DIR$/target + + + + + \ No newline at end of file diff --git a/Java-EE/.idea/artifacts/ConnectionAll_war_exploded.xml b/Java-EE/.idea/artifacts/ConnectionAll_war_exploded.xml new file mode 100644 index 0000000..7ddc7d8 --- /dev/null +++ b/Java-EE/.idea/artifacts/ConnectionAll_war_exploded.xml @@ -0,0 +1,22 @@ + + + $PROJECT_DIR$/target/ConnectionAll + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Java-EE/.idea/artifacts/Java_EE_war.xml b/Java-EE/.idea/artifacts/Java_EE_war.xml new file mode 100644 index 0000000..0231102 --- /dev/null +++ b/Java-EE/.idea/artifacts/Java_EE_war.xml @@ -0,0 +1,8 @@ + + + $PROJECT_DIR$/target + + + + + \ No newline at end of file diff --git a/Java-EE/.idea/artifacts/Java_EE_war_exploded.xml b/Java-EE/.idea/artifacts/Java_EE_war_exploded.xml new file mode 100644 index 0000000..fd70e32 --- /dev/null +++ b/Java-EE/.idea/artifacts/Java_EE_war_exploded.xml @@ -0,0 +1,29 @@ + + + $PROJECT_DIR$/target/ConnectionAll + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Java-EE/.idea/compiler.xml b/Java-EE/.idea/compiler.xml new file mode 100644 index 0000000..9634217 --- /dev/null +++ b/Java-EE/.idea/compiler.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Java-EE/.idea/encodings.xml b/Java-EE/.idea/encodings.xml new file mode 100644 index 0000000..b26911b --- /dev/null +++ b/Java-EE/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Java-EE/.idea/inspectionProfiles/Project_Default.xml b/Java-EE/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..6560a98 --- /dev/null +++ b/Java-EE/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,36 @@ + + + + \ No newline at end of file diff --git a/Java-EE/.idea/libraries/Maven__commons_codec_commons_codec_1_10.xml b/Java-EE/.idea/libraries/Maven__commons_codec_commons_codec_1_10.xml new file mode 100644 index 0000000..37c6865 --- /dev/null +++ b/Java-EE/.idea/libraries/Maven__commons_codec_commons_codec_1_10.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/Java-EE/.idea/libraries/Maven__commons_logging_commons_logging_1_1_1.xml b/Java-EE/.idea/libraries/Maven__commons_logging_commons_logging_1_1_1.xml new file mode 100644 index 0000000..96f9812 --- /dev/null +++ b/Java-EE/.idea/libraries/Maven__commons_logging_commons_logging_1_1_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/Java-EE/.idea/libraries/Maven__junit_junit_4_11.xml b/Java-EE/.idea/libraries/Maven__junit_junit_4_11.xml new file mode 100644 index 0000000..4ea279a --- /dev/null +++ b/Java-EE/.idea/libraries/Maven__junit_junit_4_11.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/Java-EE/.idea/libraries/Maven__log4j_log4j_1_2_17.xml b/Java-EE/.idea/libraries/Maven__log4j_log4j_1_2_17.xml new file mode 100644 index 0000000..abf1ff9 --- /dev/null +++ b/Java-EE/.idea/libraries/Maven__log4j_log4j_1_2_17.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/Java-EE/.idea/libraries/Maven__org_apache_commons_commons_collections4_4_1.xml b/Java-EE/.idea/libraries/Maven__org_apache_commons_commons_collections4_4_1.xml new file mode 100644 index 0000000..0ca0d26 --- /dev/null +++ b/Java-EE/.idea/libraries/Maven__org_apache_commons_commons_collections4_4_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/Java-EE/.idea/libraries/Maven__org_apache_poi_poi_3_16.xml b/Java-EE/.idea/libraries/Maven__org_apache_poi_poi_3_16.xml new file mode 100644 index 0000000..212364f --- /dev/null +++ b/Java-EE/.idea/libraries/Maven__org_apache_poi_poi_3_16.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/Java-EE/.idea/libraries/Maven__org_apiguardian_apiguardian_api_1_0_0.xml b/Java-EE/.idea/libraries/Maven__org_apiguardian_apiguardian_api_1_0_0.xml new file mode 100644 index 0000000..50d9fbc --- /dev/null +++ b/Java-EE/.idea/libraries/Maven__org_apiguardian_apiguardian_api_1_0_0.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/Java-EE/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml b/Java-EE/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml new file mode 100644 index 0000000..01cdb39 --- /dev/null +++ b/Java-EE/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/Java-EE/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_api_5_3_0_M1.xml b/Java-EE/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_api_5_3_0_M1.xml new file mode 100644 index 0000000..d743bcf --- /dev/null +++ b/Java-EE/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_api_5_3_0_M1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/Java-EE/.idea/libraries/Maven__org_junit_platform_junit_platform_commons_1_3_0_M1.xml b/Java-EE/.idea/libraries/Maven__org_junit_platform_junit_platform_commons_1_3_0_M1.xml new file mode 100644 index 0000000..c5f5920 --- /dev/null +++ b/Java-EE/.idea/libraries/Maven__org_junit_platform_junit_platform_commons_1_3_0_M1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/Java-EE/.idea/libraries/Maven__org_opentest4j_opentest4j_1_1_0.xml b/Java-EE/.idea/libraries/Maven__org_opentest4j_opentest4j_1_1_0.xml new file mode 100644 index 0000000..9e9352a --- /dev/null +++ b/Java-EE/.idea/libraries/Maven__org_opentest4j_opentest4j_1_1_0.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/Java-EE/.idea/misc.xml b/Java-EE/.idea/misc.xml new file mode 100644 index 0000000..6409283 --- /dev/null +++ b/Java-EE/.idea/misc.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/Java-EE/.idea/modules.xml b/Java-EE/.idea/modules.xml new file mode 100644 index 0000000..eeb65d8 --- /dev/null +++ b/Java-EE/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Java-EE/.idea/uiDesigner.xml b/Java-EE/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/Java-EE/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Java-EE/.idea/vcs.xml b/Java-EE/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/Java-EE/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Java-EE/Java EE.iml b/Java-EE/Java EE.iml new file mode 100644 index 0000000..4ef89c3 --- /dev/null +++ b/Java-EE/Java EE.iml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Java-EE/LICENSE b/Java-EE/LICENSE new file mode 100644 index 0000000..48d1fa3 --- /dev/null +++ b/Java-EE/LICENSE @@ -0,0 +1,191 @@ +Apache License +Version 2.0, January 2004 +http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + +"License" shall mean the terms and conditions for use, reproduction, and +distribution as defined by Sections 1 through 9 of this document. + +"Licensor" shall mean the copyright owner or entity authorized by the copyright +owner that is granting the License. + +"Legal Entity" shall mean the union of the acting entity and all other entities +that control, are controlled by, or are under common control with that entity. +For the purposes of this definition, "control" means (i) the power, direct or +indirect, to cause the direction or management of such entity, whether by +contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the +outstanding shares, or (iii) beneficial ownership of such entity. + +"You" (or "Your") shall mean an individual or Legal Entity exercising +permissions granted by this License. + +"Source" form shall mean the preferred form for making modifications, including +but not limited to software source code, documentation source, and configuration +files. + +"Object" form shall mean any form resulting from mechanical transformation or +translation of a Source form, including but not limited to compiled object code, +generated documentation, and conversions to other media types. + +"Work" shall mean the work of authorship, whether in Source or Object form, made +available under the License, as indicated by a copyright notice that is included +in or attached to the work (an example is provided in the Appendix below). + +"Derivative Works" shall mean any work, whether in Source or Object form, that +is based on (or derived from) the Work and for which the editorial revisions, +annotations, elaborations, or other modifications represent, as a whole, an +original work of authorship. For the purposes of this License, Derivative Works +shall not include works that remain separable from, or merely link (or bind by +name) to the interfaces of, the Work and Derivative Works thereof. + +"Contribution" shall mean any work of authorship, including the original version +of the Work and any modifications or additions to that Work or Derivative Works +thereof, that is intentionally submitted to Licensor for inclusion in the Work +by the copyright owner or by an individual or Legal Entity authorized to submit +on behalf of the copyright owner. For the purposes of this definition, +"submitted" means any form of electronic, verbal, or written communication sent +to the Licensor or its representatives, including but not limited to +communication on electronic mailing lists, source code control systems, and +issue tracking systems that are managed by, or on behalf of, the Licensor for +the purpose of discussing and improving the Work, but excluding communication +that is conspicuously marked or otherwise designated in writing by the copyright +owner as "Not a Contribution." + +"Contributor" shall mean Licensor and any individual or Legal Entity on behalf +of whom a Contribution has been received by Licensor and subsequently +incorporated within the Work. + +2. Grant of Copyright License. + +Subject to the terms and conditions of this License, each Contributor hereby +grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, +irrevocable copyright license to reproduce, prepare Derivative Works of, +publicly display, publicly perform, sublicense, and distribute the Work and such +Derivative Works in Source or Object form. + +3. Grant of Patent License. + +Subject to the terms and conditions of this License, each Contributor hereby +grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, +irrevocable (except as stated in this section) patent license to make, have +made, use, offer to sell, sell, import, and otherwise transfer the Work, where +such license applies only to those patent claims licensable by such Contributor +that are necessarily infringed by their Contribution(s) alone or by combination +of their Contribution(s) with the Work to which such Contribution(s) was +submitted. If You institute patent litigation against any entity (including a +cross-claim or counterclaim in a lawsuit) alleging that the Work or a +Contribution incorporated within the Work constitutes direct or contributory +patent infringement, then any patent licenses granted to You under this License +for that Work shall terminate as of the date such litigation is filed. + +4. Redistribution. + +You may reproduce and distribute copies of the Work or Derivative Works thereof +in any medium, with or without modifications, and in Source or Object form, +provided that You meet the following conditions: + +You must give any other recipients of the Work or Derivative Works a copy of +this License; and +You must cause any modified files to carry prominent notices stating that You +changed the files; and +You must retain, in the Source form of any Derivative Works that You distribute, +all copyright, patent, trademark, and attribution notices from the Source form +of the Work, excluding those notices that do not pertain to any part of the +Derivative Works; and +If the Work includes a "NOTICE" text file as part of its distribution, then any +Derivative Works that You distribute must include a readable copy of the +attribution notices contained within such NOTICE file, excluding those notices +that do not pertain to any part of the Derivative Works, in at least one of the +following places: within a NOTICE text file distributed as part of the +Derivative Works; within the Source form or documentation, if provided along +with the Derivative Works; or, within a display generated by the Derivative +Works, if and wherever such third-party notices normally appear. The contents of +the NOTICE file are for informational purposes only and do not modify the +License. You may add Your own attribution notices within Derivative Works that +You distribute, alongside or as an addendum to the NOTICE text from the Work, +provided that such additional attribution notices cannot be construed as +modifying the License. +You may add Your own copyright statement to Your modifications and may provide +additional or different license terms and conditions for use, reproduction, or +distribution of Your modifications, or for any such Derivative Works as a whole, +provided Your use, reproduction, and distribution of the Work otherwise complies +with the conditions stated in this License. + +5. Submission of Contributions. + +Unless You explicitly state otherwise, any Contribution intentionally submitted +for inclusion in the Work by You to the Licensor shall be under the terms and +conditions of this License, without any additional terms or conditions. +Notwithstanding the above, nothing herein shall supersede or modify the terms of +any separate license agreement you may have executed with Licensor regarding +such Contributions. + +6. Trademarks. + +This License does not grant permission to use the trade names, trademarks, +service marks, or product names of the Licensor, except as required for +reasonable and customary use in describing the origin of the Work and +reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. + +Unless required by applicable law or agreed to in writing, Licensor provides the +Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, +including, without limitation, any warranties or conditions of TITLE, +NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are +solely responsible for determining the appropriateness of using or +redistributing the Work and assume any risks associated with Your exercise of +permissions under this License. + +8. Limitation of Liability. + +In no event and under no legal theory, whether in tort (including negligence), +contract, or otherwise, unless required by applicable law (such as deliberate +and grossly negligent acts) or agreed to in writing, shall any Contributor be +liable to You for damages, including any direct, indirect, special, incidental, +or consequential damages of any character arising as a result of this License or +out of the use or inability to use the Work (including but not limited to +damages for loss of goodwill, work stoppage, computer failure or malfunction, or +any and all other commercial damages or losses), even if such Contributor has +been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. + +While redistributing the Work or Derivative Works thereof, You may choose to +offer, and charge a fee for, acceptance of support, warranty, indemnity, or +other liability obligations and/or rights consistent with this License. However, +in accepting such obligations, You may act only on Your own behalf and on Your +sole responsibility, not on behalf of any other Contributor, and only if You +agree to indemnify, defend, and hold each Contributor harmless for any liability +incurred by, or claims asserted against, such Contributor by reason of your +accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work + +To apply the Apache License to your work, attach the following boilerplate +notice, with the fields enclosed by brackets "{}" replaced with your own +identifying information. (Don't include the brackets!) The text should be +enclosed in the appropriate comment syntax for the file format. We also +recommend that a file or class name and description of purpose be included on +the same "printed page" as the copyright notice for easier identification within +third-party archives. + + Copyright 2018 Ecloss + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. \ No newline at end of file diff --git a/Java-EE/README.md b/Java-EE/README.md new file mode 100644 index 0000000..c80da58 --- /dev/null +++ b/Java-EE/README.md @@ -0,0 +1,37 @@ +# Java-EE + +#### 项目介绍 +用于java基础 + +#### 软件架构 +软件架构说明 + + +#### 安装教程 + +1. xxxx +2. xxxx +3. xxxx + +#### 使用说明 + +1. xxxx +2. xxxx +3. xxxx + +#### 参与贡献 + +1. Fork 本项目 +2. 新建 Feat_xxx 分支 +3. 提交代码 +4. 新建 Pull Request + + +#### 码云特技 + +1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md +2. 码云官方博客 [blog.gitee.com](https://blog.gitee.com) +3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解码云上的优秀开源项目 +4. [GVP](https://gitee.com/gvp) 全称是码云最有价值开源项目,是码云综合评定出的优秀开源项目 +5. 码云官方提供的使用手册 [http://git.mydoc.io/](http://git.mydoc.io/) +6. 码云封面人物是一档用来展示码云会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) \ No newline at end of file diff --git a/Java-EE/pom.xml b/Java-EE/pom.xml new file mode 100644 index 0000000..ed2ea9f --- /dev/null +++ b/Java-EE/pom.xml @@ -0,0 +1,96 @@ + + + + 4.0.0 + + com.XiaoBai + ConnectionAll + 1.0-SNAPSHOT + war + + ConnectionAll Maven Webapp + + http://www.example.com + + + UTF-8 + 1.7 + 1.7 + + + + + + junit + junit + 4.11 + + + + org.junit.jupiter + junit-jupiter-api + RELEASE + + + + + org.apache.poi + poi + 3.16 + + + + + commons-logging + commons-logging + 1.1.1 + + + + + log4j + log4j + 1.2.17 + + + + + + + ConnectionAll + + + + maven-clean-plugin + 3.0.0 + + + + maven-resources-plugin + 3.0.2 + + + maven-compiler-plugin + 3.7.0 + + + maven-surefire-plugin + 2.20.1 + + + maven-war-plugin + 3.2.0 + + + maven-install-plugin + 2.5.2 + + + maven-deploy-plugin + 2.8.2 + + + + + diff --git a/Java-EE/src/main/java/collection/demo/CollectionDemo.java b/Java-EE/src/main/java/collection/demo/CollectionDemo.java new file mode 100644 index 0000000..7acfe77 --- /dev/null +++ b/Java-EE/src/main/java/collection/demo/CollectionDemo.java @@ -0,0 +1,72 @@ +package collection.demo; + +import java.util.ArrayList; +import java.util.Collection; + +public class CollectionDemo { + + public static void main(String[] args) { + Collection coll = new ArrayList(); + methodDemo(coll); + System.out.println("---------------------------"); + methodAllDemo(); + } + + /** + * 演示Collection中的基本功能 + */ + public static void methodDemo(Collection coll) { + + // 1. 添加元素 返回boolean + coll.add("abc1"); + coll.add("abc2"); + coll.add("abc3"); + + // 2.删除元素 返回boolean + coll.remove("abc1"); + + // 3.清除所有的元素 void + coll.clear(); + + // 4.包含判断 + System.out.println("contains: " + coll.contains("abc1")); + + System.out.println(coll); + } + + /** + * 演示带All的方法 + */ + public static void methodAllDemo() { + + // 1.创建两个容器 + Collection c1 = new ArrayList(); + Collection c2 = new ArrayList(); + + // 2.添加元素 + c1.add("abc1"); + c1.add("abc2"); + c1.add("abc3"); + c1.add("abc4"); + + c2.add("abc2"); + c2.add("abc3"); + c2.add("abc5"); + + // 往c1中添加c2 + c1.addAll(c2); + + // 判断c1中是否包含c2中所有的元素 + boolean b = c1.containsAll(c2); + System.out.println("b = " + b); + + // 从c1中删除c2, 将c1中和c2相同的元素从c1删除 + c1.removeAll(c2); + System.out.println(c1); + + c1.retainAll(c2); + System.out.println(c1); + + } + +} diff --git a/Java-EE/src/main/java/domain/Person.java b/Java-EE/src/main/java/domain/Person.java new file mode 100644 index 0000000..8d54861 --- /dev/null +++ b/Java-EE/src/main/java/domain/Person.java @@ -0,0 +1,65 @@ +package domain; + +public class Person implements Comparable { + + private String name; + private Integer age; + + public Person() { + } + + public Person(String name, Integer age) { + this.name = name; + this.age = age; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Integer getAge() { + return age; + } + + public void setAge(Integer age) { + this.age = age; + } + + @Override + public int compareTo(Person o) { + int temp = this.getAge() - o.getAge(); + return temp == 0 ? this.getName().compareTo(o.getName()) :temp; + } + + @Override + public String toString() { + return "Person{" + + "name='" + name + '\'' + + ", age=" + age + + '}'; + } + + @Override + public int hashCode() { + final int NUMBER = 31; + return this.name.hashCode() + this.age*NUMBER; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!(obj instanceof Person)) { + throw new ClassCastException("类型不匹配"); + } + Person p = (Person)obj; + return this.name.equals(p.name) && this.age == p.age; + + + } +} diff --git a/Java-EE/src/main/java/domain/Student.java b/Java-EE/src/main/java/domain/Student.java new file mode 100644 index 0000000..d2ccf85 --- /dev/null +++ b/Java-EE/src/main/java/domain/Student.java @@ -0,0 +1,17 @@ +package domain; + +public class Student extends Person { + + public Student() { + super(); + } + + public Student(String name, Integer age) { + super(name, age); + } + + @Override + public String toString() { + return "Student [name=" + getName() + ". age=" + getAge() + "]"; + } +} diff --git a/Java-EE/src/main/java/domain/Tool1.java b/Java-EE/src/main/java/domain/Tool1.java new file mode 100644 index 0000000..0205556 --- /dev/null +++ b/Java-EE/src/main/java/domain/Tool1.java @@ -0,0 +1,14 @@ +package domain; + +public class Tool1 { + + private Student stu; + + public Student getStu() { + return stu; + } + + public void setStu(Student stu) { + this.stu = stu; + } +} diff --git a/Java-EE/src/main/java/domain/Tool2.java b/Java-EE/src/main/java/domain/Tool2.java new file mode 100644 index 0000000..1a0a409 --- /dev/null +++ b/Java-EE/src/main/java/domain/Tool2.java @@ -0,0 +1,14 @@ +package domain; + +public class Tool2 { + + private Object obj; + + public Object getObj() { + return obj; + } + + public void setObj(Object obj) { + this.obj = obj; + } +} diff --git a/Java-EE/src/main/java/domain/Util.java b/Java-EE/src/main/java/domain/Util.java new file mode 100644 index 0000000..52b1ca4 --- /dev/null +++ b/Java-EE/src/main/java/domain/Util.java @@ -0,0 +1,14 @@ +package domain; + +public class Util { + + private W obj; + + public W getObj() { + return obj; + } + + public void setObj(W obj) { + this.obj = obj; + } +} diff --git a/Java-EE/src/main/java/domain/Worker.java b/Java-EE/src/main/java/domain/Worker.java new file mode 100644 index 0000000..1f26cf4 --- /dev/null +++ b/Java-EE/src/main/java/domain/Worker.java @@ -0,0 +1,17 @@ +package domain; + +public class Worker extends Person { + + public Worker() { + super(); + } + + public Worker(String name, Integer age) { + super(name, age); + } + + @Override + public String toString() { + return "Worker [name=" + getName() + ". age=" + getAge() + "]"; + } +} diff --git a/Java-EE/src/main/java/enumeration/Day.java b/Java-EE/src/main/java/enumeration/Day.java new file mode 100644 index 0000000..f9bced1 --- /dev/null +++ b/Java-EE/src/main/java/enumeration/Day.java @@ -0,0 +1,8 @@ +package enumeration; + +public enum Day { + + MONDAY, TUESDAY, WEDNESDAY, + THURSDAY, FRIDAY, SATURDAY, SUNDAY + +} diff --git a/Java-EE/src/main/java/enumeration/DayDemo.java b/Java-EE/src/main/java/enumeration/DayDemo.java new file mode 100644 index 0000000..0962cef --- /dev/null +++ b/Java-EE/src/main/java/enumeration/DayDemo.java @@ -0,0 +1,20 @@ +package enumeration; + +public class DayDemo { + + public static final int MONDAY = 1; + + public static final int TUESDAY = 2; + + public static final int WEDNESDAY = 3; + + public static final int THURESDAY = 4; + + public static final int FRIDAY = 5; + + public static final int SATURDAY = 6; + + public static final int SUNDAY = 7; + + +} diff --git a/Java-EE/src/main/java/enumeration/EnumerationDemo.java b/Java-EE/src/main/java/enumeration/EnumerationDemo.java new file mode 100644 index 0000000..468682c --- /dev/null +++ b/Java-EE/src/main/java/enumeration/EnumerationDemo.java @@ -0,0 +1,29 @@ +package enumeration; + +import java.util.Iterator; +import java.util.Vector; + +public class EnumerationDemo { + + public static void main(String[] args) { + /** + * Enumeration: 枚举 + * 具备枚举取出方式的容器只有Vector + */ + Vector v = new Vector(); + v.add("abc1"); + v.add("abc2"); + v.add("abc3"); + + for (Iterator it = v.iterator(); it.hasNext(); ) { + System.out.println("iterator: " + it.next() ); + } + + // 获取高级for --> 无角标,仅为遍历 + for (Object obj : v) { + System.out.println("foreach: " + obj ); + } + + } + +} diff --git a/Java-EE/src/main/java/enumeration/demo/EnumDemo.java b/Java-EE/src/main/java/enumeration/demo/EnumDemo.java new file mode 100644 index 0000000..ae993ab --- /dev/null +++ b/Java-EE/src/main/java/enumeration/demo/EnumDemo.java @@ -0,0 +1,15 @@ +package enumeration.demo; + +import enumeration.Day; + +public class EnumDemo { + + public static void main(String[] args) { + + // 直接引用 + Day day = Day.FRIDAY; + //System.out.println(day3); + + } + +} diff --git a/Java-EE/src/main/java/enumeration/demo1/Gender.java b/Java-EE/src/main/java/enumeration/demo1/Gender.java new file mode 100644 index 0000000..b2ed8d7 --- /dev/null +++ b/Java-EE/src/main/java/enumeration/demo1/Gender.java @@ -0,0 +1,11 @@ +package enumeration.demo1; + +public enum Gender implements GenderDescription { + MALE, FEMALE; + + + @Override + public void info() { + System.out.println("这是一个用于定义性别的枚举类"); + } +} diff --git a/Java-EE/src/main/java/enumeration/demo1/GenderDescription.java b/Java-EE/src/main/java/enumeration/demo1/GenderDescription.java new file mode 100644 index 0000000..f0acd45 --- /dev/null +++ b/Java-EE/src/main/java/enumeration/demo1/GenderDescription.java @@ -0,0 +1,11 @@ +package enumeration.demo1; + + +/** + * Created by Ecloss on 2018/7/12 + */ +public interface GenderDescription { + + public void info(); + +} diff --git a/Java-EE/src/main/java/enumeration/demo1/Operation.java b/Java-EE/src/main/java/enumeration/demo1/Operation.java new file mode 100644 index 0000000..1f07edf --- /dev/null +++ b/Java-EE/src/main/java/enumeration/demo1/Operation.java @@ -0,0 +1,48 @@ +package enumeration.demo1; + +public enum Operation { + + + //用于执行加法运算 + PLUS { + @Override + public double calulate(double x, double y) { + return x + y; + } + }, + + //用于执行减法运算 + MINUS { + @Override + public double calulate(double x, double y) { + return x - y; + } + }, + + //用于执行乘法运算 + TIMES { + @Override + public double calulate(double x, double y) { + return x * y; + } + }, + + //用于执行除法运算 + DIVIDE { + @Override + public double calulate(double x, double y) { + return x / y; + } + }; + + /** + * 为枚举类定义一个抽象方法,枚举类中所有的枚举值都必须实现这个方法 + * + * @param x + * @param y + * @return + */ + public abstract double calulate(double x, double y); + + +} diff --git a/Java-EE/src/main/java/enumeration/demo1/WeekEnum.java b/Java-EE/src/main/java/enumeration/demo1/WeekEnum.java new file mode 100644 index 0000000..58b84ce --- /dev/null +++ b/Java-EE/src/main/java/enumeration/demo1/WeekEnum.java @@ -0,0 +1,34 @@ +package enumeration.demo1; + +public enum WeekEnum { + + // 在第一行显式地列出7个枚举实例(枚举值),系统会自动添加public static final修饰 + SUNDAY("星期日"), MONDAY("星期一"), TUESDAY("星期二"), WEDNESDAY("星期三"), + THURSDAY("星期四"), FRIDAY("星期五"), SATURDAY("星期六"); + + // 定义一个private修饰的实例变量 + private String date; + + WeekEnum(String date) { + this.date = date; + } + + public String getDate() { + return date; + } + + public void setDate(String date) { + this.date = date; + } + + /** + * 重写toString方法 + * @return + */ + @Override + public String toString() { + return "WeekEnum{" + + "date='" + date + '\'' + + '}'; + } +} diff --git a/Java-EE/src/main/java/enumeration/demo1/WeekEnum02.java b/Java-EE/src/main/java/enumeration/demo1/WeekEnum02.java new file mode 100644 index 0000000..76bf3f8 --- /dev/null +++ b/Java-EE/src/main/java/enumeration/demo1/WeekEnum02.java @@ -0,0 +1,27 @@ +package enumeration.demo1; + +public enum WeekEnum02 { + SUNDAY("星期天", 1), + MONDAY("星期一", 2), + TUESDAY("星期二", 3), + WEDNESDAY("星期三",4), + THURESDAY("星期四", 5), + FRIDAY("星期五", 6), + SATURDAY("星期六", 7); + + private String content; + private Integer value; + + WeekEnum02(String content, Integer value) { + this.content = content; + this.value = value; + } + + public String getContent() { + return content; + } + + public Integer getValue() { + return value; + } +} diff --git a/Java-EE/src/main/java/enumeration/demo1/WeenEnum.java b/Java-EE/src/main/java/enumeration/demo1/WeenEnum.java new file mode 100644 index 0000000..5c62ed0 --- /dev/null +++ b/Java-EE/src/main/java/enumeration/demo1/WeenEnum.java @@ -0,0 +1,8 @@ +package enumeration.demo1; + +public enum WeenEnum { + + // 在第一行显式地列出7个枚举实例(枚举值),系统会自动添加public static final修饰 + SUNDAY, MONDAY, TUEDAY, WENNESDAY, THURSDAY, FIRDAY, SATURDAY; + +} diff --git a/Java-EE/src/main/java/enumeration/test/DemoTest01.java b/Java-EE/src/main/java/enumeration/test/DemoTest01.java new file mode 100644 index 0000000..3b7dfec --- /dev/null +++ b/Java-EE/src/main/java/enumeration/test/DemoTest01.java @@ -0,0 +1,108 @@ +package enumeration.test; + +import enumeration.demo1.WeekEnum; +import enumeration.demo1.WeekEnum02; +import enumeration.demo1.WeenEnum; +import org.junit.jupiter.api.Test; + +public class DemoTest01 { + + @Test + public void test01() { + WeenEnum str = WeenEnum.THURSDAY; + System.out.println(str); + } + + /** + * 1.int compareTo(E o): A.compateTo(E o)该方法用于与制定枚举对象比较顺序, + * 同一个枚举实例只能与相同类型的枚举实例比较。 + * A位于o之后:如果该枚举对象位于指定枚举对象之后,则返回正整数; + * A位于o之前:反之返回负整数; + * 否则返回零; + */ + @Test + public void test02() { + // 星期五在 周六之前 : 返回-1 + System.out.println(WeekEnum.FRIDAY.compareTo(WeekEnum.SATURDAY)); + // 周五在 周四之后: 返回+1 + System.out.println(WeekEnum.FRIDAY.compareTo(WeekEnum.MONDAY)); + // + System.out.println(WeekEnum.FRIDAY.compareTo(WeekEnum.FRIDAY)); + } + + /** + * String name(); 返回此枚举实例的名称,即枚举值; + */ + /** + * static values(); 返回一个包含全部枚举值的数组,可以用来遍历所有枚举值 + */ + @Test + public void test03( ){ + for (WeekEnum we : WeekEnum.values()){ + System.out.println(we); + } + } + + /** + * toString();方法 + */ + @Test + public void test05( ){ + for (WeekEnum we : WeekEnum.values()){ + System.out.println(we); + } + } + + /** + * WeekEnum02的方法 + */ + @Test + public void test08( ) { + for (WeekEnum02 we2 : WeekEnum02.values()) { + System.out.println(we2.getContent() + " " + we2.getValue()); + } + } + + @Test + public void test09( ) { + for (WeekEnum02 we2 : WeekEnum02.values()) { + System.out.println(we2.ordinal()); + } + } + + @Test + public void test10( ) { + for (WeekEnum02 we2 : WeekEnum02.values()) { + System.out.println(WeekEnum02.valueOf(WeekEnum02.class, we2.name())); + } + } + + /** + * int ordinal(); 返回枚举值在枚举类中的索引值,从0开始, + * 即枚举值在枚举声明中的顺序,这个顺序根据枚举值生命的顺序而定 + */ + @Test + public void test04( ) { + for (WeekEnum we : WeekEnum.values()) { + System.out.println(we.ordinal()); + } + } + + /** + * static valueOf(); + * 返回带指定名称的指定枚举类型的枚举常量, + * 名称必须与在此类型中声明枚举常亮所用的标识符完全匹配(不允许使用二外的空白字符), + * 这个方法与toString相对呀,因此重写toString()方法,一定要重写valueOf()方法 + * 我们可以自己重写toString()方法,单不能自己重写valueOf()方法,当我们重写toString方法时 + * valueOf()方法会自动重写,不用我们理会 + */ + @Test + public static void test07( ){ + System.out.println(WeekEnum.valueOf(WeekEnum.class, "MONDAY")); + System.out.println(WeekEnum.valueOf(WeekEnum.class, "FRIDAY")); + System.out.println(WeekEnum.valueOf(WeekEnum.class, "SUNDAY")); + + } + + +} diff --git a/Java-EE/src/main/java/enumeration/test/GenderTest.java b/Java-EE/src/main/java/enumeration/test/GenderTest.java new file mode 100644 index 0000000..27ab700 --- /dev/null +++ b/Java-EE/src/main/java/enumeration/test/GenderTest.java @@ -0,0 +1,18 @@ +package enumeration.test; + +import enumeration.demo1.Gender; +import org.junit.jupiter.api.Test; + +/** + * @author Elcoss + * @date 2018/7/12 + */ +public class GenderTest { + + @Test + public void test01( ){ + Gender.MALE.info(); + Gender.FEMALE.info(); + } + +} diff --git a/Java-EE/src/main/java/enumeration/test/OperationTest.java b/Java-EE/src/main/java/enumeration/test/OperationTest.java new file mode 100644 index 0000000..7dee06f --- /dev/null +++ b/Java-EE/src/main/java/enumeration/test/OperationTest.java @@ -0,0 +1,16 @@ +package enumeration.test; + +import enumeration.demo1.Operation; +import org.junit.jupiter.api.Test; + +public class OperationTest { + + @Test + public void test01() { + System.out.println("6 + 2 = " + Operation.PLUS.calulate(6, 2)); + System.out.println("6 - 2 = " + Operation.MINUS.calulate(6, 2)); + System.out.println("6 * 2 = " + Operation.TIMES.calulate(6, 2)); + System.out.println("6 / 2 = " + Operation.DIVIDE.calulate(6, 2)); + } + +} diff --git a/Java-EE/src/main/java/foreach/ForInTest.java b/Java-EE/src/main/java/foreach/ForInTest.java new file mode 100644 index 0000000..1ecd755 --- /dev/null +++ b/Java-EE/src/main/java/foreach/ForInTest.java @@ -0,0 +1,52 @@ +package foreach; + +import org.junit.jupiter.api.Test; + +import java.util.Iterator; + +public class ForInTest { + + @Test + public void demo001() { + // Car 用于forin语句的 + } + + //class Car implements Iterator { + // String[] names = {"保时捷", "宝马", "奥迪", "桑塔纳", "大众" }; + // + // @Override + // public Iterator iterator() { + // // 自定义迭代器 + // return new MyIterator(); + // } + // + // class MyIterator implements Iterator { + // + // int index = 0; + // + // @Override + // public boolean hasNext() { + // if (index >= names.length) { + // return false; + // } + // return true; + // } + // + // @Override + // public String next() { + // String name = names[index]; + // index++; + // return name; + // } + // + // @Override + // public void remove() { + // + // } + // + // } + // + //} + + +} diff --git a/Java-EE/src/main/java/generic/GenericDemo.java b/Java-EE/src/main/java/generic/GenericDemo.java new file mode 100644 index 0000000..103fe5d --- /dev/null +++ b/Java-EE/src/main/java/generic/GenericDemo.java @@ -0,0 +1,39 @@ +package generic; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +public class GenericDemo { + + public static void main(String[] args) { + + List list = new ArrayList(); + + list.add("abc"); + list.add(4); + + for (Iterator it = list.iterator(); it.hasNext(); ) { + + System.out.println(it.next()); + // 等价于: + Object obj = it.next(); + System.out.println(obj.toString()); + + String str = (String)it.next(); + System.out.println(str.length()); + // ->java.lang.ClassCastException + } + + // 为了在运行时期不出现类型异常,可以在定义容器时,就明确容器中的元素的类型 + + List list1 = new ArrayList(); + list1.add("abc"); + for (Iterator it = list1.iterator(); it.hasNext(); ) { + String str = it.next(); + System.out.println(str.length()); + } + + } + +} diff --git a/Java-EE/src/main/java/generic/GenericDemo2.java b/Java-EE/src/main/java/generic/GenericDemo2.java new file mode 100644 index 0000000..b430e5c --- /dev/null +++ b/Java-EE/src/main/java/generic/GenericDemo2.java @@ -0,0 +1,26 @@ +package generic; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +public class GenericDemo2 { + + public static void main(String[] args) { + + // 创建一个List集合,存储整数 , List ArrayList + List list = new ArrayList(); + + list.add(5); + list.add(6); + + for (Iterator it = list.iterator(); it.hasNext(); ) { + + Integer integer = it.next(); + System.out.println(integer); + + } + + } + +} diff --git a/Java-EE/src/main/java/generic/GenericDemo3.java b/Java-EE/src/main/java/generic/GenericDemo3.java new file mode 100644 index 0000000..c7c144b --- /dev/null +++ b/Java-EE/src/main/java/generic/GenericDemo3.java @@ -0,0 +1,52 @@ +package generic; + +import domain.Person; + +import java.util.HashSet; +import java.util.Set; +import java.util.TreeSet; + +public class GenericDemo3 { + + public static void main(String[] args) { + + Set set = new TreeSet(); + + set.add("abcd"); + set.add("aa"); + set.add("nba"); + set.add("cba"); + + for (String s : set) { + System.out.println(s); + } + + // 按照年龄排序 + Set set1 = new TreeSet(); + set1.add(new Person("abcd", 20)); + set1.add(new Person("aa", 25)); + set1.add(new Person("nba", 11)); + set1.add(new Person("cba", 60)); + + for (Person p : set1) { + System.out.println(p); + } + + System.out.println("------------------"); + + // HashSet不重复的实现 + Set set2 = new HashSet(); + set2.add(new Person("aa", 26)); + set2.add(new Person("abcd", 20)); + set2.add(new Person("abcd", 20)); + set2.add(new Person("nba", 22)); + set2.add(new Person("nba", 22)); + set2.add(new Person("cba", 24)); + + for (Person p : set2) { + System.out.println(p); + } + + } + +} diff --git a/Java-EE/src/main/java/generic/GenericDemo4.java b/Java-EE/src/main/java/generic/GenericDemo4.java new file mode 100644 index 0000000..e28d572 --- /dev/null +++ b/Java-EE/src/main/java/generic/GenericDemo4.java @@ -0,0 +1,30 @@ +package generic; + +import domain.Student; +import domain.Tool2; +import domain.Util; +import domain.Worker; + +public class GenericDemo4 { + + public static void main(String[] args) { + + /** + * 泛型1:泛型类--> 泛型定义在类上 + */ + + // JDK 1.4 + Tool2 tool2 = new Tool2(); + tool2.setObj(new Worker()); + Student student = (Student)tool2.getObj(); + //System.out.println(student); + + // JDK 1.5 + Util util = new Util(); + //util.setObj(new Worker()); + Student stu = util.getObj(); // 避免了向下转型,不用强制类型转换 + System.out.println(stu); + + } + +} diff --git a/Java-EE/src/main/java/generic/GenericDemo5.java b/Java-EE/src/main/java/generic/GenericDemo5.java new file mode 100644 index 0000000..981965d --- /dev/null +++ b/Java-EE/src/main/java/generic/GenericDemo5.java @@ -0,0 +1,50 @@ +package generic; + +public class GenericDemo5 { + + public static void main(String[] args) { + + /** + * 泛型2:泛型方法--> 泛型定义在方法上 + */ + //Demo1 d = new Demo1(); + //d.show("abc"); + ////d.print(6);在类上明确类型后,错误参数类型在编译时期就报错。 + //Demo1 d1 = new Demo1(); + //d1.print(6); + ////d1.show("abc"); + //System.out.println("----------------"); + // + //Demo2 d2 = new Demo2(); + //d2.show("abc"); + //d2.print("bcd"); + //d2.print(6); + + } + + class Demo1 { + + public void show(W w) { + System.out.println("show: " + w); + } + + public void print(W w) { + System.out.println("print: " + w); + } + } + + class Demo2 { + public void show(W w) { + System.out.println("show: " + w); + } + public void print(Q w) { + System.out.println("print: " + w); + } + + public void staticShow(A a) { + System.out.println("static show: " + a); + } + + } + +} diff --git a/Java-EE/src/main/java/generic/GenericDemo6.java b/Java-EE/src/main/java/generic/GenericDemo6.java new file mode 100644 index 0000000..c36f81f --- /dev/null +++ b/Java-EE/src/main/java/generic/GenericDemo6.java @@ -0,0 +1,30 @@ +package generic; + +public class GenericDemo6 { + + public static void main(String[] args) { + + /** + * 泛型3:泛型接口--> 泛型定义在接口上 + */ + SubDemo d = new SubDemo(); + d.show("abc"); + + } +} + +interface Inter { + public void show(T t); +} + +class InterImpl implements Inter { + + @Override + public void show(W w) { + System.out.println("show: " + w); + } +} + + class SubDemo extends InterImpl { + +} diff --git a/Java-EE/src/main/java/generic/GenericDemo7.java b/Java-EE/src/main/java/generic/GenericDemo7.java new file mode 100644 index 0000000..f54ea4f --- /dev/null +++ b/Java-EE/src/main/java/generic/GenericDemo7.java @@ -0,0 +1,41 @@ +package generic; + +import domain.Student; + +import java.util.*; + +public class GenericDemo7 { + + public static void main(String[] args) { + + /** + * 通配符<?> --> 相当于 + */ + List list = new ArrayList(); + list.add("abc1"); + list.add("abc2"); + list.add("abc3"); + printCollection(list); + + Set set = new HashSet(); + set.add("haha"); + set.add("xixi"); + set.add("hoho"); + printCollection(set); + + List list2 = new ArrayList(); + list2.add(new Student("abc1", 21)); + list2.add(new Student("abc2", 22)); + list2.add(new Student("abc3", 23)); + list2.add(new Student("abc4", 24)); + printCollection(list2); + } + + private static void printCollection(Collection coll) { + for (Iterator it = coll.iterator(); it.hasNext(); ) { + Object obj = it.next(); + System.out.println(obj); + } + } + +} diff --git a/Java-EE/src/main/java/generic/GenericDemo8.java b/Java-EE/src/main/java/generic/GenericDemo8.java new file mode 100644 index 0000000..5599cf8 --- /dev/null +++ b/Java-EE/src/main/java/generic/GenericDemo8.java @@ -0,0 +1,48 @@ +package generic; + +import domain.Person; +import domain.Student; +import domain.Worker; + +import java.util.*; + +public class GenericDemo8 { + + public static void main(String[] args) { + + /** + * 泛型的限定 + */ + List list = new ArrayList(); + list.add(new Student("abc1", 21)); + list.add(new Student("abc2", 22)); + list.add(new Student("abc3", 23)); + list.add(new Student("abc4", 24)); + printCollection(list); + + Set set = new HashSet(); + set.add(new Worker("haha", 23)); + set.add(new Worker("xixi", 24)); + set.add(new Worker("hoho", 21)); + set.add(new Worker("haha", 29)); + printCollection(set); + List list4 = new ArrayList<>(); + + List list5 = new ArrayList(); + List list6 = new ArrayList(); + } + + + /* + * 泛型的限定: + * ? extends E :接收E类型或者E的子类型。-->泛型上限。 + * ? super E :接收E类型或者E的父类型。-->泛型下限。 + */ + private static void printCollection(Collection coll) { + for (Iterator it = coll.iterator(); it.hasNext();) { + Person obj = it.next(); + System.out.println(obj.getName() + ":" + obj.getAge()); + } + } + +} diff --git a/Java-EE/src/main/java/list/demo/ListDemo.java b/Java-EE/src/main/java/list/demo/ListDemo.java new file mode 100644 index 0000000..29ffc56 --- /dev/null +++ b/Java-EE/src/main/java/list/demo/ListDemo.java @@ -0,0 +1,56 @@ +package list.demo; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +public class ListDemo { + + public static void main(String[] args) { + List list = new ArrayList(); + methodDemo(list); + } + + /** + * 演示list特有的方法 + */ + public static void methodDemo(List list) { + + // 1. 常规添加元素 + list.add("abc1"); + list.add("abc2"); + list.add("abc3"); + System.out.println(list); + + // 2. 插入元素 + list.add(1, "hehe"); + System.out.println(list); + + // 3. 删除 + list.remove(1); + list.remove("abc3"); + System.out.println(list); + + // 4.获取 + System.out.println(list.get(1)); + System.out.println(list.get(0)); + System.out.println(list.indexOf("abc3")); + + // 5. 修改 + list.set(1, "keke"); + + System.out.println(list); + + // 6.取出集合中所有的元素 Iterator + for (Iterator it = list.iterator(); it.hasNext(); ) { + System.out.println("iterator = " + it.next()); + } + + // 7.用list遍历 + for (int i = 0; i < list.size(); i++) { + System.out.println("get: " + list.get(i)); + } + + } + +} diff --git a/Java-EE/src/main/java/list/test/ArrayListTest.java b/Java-EE/src/main/java/list/test/ArrayListTest.java new file mode 100644 index 0000000..678479d --- /dev/null +++ b/Java-EE/src/main/java/list/test/ArrayListTest.java @@ -0,0 +1,36 @@ +package list.test; + + +import domain.Person; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +public class ArrayListTest { + + public static void main(String[] args) { + + // 1. 创建ArrayList集合对象 + List list = new ArrayList(); + + // 2. 添加Person类型的对象 + Person p1 = new Person("list1", 21); + Person p2 = new Person("list2", 22); + + list.add(p1); + list.add(p2); + list.add(new Person("list2", 23)); + + // 3.添加元素 + for (Iterator it = list.iterator(); it.hasNext(); ) { + + // it.next()都是Object类型的,所以转换为具体的对象时,需要向下转型 + Person p = (Person) it.next(); + System.out.println(p.getName() + ":" + p.getAge()); + + } + + } + +} diff --git a/Java-EE/src/main/java/list/test/ArrayListTest2.java b/Java-EE/src/main/java/list/test/ArrayListTest2.java new file mode 100644 index 0000000..ea4d16c --- /dev/null +++ b/Java-EE/src/main/java/list/test/ArrayListTest2.java @@ -0,0 +1,39 @@ +package list.test; + +import java.util.ArrayList; +import java.util.List; + +public class ArrayListTest2 { + + public static void main(String[] args) { + + List list = new ArrayList(); + list.add("abc1"); + list.add("abc2"); + list.add("abc3"); + list.add("abc4"); + list.add("abc1"); + list.add("abc2"); + list.add("abc3"); + list.add("abc4"); + list.add("abc3"); + list.add("abc6"); + + System.out.println(list); + System.out.println("-------------------"); + singleElement(list); + System.out.println(list); + + } + + public static void singleElement(List list) { + for (int i = 0; i < list.size()-1; i++) { + for (int j = i+1; j < list.size(); j++) { + if (list.get(i).equals(list.get(j))) { + list.remove(j--); + } + } + } + } + +} diff --git a/Java-EE/src/main/java/map/MapDemo.java b/Java-EE/src/main/java/map/MapDemo.java new file mode 100644 index 0000000..7297a2e --- /dev/null +++ b/Java-EE/src/main/java/map/MapDemo.java @@ -0,0 +1,35 @@ +package map; + +import java.util.HashMap; +import java.util.Map; + +public class MapDemo { + + public static void main(String[] args) { + + /** + * 需求:Map集合中存储学号,姓名 + */ + Map map = new HashMap(); + methodDemo(map); + } + + public static void methodDemo(Map map) { + + //1. 存储键值对。如果键相同,会出现覆盖 + System.out.println(map.put(3, "XiaoBai")); + System.out.println(map.put(3, "erhu")); + map.put(7, "HaoCai"); + map.put(2, "55555"); + + // 2. 移除remove ----> 会改变长度 + System.out.println(map.remove(7)); + + //3. 获取 + System.out.println(map.get(7)); + + System.out.println(map); + + } + +} diff --git a/Java-EE/src/main/java/poi/ExportExcel.java b/Java-EE/src/main/java/poi/ExportExcel.java new file mode 100644 index 0000000..54793fa --- /dev/null +++ b/Java-EE/src/main/java/poi/ExportExcel.java @@ -0,0 +1,63 @@ +package poi; + +import org.apache.poi.hssf.usermodel.HSSFCell; +import org.apache.poi.hssf.usermodel.HSSFRow; +import org.apache.poi.hssf.usermodel.HSSFSheet; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.ss.util.CellRangeAddress; + +import javax.xml.ws.Response; +import java.io.OutputStream; + +/** + * Created By Ecloss on 2018/7/12 + * 导数据导出表结构 + */ + +public class ExportExcel { + + public static void main(String[] args) { + + +//创建HSSFWorkbook对象(excel的文档对象) + HSSFWorkbook wb = new HSSFWorkbook(); +//建立新的sheet对象(excel的表单) + HSSFSheet sheet=wb.createSheet("成绩表"); +//在sheet里创建第一行,参数为行索引(excel的行),可以是0~65535之间的任何一个 + HSSFRow row1=sheet.createRow(0); +//创建单元格(excel的单元格,参数为列索引,可以是0~255之间的任何一个 + HSSFCell cell=row1.createCell(0); + //设置单元格内容 + cell.setCellValue("学员考试成绩一览表"); +//合并单元格CellRangeAddress构造参数依次表示起始行,截至行,起始列, 截至列 + sheet.addMergedRegion(new CellRangeAddress(0,0,0,3)); +//在sheet里创建第二行 + HSSFRow row2=sheet.createRow(1); + //创建单元格并设置单元格内容 + row2.createCell(0).setCellValue("姓名"); + row2.createCell(1).setCellValue("班级"); + row2.createCell(2).setCellValue("笔试成绩"); + row2.createCell(3).setCellValue("机试成绩"); + //在sheet里创建第三行 + HSSFRow row3=sheet.createRow(2); + row3.createCell(0).setCellValue("李明"); + row3.createCell(1).setCellValue("As178"); + row3.createCell(2).setCellValue(87); + row3.createCell(3).setCellValue(78); + //.....省略部分代码 + + +//输出Excel文件 +// Response response = new Response() { +// } +// OutputStream output=response.getOutputStream(); +// response.reset(); +// response.setHeader("Content-disposition", "attachment; filename=details.xls"); +// response.setContentType("application/msexcel"); +// wb.write(output); +// output.close(); +// retrun null; + + } + +} diff --git a/Java-EE/src/main/java/poi/ExportExcel02.java b/Java-EE/src/main/java/poi/ExportExcel02.java new file mode 100644 index 0000000..7919d6f --- /dev/null +++ b/Java-EE/src/main/java/poi/ExportExcel02.java @@ -0,0 +1,46 @@ +package poi; + +import org.apache.poi.hssf.usermodel.HSSFCell; +import org.apache.poi.hssf.usermodel.HSSFRow; +import org.apache.poi.hssf.usermodel.HSSFSheet; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.ss.util.CellRangeAddress; + +import java.io.FileNotFoundException; +import java.io.FileOutputStream; + +/** + * Created by Ecloss on 2018/7/12 + * 用程序的方法来导出数据 + */ +public class ExportExcel02 { + + public static void main(String[] args) { + + // web对象 + HSSFWorkbook wb = new HSSFWorkbook(); + // 创建表头等 + HSSFSheet sheet = wb.createSheet("test1"); + // 创建行 + HSSFRow row = sheet.createRow(1); + + // 创建列 + HSSFCell cell = row.createCell(0); + + HSSFCell cell2 = row.createCell(2); + cell.setCellValue("嗯哼"); + cell2.setCellValue("我是要写入的值"); + sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 3)); + + try { + FileOutputStream output = new FileOutputStream("F:\\xiaobai1.xlsx"); + wb.write(output); + output.flush(); + System.out.println("成功创建Excel文件"); + } catch (Exception e) { + e.printStackTrace(); + } + + } + +} diff --git a/Java-EE/src/main/java/poi/ExportExcel03.java b/Java-EE/src/main/java/poi/ExportExcel03.java new file mode 100644 index 0000000..6789cbd --- /dev/null +++ b/Java-EE/src/main/java/poi/ExportExcel03.java @@ -0,0 +1,45 @@ +package poi; + +import org.apache.poi.hssf.usermodel.HSSFSheet; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; + +public class ExportExcel03 { + + + //public void exportInfo(){ + // try { + // + // String myId = getRequest().getParameter("myId"); + // + // MyOrder my = endOrderService.getMyOrderMyId(myId); //订单信息 + // List mylist = endOrderService.getOrderInfos(myId); //订单产品详情 + // if(my!=null || mylist!=null){ + // //web对象 + // HSSFWorkbook wb = new HSSFWorkbook(); + // + // //创建表头等 + // HSSFSheet sheet = wb.createSheet(my.getOrder_title()); + // //省略省略/.... + // + // //以下是关键 + // HttpServletResponse response = ServletActionContext.getResponse(); + // response.reset(); + // OutputStream output = getRepsonse().getOutputStream(); + // response.setHeader("Content-disposition", "attachment; filename=Info.xls"); + // response.setContentType("application/msexcel"); + // wb.write(output); + // output.close(); + // System.out.println("成功创建excel文件"); + // } + // }catch (Exception e) { + // e.printStackTrace(); + // } + + + public static void main(String[] args) { + + + + } + +} diff --git a/Java-EE/src/main/java/reflect/DemoTest01.java b/Java-EE/src/main/java/reflect/DemoTest01.java new file mode 100644 index 0000000..061df69 --- /dev/null +++ b/Java-EE/src/main/java/reflect/DemoTest01.java @@ -0,0 +1,40 @@ +package reflect; + +import org.junit.jupiter.api.Test; + +import java.lang.reflect.Method; +import java.util.Scanner; + +public class DemoTest01 { + /** + * 业务需求,执行某个类中全部的以test + * 为开头的无参数无返回的非静态方法 + * @param args + */ + + public static void main(String[] args) { + try { + Scanner in = new Scanner(System.in); + System.out.println("请输入类名"); + String className = in.nextLine(); + // 获取动态类 + Class cls = Class.forName(className); + // 创建动态对象 + Object obj = cls.newInstance(); + // 获取动态方法 + Method[] mt = cls.getDeclaredMethods(); + Object obj1 = ""; + for (Method method : mt) { + if (method.getName().startsWith("test")) { + System.out.println(method); + method.invoke(obj); + } + + } + } catch (Exception e) { + e.printStackTrace(); + } + + } + +} diff --git a/Java-EE/src/main/java/reflect/Foo.java b/Java-EE/src/main/java/reflect/Foo.java new file mode 100644 index 0000000..8db26fe --- /dev/null +++ b/Java-EE/src/main/java/reflect/Foo.java @@ -0,0 +1,18 @@ +package reflect; + +public class Foo { + + public void testHi() { + System.out.println("Hi"); + } + + /** + * + * @param x + * @param y + */ + public void bu(int x, int y) { + System.out.println(x + y); + } + +} diff --git a/Java-EE/src/main/java/reflect/Goo.java b/Java-EE/src/main/java/reflect/Goo.java new file mode 100644 index 0000000..c34b68a --- /dev/null +++ b/Java-EE/src/main/java/reflect/Goo.java @@ -0,0 +1,4 @@ +package reflect; + +public class Goo { +} diff --git a/Java-EE/src/main/java/reflect/demoTest.java b/Java-EE/src/main/java/reflect/demoTest.java new file mode 100644 index 0000000..820a92d --- /dev/null +++ b/Java-EE/src/main/java/reflect/demoTest.java @@ -0,0 +1,56 @@ +package reflect; + +import org.apache.poi.util.SystemOutLogger; +import org.junit.jupiter.api.Test; + +import java.lang.reflect.Method; +import java.util.Scanner; + +public class demoTest { + + /** + * 方法:Class.forName cls.newInstance cls.getDeclaredMethods + * @param args + * @throws Exception + */ + public static void main(String[] args) throws Exception { + Scanner in = new Scanner(System.in); + System.out.println("请输入类名"); + String className = in.nextLine(); + // 编译错误,是因为 出现ClassNotFoundException + // 动态加载类 + Class cls = Class.forName(className); + System.out.println(cls); + // 动态创建对象 + Object obj = cls.newInstance(); + System.out.println("动态创建对象: " + obj); + + //动态获取类的信息 + // 从cls代表的类信息中获取全部的方法信息 + Method[] ary = cls.getDeclaredMethods(); + for (Method method : ary) { + // 返回方法 + System.out.println(method); + // 返回方法名 + System.out.println(method.getName()); + // 返回 返回类型 + System.out.println(method.getReturnType()); + // 返回方法的注释 + System.out.println(method.getAnnotations()); + } + + } + + + + + @Test + public void test01( ) throws Exception { + Scanner inp = new Scanner(System.in); + System.out.println("请输入一个类名"); + String className = inp.nextLine(); + Class cls = Class.forName(className); + System.out.println(cls); + } + +} diff --git a/Java-EE/src/main/java/try_catch/Exception01.java b/Java-EE/src/main/java/try_catch/Exception01.java new file mode 100644 index 0000000..ff5042e --- /dev/null +++ b/Java-EE/src/main/java/try_catch/Exception01.java @@ -0,0 +1,17 @@ +package try_catch; + +public class Exception01 { + + public static void main(String[] args) { + + int a = 5, b = 0; + try { + int c = a / b; + System.out.println(c); + } catch (ArithmeticException e) { + System.out.println("除数不能为0,程序出现异常"); + } + + } + +} diff --git a/Java-EE/src/main/java/try_catch/Exception02.java b/Java-EE/src/main/java/try_catch/Exception02.java new file mode 100644 index 0000000..b16bf41 --- /dev/null +++ b/Java-EE/src/main/java/try_catch/Exception02.java @@ -0,0 +1,24 @@ +package try_catch; + +public class Exception02 { + + public static void main(String[] args) { + + int[] intArray = new int[3]; + int intArray1[] = new int[3]; + try { + for (int i = 0; i <= intArray.length; i++) { + intArray[i] = i; + System.out.println("intArray[" + i + "] = " + intArray[i]); + System.out.println("intArray[" + i + "] = " + (i-2) + "的值:" + intArray[i] % (i-2)); + } + } catch (ArrayIndexOutOfBoundsException e) { + System.out.println("intArray数组下表越界异常。"); + } catch (ArithmeticException e) { + System.out.println("除数为0异常。"); + } + System.out.println("程序正常结束"); + + } + +} diff --git a/Java-EE/src/main/java/try_catch/Exception03.java b/Java-EE/src/main/java/try_catch/Exception03.java new file mode 100644 index 0000000..b8dff9f --- /dev/null +++ b/Java-EE/src/main/java/try_catch/Exception03.java @@ -0,0 +1,24 @@ +package try_catch; + +import org.junit.jupiter.api.Test; + +public class Exception03 { + + @Test + public void test01( ) { + int i = 0; + String gerrting[] = {"Hello World !", "Hello World !!", "Hello World !!!"}; + while (i < 4) { + try { + System.out.println(gerrting[i++]); + } catch (ArrayIndexOutOfBoundsException e) { + System.out.println("数组下表越界异常"); + }catch (Exception e) { + System.out.println("Exception"); + }finally { + System.out.println("-----------------------"); + } + } + } + +} diff --git a/Java-EE/src/main/java/try_catch/Exception04.java b/Java-EE/src/main/java/try_catch/Exception04.java new file mode 100644 index 0000000..15c3631 --- /dev/null +++ b/Java-EE/src/main/java/try_catch/Exception04.java @@ -0,0 +1,81 @@ +package try_catch; + +import org.junit.jupiter.api.Test; + +import java.io.IOException; + +public class Exception04 { + + /** + * 合法 + * @throws IOException + */ + void method1( ) throws IOException{}; + + /** + * 编译错误,必须捕获或抛出IOException + */ + void method2( ) throws IOException { + method1(); + } + + /** + * 合法,声明抛出IOException + * @throws IOException + */ + void method3( ) throws IOException { + method1(); + } + + /** + * 合法,声明抛出Exception,IOException是Exception的子类 + * @throws Exception + */ + void method4( ) throws Exception{ + method1(); + } + + /** + * 合法,捕获IOException异常 + */ + @Test + void method5( ) { + try { + method1(); + } catch (IOException e) { + System.out.println("IOException"); + } catch (Exception e) { + System.out.println("Exception"); + } finally { + System.out.println("finally"); + } + } + + /** + * 编译错误,必须捕获或者声明抛出Exception + */ + void method6( ) throws IOException { + try { + method1(); + } catch (IOException e) { + throw new IOException(); + } + } + + void method7( ) throws Exception { + try { + method1(); + } catch (Exception e) { + throw new Exception(); + } + } + + void method8( ) throws Exception { + try { + method1(); + } catch (IOException e) { + throw new Exception(); + } + } + +} diff --git a/Java-EE/src/main/java/try_catch/TestException.java b/Java-EE/src/main/java/try_catch/TestException.java new file mode 100644 index 0000000..796a86f --- /dev/null +++ b/Java-EE/src/main/java/try_catch/TestException.java @@ -0,0 +1,45 @@ +package try_catch; + +public class TestException { + + static int quotient(int x, int y) throws MyException { + //定义方法抛出异常 + if (y < 0) { + throw new MyException("除数不能是负数"); + } + return x/y; + } + + public static void main(String[] args) { + + int a = 3; + int b = 1; + try { + int result = quotient(a, b); + System.out.println(result); + } catch (MyException e) { + System.out.println(e.getMessage()); + } catch (ArithmeticException e) { + System.out.println("除数不能为0"); + } catch (Exception e) { + System.out.println("程序发生了其它的异常"); + + } + //System.err(null); + System.exit(1); + } + +} + +class MyException extends Exception { + String message; //定义String类型变量 + public MyException(String ErrorMessgr) { + message = ErrorMessgr; + } + + // 覆盖getMessage( ) 方法 + @Override + public String getMessage() { + return message; + } +} diff --git a/Java-EE/src/main/java/try_catch/Try_Catch01.java b/Java-EE/src/main/java/try_catch/Try_Catch01.java new file mode 100644 index 0000000..13f6ea2 --- /dev/null +++ b/Java-EE/src/main/java/try_catch/Try_Catch01.java @@ -0,0 +1,79 @@ +package try_catch; + +public class Try_Catch01 { + + boolean testEx2( ) throws Exception { + boolean ret = true; + try { + int b = 12; + int c; + for (int i = 2; i >= -2; i--) { + //i为0时,抛出了异常,空指针异常 2 1 + c = b / i; + System.out.println("i=" + i); + } + return true; + } catch (Exception e) { + // testEx2, catch exception + System.out.println("testEx2, catch exception"); + ret = false; + throw e; + } finally { + // testEx2, finallyl return value=false + System.out.println("testEx2, finally; return value=" + ret); + return ret; + } + } + + boolean testEx1( ) throws Exception { + boolean ret = true; + try { + // 传来的值为false直接返回, 下面的语句就不在返回了 + ret = testEx2(); + if (!ret) { + return false; + } + System.out.println("testEx1, at the end of try"); + return ret; + } catch (Exception e) { + System.out.println("testEx1, catch exception"); + ret = false; + throw e; + } finally { + // 这里为什么会输出这段呢 + //ret = true; + System.out.println("testEx1, finally; return value=" + ret); + return ret; + } + } + + boolean testEx( ) throws Exception{ + boolean ret = true; + try { + // 直接返回false + ret = testEx1(); + } catch (Exception e) { + System.out.println("testEx, catch exception"); + ret = false; + throw e; + } finally { + //int c = 4 / 0; + System.exit(1); + // 最后输出:testEx, finally; return value=false + System.out.println("testEx, finally; return value=" + ret); + return ret; + } + } + + public static void main(String[] args) { + Try_Catch01 tc = new Try_Catch01(); + try { + System.out.println(tc.testEx()); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public Try_Catch01() { + } +} diff --git a/Java-EE/src/main/webapp/WEB-INF/web.xml b/Java-EE/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..9f88c1f --- /dev/null +++ b/Java-EE/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,7 @@ + + + + Archetype Created Web Application + diff --git a/Java-EE/src/main/webapp/index.jsp b/Java-EE/src/main/webapp/index.jsp new file mode 100644 index 0000000..c38169b --- /dev/null +++ b/Java-EE/src/main/webapp/index.jsp @@ -0,0 +1,5 @@ + + +

Hello World!

+ + -- Gitee