├── java-jmx ├── src │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── com │ │ │ └── heks │ │ │ └── jmx │ │ │ ├── DynamicMBean.java │ │ │ ├── HelloWorldMBean.java │ │ │ └── JmxApplication.java │ └── test │ │ └── java │ │ └── com │ │ └── heks │ │ └── jmx │ │ └── JmxApplicationTests.java ├── delombok │ └── src-bak │ │ └── src │ │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── com │ │ │ └── heks │ │ │ └── jmx │ │ │ ├── DynamicMBean.java │ │ │ ├── HelloWorldMBean.java │ │ │ └── JmxApplication.java │ │ └── test │ │ └── java │ │ └── com │ │ └── heks │ │ └── jmx │ │ └── JmxApplicationTests.java └── .gitignore ├── java-sysEnv ├── src │ └── main │ │ ├── resources │ │ └── application.properties │ │ └── java │ │ └── com │ │ └── heks │ │ └── jj │ │ └── JavaSysEnvApplication.java ├── delombok │ └── src-bak │ │ └── src │ │ └── main │ │ ├── resources │ │ └── application.properties │ │ └── java │ │ └── com │ │ └── heks │ │ └── jj │ │ └── JavaSysEnvApplication.java └── .gitignore ├── java-algorithms ├── src │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── com │ │ │ └── hks │ │ │ └── eightsortingalgorithms │ │ │ ├── leetcode │ │ │ ├── LRUCache.java │ │ │ ├── maxProfit.java │ │ │ ├── maxProfit2.java │ │ │ ├── myPow.java │ │ │ ├── firstUniqChar.java │ │ │ ├── mySqrt.java │ │ │ ├── maxSubArray.java │ │ │ ├── findPeakElement.java │ │ │ ├── minimumTotal.java │ │ │ ├── convertToTitle.java │ │ │ ├── findDuplicate.java │ │ │ ├── coinChange.java │ │ │ ├── longestCommonSubsequence.java │ │ │ ├── merge.java │ │ │ ├── getKthFromEnd.java │ │ │ ├── subsets.java │ │ │ ├── lengthOfLongestSubstring.java │ │ │ ├── sortColors.java │ │ │ ├── isValidSerialization.java │ │ │ ├── lengthOfLIS.java │ │ │ ├── maxDepth.java │ │ │ ├── getIntersectionNode.java │ │ │ ├── maxProduct.java │ │ │ ├── longestPalindrome.java │ │ │ ├── invertTree.java │ │ │ ├── generateParenthesis.java │ │ │ ├── minDistance.java │ │ │ ├── uniquePaths.java │ │ │ ├── rotate.java │ │ │ ├── DuplicateZeros.java │ │ │ ├── triangleNumber.java │ │ │ ├── hasPathSum.java │ │ │ ├── rotateMatrix.java │ │ │ ├── detectCycle.java │ │ │ ├── pruneTree.java │ │ │ ├── deleteDuplicates.java │ │ │ └── lowestCommonAncestor.java │ │ │ ├── nowcoder │ │ │ ├── TreeMax.java │ │ │ ├── StackHanoi.java │ │ │ ├── StackToQueue.java │ │ │ └── StackReverse.java │ │ │ ├── method │ │ │ ├── sort │ │ │ │ ├── MergeAlgorithms.java │ │ │ │ ├── QuickAlgorithms.java │ │ │ │ ├── ShellAlgorithms.java │ │ │ │ ├── BubbleAlgorithms.java │ │ │ │ ├── BucketAlgorithms.java │ │ │ │ ├── SelectAlgorithms.java │ │ │ │ ├── SelectHeapAlgorithms.java │ │ │ │ ├── StraightInsertAlgorithms.java │ │ │ │ └── impl │ │ │ │ │ ├── BubbleAlgorithmsImpl.java │ │ │ │ │ ├── StraightInsertAlgorithmsImpl.java │ │ │ │ │ └── SelectAlgorithmsImpl.java │ │ │ └── search │ │ │ │ ├── BinarySearch.java │ │ │ │ └── impl │ │ │ │ └── BinarySearchImpl.java │ │ │ ├── EightSortingAlgorithmsApplication.java │ │ │ └── controller │ │ │ └── sort │ │ │ └── ShellAlgorithmsController.java │ └── test │ │ └── java │ │ └── com │ │ └── hks │ │ └── eightsortingalgorithms │ │ └── EightSortingAlgorithmsApplicationTests.java ├── target │ ├── classes │ │ ├── application.properties │ │ └── com │ │ │ └── hks │ │ │ └── eightsortingalgorithms │ │ │ ├── config │ │ │ └── Swagger2.class │ │ │ ├── leetcode │ │ │ └── TwoSum.class │ │ │ ├── aspect │ │ │ └── MethodTimeAspect.class │ │ │ ├── method │ │ │ ├── search │ │ │ │ ├── BinarySearch.class │ │ │ │ └── impl │ │ │ │ │ └── BinarySearchImpl.class │ │ │ └── sort │ │ │ │ ├── MergeAlgorithms.class │ │ │ │ ├── QuickAlgorithms.class │ │ │ │ ├── ShellAlgorithms.class │ │ │ │ ├── BubbleAlgorithms.class │ │ │ │ ├── BucketAlgorithms.class │ │ │ │ ├── SelectAlgorithms.class │ │ │ │ ├── SelectHeapAlgorithms.class │ │ │ │ ├── StraightInsertAlgorithms.class │ │ │ │ └── impl │ │ │ │ ├── BubbleAlgorithmsImpl.class │ │ │ │ ├── BucketAlgorithmsImpl.class │ │ │ │ ├── MergeAlgorithmsImpl.class │ │ │ │ ├── QuickAlgorithmsImpl.class │ │ │ │ ├── SelectAlgorithmsImpl.class │ │ │ │ ├── ShellAlgorithmsImpl.class │ │ │ │ ├── SelectHeapAlgorithmsImpl.class │ │ │ │ └── StraightInsertAlgorithmsImpl.class │ │ │ ├── nowcoder │ │ │ ├── RebuildBinaryTree.class │ │ │ └── RebuildBinaryTree$TreeNode.class │ │ │ ├── EightSortingAlgorithmsApplication.class │ │ │ └── controller │ │ │ ├── search │ │ │ └── BinarySearchController.class │ │ │ └── sort │ │ │ ├── BubbleAlgorithmsController.class │ │ │ ├── BucketAlgorithmsController.class │ │ │ ├── MergeAlgorithmsController.class │ │ │ ├── QuickAlgorithmsController.class │ │ │ ├── SelectAlgorithmsController.class │ │ │ ├── ShellAlgorithmsController.class │ │ │ ├── SelectHeapAlgorithmsController.class │ │ │ └── StraightInsertAlgorithmsController.class │ └── test-classes │ │ └── com │ │ └── hks │ │ └── eightsortingalgorithms │ │ └── EightSortingAlgorithmsApplicationTests.class └── README.md ├── java-agent ├── .DS_Store ├── .gitignore ├── target │ ├── maven-status │ │ └── maven-compiler-plugin │ │ │ ├── testCompile │ │ │ └── default-testCompile │ │ │ │ ├── createdFiles.lst │ │ │ │ └── inputFiles.lst │ │ │ └── compile │ │ │ └── default-compile │ │ │ ├── inputFiles.lst │ │ │ └── createdFiles.lst │ ├── java-agent-1.0-SNAPSHOT.jar │ ├── maven-archiver │ │ └── pom.properties │ ├── classes │ │ └── META-INF │ │ │ └── MANIFEST.MF │ ├── java-agent-1.0-SNAPSHOT-jar-with-dependencies.jar │ └── surefire-reports │ │ └── TestJVM.txt ├── src │ ├── main │ │ └── resources │ │ │ └── META-INF │ │ │ └── MANIFEST.MF │ └── test │ │ └── java │ │ └── TestJVM.java ├── delombok │ └── src-bak │ │ └── src │ │ ├── main │ │ └── resources │ │ │ └── META-INF │ │ │ └── MANIFEST.MF │ │ └── test │ │ └── java │ │ └── TestJVM.java └── readme.md ├── java-network └── Cidr.class ├── java-8future ├── src │ └── test │ │ └── java │ │ ├── User.java │ │ └── FunctionTest.java └── delombok │ └── src-bak │ └── src │ └── test │ └── java │ ├── User.java │ └── FunctionTest.java ├── java-intercept ├── target │ └── classes │ │ └── com │ │ └── hks │ │ └── intercept │ │ ├── Client.class │ │ ├── ClientImp.class │ │ ├── InterceptTest.class │ │ ├── ForwardingClient.class │ │ ├── InterceptTest$1.class │ │ ├── InterceptTest$2.class │ │ └── ForwardingClientImpl.class ├── src │ └── main │ │ └── java │ │ └── com │ │ └── hks │ │ └── intercept │ │ ├── Client.java │ │ ├── ClientImp.java │ │ ├── ForwardingClient.java │ │ ├── ForwardingClientImpl.java │ │ └── InterceptTest.java ├── delombok │ └── src-bak │ │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── hks │ │ └── intercept │ │ ├── Client.java │ │ ├── ClientImp.java │ │ ├── ForwardingClient.java │ │ ├── ForwardingClientImpl.java │ │ └── InterceptTest.java └── pom.xml ├── java-jvmpre ├── src │ ├── main │ │ └── java │ │ │ └── som │ │ │ └── hks │ │ │ ├── stackAccess │ │ │ ├── Doer.java │ │ │ ├── Friend.java │ │ │ └── Stranger.java │ │ │ ├── oom │ │ │ ├── PutInEden.java │ │ │ ├── ReferenceTest.java │ │ │ ├── PutInEden2.java │ │ │ ├── BigObj2Old.java │ │ │ ├── EqualsOOMTest.java │ │ │ ├── MaxTenuringThreshold.java │ │ │ ├── GCTimeTest.java │ │ │ └── HeapSize.java │ │ │ ├── aceessControler │ │ │ ├── MySecurityManager.java │ │ │ ├── TestMySecurityManager.java │ │ │ └── MyFileInputStream.java │ │ │ └── securityManager │ │ │ ├── MySecurityManager.java │ │ │ └── TestMySecurityManager.java │ └── test │ │ └── java │ │ └── com │ │ └── hks │ │ ├── RuntimeConstantPoolOOM.java │ │ ├── HeapOOM.java │ │ ├── HeapAllocation.java │ │ ├── JavaVMStackSOF.java │ │ └── DirectMemoryOOM.java ├── delombok │ └── src-bak │ │ └── src │ │ ├── main │ │ └── java │ │ │ └── som │ │ │ └── hks │ │ │ ├── stackAccess │ │ │ ├── Doer.java │ │ │ ├── Friend.java │ │ │ └── Stranger.java │ │ │ ├── oom │ │ │ ├── PutInEden.java │ │ │ ├── ReferenceTest.java │ │ │ ├── PutInEden2.java │ │ │ ├── BigObj2Old.java │ │ │ ├── EqualsOOMTest.java │ │ │ ├── MaxTenuringThreshold.java │ │ │ ├── GCTimeTest.java │ │ │ └── HeapSize.java │ │ │ ├── securityManager │ │ │ ├── MySecurityManager.java │ │ │ └── TestMySecurityManager.java │ │ │ └── aceessControler │ │ │ ├── MySecurityManager.java │ │ │ ├── MyFileInputStream.java │ │ │ └── TestMySecurityManager.java │ │ └── test │ │ └── java │ │ └── com │ │ └── hks │ │ ├── RuntimeConstantPoolOOM.java │ │ ├── HeapOOM.java │ │ ├── HeapAllocation.java │ │ ├── JavaVMStackSOF.java │ │ └── DirectMemoryOOM.java └── pom.xml ├── java-proxy ├── src │ └── main │ │ └── java │ │ └── com │ │ └── hks │ │ └── proxy │ │ ├── UserService.java │ │ ├── UserServiceImpl.java │ │ ├── cglib │ │ ├── CglibProxyTest.java │ │ └── MyMethodInterceptor.java │ │ └── jdk │ │ └── JDKProxyTest.java ├── delombok │ └── src-bak │ │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── hks │ │ └── proxy │ │ ├── UserService.java │ │ ├── UserServiceImpl.java │ │ ├── cglib │ │ ├── CglibProxyTest.java │ │ └── MyMethodInterceptor.java │ │ └── jdk │ │ └── JDKProxyTest.java └── pom.xml ├── java-factory ├── src │ └── main │ │ └── java │ │ └── com │ │ └── hks │ │ └── factory │ │ ├── Food.java │ │ ├── Fish.java │ │ ├── Fruit.java │ │ ├── StaticFactoryClass.java │ │ ├── FoodFactoryTest.java │ │ └── FoodFactory.java └── delombok │ └── src-bak │ └── src │ └── main │ └── java │ └── com │ └── hks │ └── factory │ ├── Food.java │ ├── Fish.java │ ├── Fruit.java │ ├── StaticFactoryClass.java │ ├── FoodFactoryTest.java │ └── FoodFactory.java ├── java-object ├── src │ └── main │ │ └── java │ │ └── com │ │ └── hks │ │ ├── enumClass │ │ ├── Grade.java │ │ ├── AntStatus.java │ │ ├── Sample.java │ │ ├── Sample2.java │ │ ├── EnumMapSample.java │ │ └── Sample3.java │ │ ├── QiangZhiZhuanHuan.java │ │ ├── ZiDongLeiZhuan.java │ │ ├── builder │ │ └── BuilderTest.java │ │ ├── cloneClass │ │ ├── ReferenceCopy.java │ │ └── Person.java │ │ ├── serializable │ │ └── Employee.java │ │ ├── valuePass │ │ ├── Person.java │ │ ├── RefrencePassTest.java │ │ └── ValuePassTest.java │ │ ├── PrecisionDemo.java │ │ ├── staticClass │ │ └── ThisClass.java │ │ └── hashcode │ │ └── Person.java ├── delombok │ └── src-bak │ │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── hks │ │ ├── enumClass │ │ ├── Grade.java │ │ ├── AntStatus.java │ │ ├── Sample.java │ │ ├── Sample2.java │ │ ├── EnumMapSample.java │ │ └── Sample3.java │ │ ├── QiangZhiZhuanHuan.java │ │ ├── ZiDongLeiZhuan.java │ │ ├── builder │ │ └── BuilderTest.java │ │ ├── cloneClass │ │ ├── ReferenceCopy.java │ │ └── Person.java │ │ ├── serializable │ │ └── Employee.java │ │ ├── valuePass │ │ ├── Person.java │ │ ├── RefrencePassTest.java │ │ └── ValuePassTest.java │ │ ├── PrecisionDemo.java │ │ └── staticClass │ │ └── ThisClass.java └── pom.xml ├── java-classloader ├── src │ ├── main │ │ └── java │ │ │ └── com │ │ │ └── hks │ │ │ └── classLoader │ │ │ ├── ClassLoaderLeakExample.java │ │ │ ├── TestBeLoader.java │ │ │ └── TestClassLoaderDemo.java │ └── test │ │ └── java │ │ └── IntegerTest.java ├── delombok │ └── src-bak │ │ └── src │ │ ├── main │ │ └── java │ │ │ └── com │ │ │ └── hks │ │ │ └── classLoader │ │ │ ├── ClassLoaderLeakExample.java │ │ │ ├── TestBeLoader.java │ │ │ └── TestClassLoaderDemo.java │ │ └── test │ │ └── java │ │ └── IntegerTest.java └── pom.xml ├── java-lock ├── src │ └── main │ │ └── java │ │ └── com │ │ └── hks │ │ └── lock │ │ ├── Test.java │ │ ├── reentrant │ │ └── SynchronizedTest.java │ │ └── spinLock │ │ ├── SpinLock.java │ │ ├── SpinLockTest.java │ │ └── SpinLock1Test.java ├── delombok │ └── src-bak │ │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── hks │ │ └── lock │ │ ├── Test.java │ │ ├── reentrant │ │ └── SynchronizedTest.java │ │ └── spinLock │ │ ├── SpinLock.java │ │ ├── SpinLockTest.java │ │ └── SpinLock1Test.java └── pom.xml ├── java-annotation ├── src │ └── main │ │ └── java │ │ └── com │ │ └── hks │ │ └── annotation │ │ ├── FruitName.java │ │ ├── MyTest.java │ │ ├── NoDBColumn.java │ │ ├── Test.java │ │ ├── MyAnnotation.java │ │ ├── FruitColor.java │ │ ├── Greeting.java │ │ ├── FruitProvider.java │ │ ├── Apple.java │ │ └── Table.java ├── delombok │ └── src-bak │ │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── hks │ │ └── annotation │ │ ├── FruitName.java │ │ ├── MyTest.java │ │ ├── NoDBColumn.java │ │ ├── Test.java │ │ ├── MyAnnotation.java │ │ ├── FruitColor.java │ │ ├── Greeting.java │ │ ├── FruitProvider.java │ │ ├── Apple.java │ │ └── Table.java └── pom.xml ├── java-8stream ├── src │ └── main │ │ └── java │ │ └── com │ │ └── heks │ │ └── stream │ │ ├── ForEach.java │ │ ├── EvalFunction.java │ │ ├── NextItemEvalProcess.java │ │ └── Person.java ├── delombok │ └── src-bak │ │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── heks │ │ └── stream │ │ ├── ForEach.java │ │ ├── EvalFunction.java │ │ ├── NextItemEvalProcess.java │ │ └── Person.java └── pom.xml ├── java-aspect ├── src │ └── main │ │ └── java │ │ └── com │ │ └── hks │ │ ├── asm │ │ ├── AopInteceptor.java │ │ ├── MyClassLoader.java │ │ ├── AopClassAdapter.java │ │ └── AopMethodVisitor.java │ │ └── agent │ │ └── Agent.java └── delombok │ └── src-bak │ └── src │ └── main │ └── java │ └── com │ └── hks │ ├── asm │ ├── AopInteceptor.java │ ├── MyClassLoader.java │ ├── AopClassAdapter.java │ └── AopMethodVisitor.java │ └── agent │ └── Agent.java ├── .gitignore ├── java-lambda ├── pom.xml ├── src │ └── main │ │ └── java │ │ └── com │ │ └── hks │ │ └── lambda │ │ ├── FilterTest.java │ │ └── PeekTest.java └── delombok │ └── src-bak │ └── src │ └── main │ └── java │ └── com │ └── hks │ └── lambda │ ├── FilterTest.java │ └── PeekTest.java ├── java-recall └── pom.xml ├── java-thread ├── pom.xml ├── src │ └── main │ │ └── java │ │ └── com │ │ └── hks │ │ └── threadpool │ │ └── TestThreadPool.java └── delombok │ └── src-bak │ └── src │ └── main │ └── java │ └── com │ └── hks │ └── threadpool │ └── TestThreadPool.java ├── java-collectors ├── pom.xml ├── src │ └── main │ │ └── java │ │ └── com │ │ └── hks │ │ ├── hashmap │ │ ├── HashMapKeyTest.java │ │ └── A.java │ │ └── genericity │ │ ├── Dog.java │ │ ├── Animal.java │ │ └── RelationTest.java └── delombok │ └── src-bak │ └── src │ └── main │ └── java │ └── com │ └── hks │ ├── hashmap │ ├── HashMapKeyTest.java │ └── A.java │ └── genericity │ ├── Dog.java │ ├── Animal.java │ └── RelationTest.java ├── java-btrace ├── src │ └── main │ │ └── java │ │ └── com │ │ └── hks │ │ └── btrace │ │ ├── BTraceOnMethodDemoTracer.java │ │ └── BTraceOnMethodDemo.java └── delombok │ └── src-bak │ └── src │ └── main │ └── java │ └── com │ └── hks │ └── btrace │ ├── BTraceOnMethodDemoTracer.java │ └── BTraceOnMethodDemo.java ├── java-cache └── pom.xml └── README.md /java-jmx/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /java-sysEnv/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /java-algorithms/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=9001 -------------------------------------------------------------------------------- /java-algorithms/target/classes/application.properties: -------------------------------------------------------------------------------- 1 | server.port=9001 -------------------------------------------------------------------------------- /java-jmx/delombok/src-bak/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /java-sysEnv/delombok/src-bak/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /java-agent/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singgel/java-base/HEAD/java-agent/.DS_Store -------------------------------------------------------------------------------- /java-agent/.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | target 3 | /target/ 4 | -------------------------------------------------------------------------------- /java-network/Cidr.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singgel/java-base/HEAD/java-network/Cidr.class -------------------------------------------------------------------------------- /java-agent/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst: -------------------------------------------------------------------------------- 1 | TestJVM.class 2 | -------------------------------------------------------------------------------- /java-jmx/src/main/java/com/heks/jmx/DynamicMBean.java: -------------------------------------------------------------------------------- 1 | package com.heks.jmx; 2 | 3 | public class DynamicMBean { 4 | } 5 | -------------------------------------------------------------------------------- /java-agent/target/java-agent-1.0-SNAPSHOT.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singgel/java-base/HEAD/java-agent/target/java-agent-1.0-SNAPSHOT.jar -------------------------------------------------------------------------------- /java-jmx/delombok/src-bak/src/main/java/com/heks/jmx/DynamicMBean.java: -------------------------------------------------------------------------------- 1 | package com.heks.jmx; 2 | 3 | public class DynamicMBean { 4 | } 5 | -------------------------------------------------------------------------------- /java-8future/src/test/java/User.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author heks 3 | * @description: TODO 4 | * @date 2020/11/11 5 | */ 6 | public class User { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /java-agent/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst: -------------------------------------------------------------------------------- 1 | /Users/xueqiu/github/java-base/java-agent/src/test/java/TestJVM.java 2 | -------------------------------------------------------------------------------- /java-intercept/target/classes/com/hks/intercept/Client.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singgel/java-base/HEAD/java-intercept/target/classes/com/hks/intercept/Client.class -------------------------------------------------------------------------------- /java-8future/delombok/src-bak/src/test/java/User.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author heks 3 | * @description: TODO 4 | * @date 2020/11/11 5 | */ 6 | public class User { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /java-agent/target/maven-archiver/pom.properties: -------------------------------------------------------------------------------- 1 | #Generated by Maven 2 | #Fri Apr 26 14:27:06 CST 2019 3 | version=1.0-SNAPSHOT 4 | groupId=com.hks 5 | artifactId=java-agent 6 | -------------------------------------------------------------------------------- /java-algorithms/src/main/java/com/hks/eightsortingalgorithms/leetcode/LRUCache.java: -------------------------------------------------------------------------------- 1 | package com.hks.eightsortingalgorithms.leetcode; 2 | 3 | public class LRUCache { 4 | } 5 | -------------------------------------------------------------------------------- /java-algorithms/src/main/java/com/hks/eightsortingalgorithms/nowcoder/TreeMax.java: -------------------------------------------------------------------------------- 1 | package com.hks.eightsortingalgorithms.nowcoder; 2 | 3 | public class TreeMax { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /java-agent/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst: -------------------------------------------------------------------------------- 1 | /Users/xueqiu/github/java-base/java-agent/src/main/java/com/hks/agent/AgentMain.java 2 | -------------------------------------------------------------------------------- /java-algorithms/README.md: -------------------------------------------------------------------------------- 1 | # eight-sorting-algorithms 2 | Java八大排序算法:选择排序、;JAVA基础偏僻难懂知识(在test里面);我的博客里面有相应的解释,以及动态的gif图片引导你理解:https://blog.csdn.net/singgel/article/details/80335658 3 | -------------------------------------------------------------------------------- /java-intercept/target/classes/com/hks/intercept/ClientImp.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singgel/java-base/HEAD/java-intercept/target/classes/com/hks/intercept/ClientImp.class -------------------------------------------------------------------------------- /java-jvmpre/src/main/java/som/hks/stackAccess/Doer.java: -------------------------------------------------------------------------------- 1 | package som.hks.stackAccess; 2 | 3 | 4 | public abstract interface Doer { 5 | 6 | void doYourThing(); 7 | 8 | } 9 | -------------------------------------------------------------------------------- /java-agent/target/classes/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Premain-Class: com.hks.agent.AgentMain 3 | Agent-Class: com.hks.agent.AgentMain 4 | Can-Redefine-Classes: true 5 | -------------------------------------------------------------------------------- /java-agent/target/java-agent-1.0-SNAPSHOT-jar-with-dependencies.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singgel/java-base/HEAD/java-agent/target/java-agent-1.0-SNAPSHOT-jar-with-dependencies.jar -------------------------------------------------------------------------------- /java-intercept/target/classes/com/hks/intercept/InterceptTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singgel/java-base/HEAD/java-intercept/target/classes/com/hks/intercept/InterceptTest.class -------------------------------------------------------------------------------- /java-agent/src/main/resources/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Premain-Class: com.hks.agent.AgentMain 3 | Agent-Class: com.hks.agent.AgentMain 4 | Can-Redefine-Classes: true 5 | -------------------------------------------------------------------------------- /java-algorithms/src/main/java/com/hks/eightsortingalgorithms/nowcoder/StackHanoi.java: -------------------------------------------------------------------------------- 1 | package com.hks.eightsortingalgorithms.nowcoder; 2 | 3 | public class StackHanoi { 4 | 5 | 6 | } 7 | -------------------------------------------------------------------------------- /java-intercept/target/classes/com/hks/intercept/ForwardingClient.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singgel/java-base/HEAD/java-intercept/target/classes/com/hks/intercept/ForwardingClient.class -------------------------------------------------------------------------------- /java-intercept/target/classes/com/hks/intercept/InterceptTest$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singgel/java-base/HEAD/java-intercept/target/classes/com/hks/intercept/InterceptTest$1.class -------------------------------------------------------------------------------- /java-intercept/target/classes/com/hks/intercept/InterceptTest$2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singgel/java-base/HEAD/java-intercept/target/classes/com/hks/intercept/InterceptTest$2.class -------------------------------------------------------------------------------- /java-jvmpre/delombok/src-bak/src/main/java/som/hks/stackAccess/Doer.java: -------------------------------------------------------------------------------- 1 | package som.hks.stackAccess; 2 | 3 | 4 | public abstract interface Doer { 5 | 6 | void doYourThing(); 7 | 8 | } 9 | -------------------------------------------------------------------------------- /java-intercept/target/classes/com/hks/intercept/ForwardingClientImpl.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singgel/java-base/HEAD/java-intercept/target/classes/com/hks/intercept/ForwardingClientImpl.class -------------------------------------------------------------------------------- /java-agent/delombok/src-bak/src/main/resources/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Premain-Class: com.hks.agent.AgentMain 3 | Agent-Class: com.hks.agent.AgentMain 4 | Can-Redefine-Classes: true 5 | -------------------------------------------------------------------------------- /java-agent/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst: -------------------------------------------------------------------------------- 1 | com/hks/agent/AgentMain$MyClassClassVisitor.class 2 | com/hks/agent/AgentMain.class 3 | com/hks/agent/AgentMain$1.class 4 | -------------------------------------------------------------------------------- /java-proxy/src/main/java/com/hks/proxy/UserService.java: -------------------------------------------------------------------------------- 1 | package com.hks.proxy; 2 | 3 | public interface UserService { 4 | 5 | String getName(int id); 6 | 7 | Integer getAge(int id); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /java-algorithms/target/classes/com/hks/eightsortingalgorithms/config/Swagger2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singgel/java-base/HEAD/java-algorithms/target/classes/com/hks/eightsortingalgorithms/config/Swagger2.class -------------------------------------------------------------------------------- /java-algorithms/target/classes/com/hks/eightsortingalgorithms/leetcode/TwoSum.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singgel/java-base/HEAD/java-algorithms/target/classes/com/hks/eightsortingalgorithms/leetcode/TwoSum.class -------------------------------------------------------------------------------- /java-factory/src/main/java/com/hks/factory/Food.java: -------------------------------------------------------------------------------- 1 | package com.hks.factory; 2 | 3 | public interface Food { 4 | 5 | /** 6 | * 使得所有食物都有一个共有的introduce方法 7 | */ 8 | public void introduce(); 9 | } 10 | -------------------------------------------------------------------------------- /java-algorithms/target/classes/com/hks/eightsortingalgorithms/aspect/MethodTimeAspect.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singgel/java-base/HEAD/java-algorithms/target/classes/com/hks/eightsortingalgorithms/aspect/MethodTimeAspect.class -------------------------------------------------------------------------------- /java-proxy/delombok/src-bak/src/main/java/com/hks/proxy/UserService.java: -------------------------------------------------------------------------------- 1 | package com.hks.proxy; 2 | 3 | public interface UserService { 4 | 5 | String getName(int id); 6 | 7 | Integer getAge(int id); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /java-algorithms/src/main/java/com/hks/eightsortingalgorithms/method/sort/MergeAlgorithms.java: -------------------------------------------------------------------------------- 1 | package com.hks.eightsortingalgorithms.method.sort; 2 | 3 | public interface MergeAlgorithms { 4 | 5 | int[] sort(int[] intArr); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /java-algorithms/src/main/java/com/hks/eightsortingalgorithms/method/sort/QuickAlgorithms.java: -------------------------------------------------------------------------------- 1 | package com.hks.eightsortingalgorithms.method.sort; 2 | 3 | public interface QuickAlgorithms { 4 | 5 | int[] sort(int[] intArr); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /java-algorithms/src/main/java/com/hks/eightsortingalgorithms/method/sort/ShellAlgorithms.java: -------------------------------------------------------------------------------- 1 | package com.hks.eightsortingalgorithms.method.sort; 2 | 3 | public interface ShellAlgorithms { 4 | 5 | int[] sort(int[] args); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /java-algorithms/target/classes/com/hks/eightsortingalgorithms/method/search/BinarySearch.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singgel/java-base/HEAD/java-algorithms/target/classes/com/hks/eightsortingalgorithms/method/search/BinarySearch.class -------------------------------------------------------------------------------- /java-algorithms/target/classes/com/hks/eightsortingalgorithms/method/sort/MergeAlgorithms.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singgel/java-base/HEAD/java-algorithms/target/classes/com/hks/eightsortingalgorithms/method/sort/MergeAlgorithms.class -------------------------------------------------------------------------------- /java-algorithms/target/classes/com/hks/eightsortingalgorithms/method/sort/QuickAlgorithms.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singgel/java-base/HEAD/java-algorithms/target/classes/com/hks/eightsortingalgorithms/method/sort/QuickAlgorithms.class -------------------------------------------------------------------------------- /java-algorithms/target/classes/com/hks/eightsortingalgorithms/method/sort/ShellAlgorithms.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singgel/java-base/HEAD/java-algorithms/target/classes/com/hks/eightsortingalgorithms/method/sort/ShellAlgorithms.class -------------------------------------------------------------------------------- /java-algorithms/target/classes/com/hks/eightsortingalgorithms/nowcoder/RebuildBinaryTree.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singgel/java-base/HEAD/java-algorithms/target/classes/com/hks/eightsortingalgorithms/nowcoder/RebuildBinaryTree.class -------------------------------------------------------------------------------- /java-object/src/main/java/com/hks/enumClass/Grade.java: -------------------------------------------------------------------------------- 1 | package com.hks.enumClass; 2 | 3 | /** 4 | * 在这里,我使用了新的关键字 enum ,为 enum 提供了一个名称,并指定了允许的值。然后, Grade 就变成了一个 枚举类型 5 | */ 6 | public enum Grade { 7 | A, B, C, D, F, INCOMPLETE 8 | } 9 | -------------------------------------------------------------------------------- /java-algorithms/src/main/java/com/hks/eightsortingalgorithms/method/sort/BubbleAlgorithms.java: -------------------------------------------------------------------------------- 1 | package com.hks.eightsortingalgorithms.method.sort; 2 | 3 | public interface BubbleAlgorithms { 4 | 5 | int[] sort(int[] intArr); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /java-algorithms/src/main/java/com/hks/eightsortingalgorithms/method/sort/BucketAlgorithms.java: -------------------------------------------------------------------------------- 1 | package com.hks.eightsortingalgorithms.method.sort; 2 | 3 | public interface BucketAlgorithms { 4 | 5 | int[] sort(int[] intArr); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /java-algorithms/src/main/java/com/hks/eightsortingalgorithms/method/sort/SelectAlgorithms.java: -------------------------------------------------------------------------------- 1 | package com.hks.eightsortingalgorithms.method.sort; 2 | 3 | public interface SelectAlgorithms { 4 | 5 | int[] sort(int[] intArr); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /java-algorithms/target/classes/com/hks/eightsortingalgorithms/method/sort/BubbleAlgorithms.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singgel/java-base/HEAD/java-algorithms/target/classes/com/hks/eightsortingalgorithms/method/sort/BubbleAlgorithms.class -------------------------------------------------------------------------------- /java-algorithms/target/classes/com/hks/eightsortingalgorithms/method/sort/BucketAlgorithms.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singgel/java-base/HEAD/java-algorithms/target/classes/com/hks/eightsortingalgorithms/method/sort/BucketAlgorithms.class -------------------------------------------------------------------------------- /java-algorithms/target/classes/com/hks/eightsortingalgorithms/method/sort/SelectAlgorithms.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singgel/java-base/HEAD/java-algorithms/target/classes/com/hks/eightsortingalgorithms/method/sort/SelectAlgorithms.class -------------------------------------------------------------------------------- /java-factory/delombok/src-bak/src/main/java/com/hks/factory/Food.java: -------------------------------------------------------------------------------- 1 | package com.hks.factory; 2 | 3 | public interface Food { 4 | 5 | /** 6 | * 使得所有食物都有一个共有的introduce方法 7 | */ 8 | public void introduce(); 9 | } 10 | -------------------------------------------------------------------------------- /java-algorithms/src/main/java/com/hks/eightsortingalgorithms/method/sort/SelectHeapAlgorithms.java: -------------------------------------------------------------------------------- 1 | package com.hks.eightsortingalgorithms.method.sort; 2 | 3 | public interface SelectHeapAlgorithms { 4 | 5 | int[] sort(int[] intArr); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /java-algorithms/target/classes/com/hks/eightsortingalgorithms/method/sort/SelectHeapAlgorithms.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singgel/java-base/HEAD/java-algorithms/target/classes/com/hks/eightsortingalgorithms/method/sort/SelectHeapAlgorithms.class -------------------------------------------------------------------------------- /java-algorithms/target/classes/com/hks/eightsortingalgorithms/EightSortingAlgorithmsApplication.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singgel/java-base/HEAD/java-algorithms/target/classes/com/hks/eightsortingalgorithms/EightSortingAlgorithmsApplication.class -------------------------------------------------------------------------------- /java-algorithms/src/main/java/com/hks/eightsortingalgorithms/method/sort/StraightInsertAlgorithms.java: -------------------------------------------------------------------------------- 1 | package com.hks.eightsortingalgorithms.method.sort; 2 | 3 | public interface StraightInsertAlgorithms { 4 | 5 | int[] sort(int[] args); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /java-algorithms/target/classes/com/hks/eightsortingalgorithms/method/search/impl/BinarySearchImpl.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singgel/java-base/HEAD/java-algorithms/target/classes/com/hks/eightsortingalgorithms/method/search/impl/BinarySearchImpl.class -------------------------------------------------------------------------------- /java-algorithms/target/classes/com/hks/eightsortingalgorithms/method/sort/StraightInsertAlgorithms.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singgel/java-base/HEAD/java-algorithms/target/classes/com/hks/eightsortingalgorithms/method/sort/StraightInsertAlgorithms.class -------------------------------------------------------------------------------- /java-algorithms/target/classes/com/hks/eightsortingalgorithms/method/sort/impl/BubbleAlgorithmsImpl.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singgel/java-base/HEAD/java-algorithms/target/classes/com/hks/eightsortingalgorithms/method/sort/impl/BubbleAlgorithmsImpl.class -------------------------------------------------------------------------------- /java-algorithms/target/classes/com/hks/eightsortingalgorithms/method/sort/impl/BucketAlgorithmsImpl.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singgel/java-base/HEAD/java-algorithms/target/classes/com/hks/eightsortingalgorithms/method/sort/impl/BucketAlgorithmsImpl.class -------------------------------------------------------------------------------- /java-algorithms/target/classes/com/hks/eightsortingalgorithms/method/sort/impl/MergeAlgorithmsImpl.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singgel/java-base/HEAD/java-algorithms/target/classes/com/hks/eightsortingalgorithms/method/sort/impl/MergeAlgorithmsImpl.class -------------------------------------------------------------------------------- /java-algorithms/target/classes/com/hks/eightsortingalgorithms/method/sort/impl/QuickAlgorithmsImpl.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singgel/java-base/HEAD/java-algorithms/target/classes/com/hks/eightsortingalgorithms/method/sort/impl/QuickAlgorithmsImpl.class -------------------------------------------------------------------------------- /java-algorithms/target/classes/com/hks/eightsortingalgorithms/method/sort/impl/SelectAlgorithmsImpl.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singgel/java-base/HEAD/java-algorithms/target/classes/com/hks/eightsortingalgorithms/method/sort/impl/SelectAlgorithmsImpl.class -------------------------------------------------------------------------------- /java-algorithms/target/classes/com/hks/eightsortingalgorithms/method/sort/impl/ShellAlgorithmsImpl.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singgel/java-base/HEAD/java-algorithms/target/classes/com/hks/eightsortingalgorithms/method/sort/impl/ShellAlgorithmsImpl.class -------------------------------------------------------------------------------- /java-algorithms/target/classes/com/hks/eightsortingalgorithms/nowcoder/RebuildBinaryTree$TreeNode.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singgel/java-base/HEAD/java-algorithms/target/classes/com/hks/eightsortingalgorithms/nowcoder/RebuildBinaryTree$TreeNode.class -------------------------------------------------------------------------------- /java-object/delombok/src-bak/src/main/java/com/hks/enumClass/Grade.java: -------------------------------------------------------------------------------- 1 | package com.hks.enumClass; 2 | 3 | /** 4 | * 在这里,我使用了新的关键字 enum ,为 enum 提供了一个名称,并指定了允许的值。然后, Grade 就变成了一个 枚举类型 5 | */ 6 | public enum Grade { 7 | A, B, C, D, F, INCOMPLETE 8 | } 9 | -------------------------------------------------------------------------------- /java-object/src/main/java/com/hks/enumClass/AntStatus.java: -------------------------------------------------------------------------------- 1 | package com.hks.enumClass; 2 | 3 | public enum AntStatus { 4 | INITIALIZING, 5 | COMPILING, 6 | COPYING, 7 | JARRING, 8 | ZIPPING, 9 | DONE, 10 | ERROR 11 | } 12 | -------------------------------------------------------------------------------- /java-algorithms/target/classes/com/hks/eightsortingalgorithms/controller/search/BinarySearchController.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singgel/java-base/HEAD/java-algorithms/target/classes/com/hks/eightsortingalgorithms/controller/search/BinarySearchController.class -------------------------------------------------------------------------------- /java-algorithms/target/classes/com/hks/eightsortingalgorithms/controller/sort/BubbleAlgorithmsController.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singgel/java-base/HEAD/java-algorithms/target/classes/com/hks/eightsortingalgorithms/controller/sort/BubbleAlgorithmsController.class -------------------------------------------------------------------------------- /java-algorithms/target/classes/com/hks/eightsortingalgorithms/controller/sort/BucketAlgorithmsController.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singgel/java-base/HEAD/java-algorithms/target/classes/com/hks/eightsortingalgorithms/controller/sort/BucketAlgorithmsController.class -------------------------------------------------------------------------------- /java-algorithms/target/classes/com/hks/eightsortingalgorithms/controller/sort/MergeAlgorithmsController.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singgel/java-base/HEAD/java-algorithms/target/classes/com/hks/eightsortingalgorithms/controller/sort/MergeAlgorithmsController.class -------------------------------------------------------------------------------- /java-algorithms/target/classes/com/hks/eightsortingalgorithms/controller/sort/QuickAlgorithmsController.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singgel/java-base/HEAD/java-algorithms/target/classes/com/hks/eightsortingalgorithms/controller/sort/QuickAlgorithmsController.class -------------------------------------------------------------------------------- /java-algorithms/target/classes/com/hks/eightsortingalgorithms/controller/sort/SelectAlgorithmsController.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singgel/java-base/HEAD/java-algorithms/target/classes/com/hks/eightsortingalgorithms/controller/sort/SelectAlgorithmsController.class -------------------------------------------------------------------------------- /java-algorithms/target/classes/com/hks/eightsortingalgorithms/controller/sort/ShellAlgorithmsController.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singgel/java-base/HEAD/java-algorithms/target/classes/com/hks/eightsortingalgorithms/controller/sort/ShellAlgorithmsController.class -------------------------------------------------------------------------------- /java-algorithms/target/classes/com/hks/eightsortingalgorithms/method/sort/impl/SelectHeapAlgorithmsImpl.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singgel/java-base/HEAD/java-algorithms/target/classes/com/hks/eightsortingalgorithms/method/sort/impl/SelectHeapAlgorithmsImpl.class -------------------------------------------------------------------------------- /java-classloader/src/main/java/com/hks/classLoader/ClassLoaderLeakExample.java: -------------------------------------------------------------------------------- 1 | package com.hks.classLoader; 2 | 3 | /** 4 | * @author heks 5 | * @description: TODO 6 | * @date 2020/11/16 7 | */ 8 | public final class ClassLoaderLeakExample { 9 | 10 | } 11 | -------------------------------------------------------------------------------- /java-algorithms/target/test-classes/com/hks/eightsortingalgorithms/EightSortingAlgorithmsApplicationTests.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singgel/java-base/HEAD/java-algorithms/target/test-classes/com/hks/eightsortingalgorithms/EightSortingAlgorithmsApplicationTests.class -------------------------------------------------------------------------------- /java-object/delombok/src-bak/src/main/java/com/hks/enumClass/AntStatus.java: -------------------------------------------------------------------------------- 1 | package com.hks.enumClass; 2 | 3 | public enum AntStatus { 4 | INITIALIZING, 5 | COMPILING, 6 | COPYING, 7 | JARRING, 8 | ZIPPING, 9 | DONE, 10 | ERROR 11 | } 12 | -------------------------------------------------------------------------------- /java-agent/src/test/java/TestJVM.java: -------------------------------------------------------------------------------- 1 | public class TestJVM { 2 | public static void main(String[] args) { 3 | TestJVM testJVM = new TestJVM(); 4 | testJVM.say(); 5 | } 6 | public void say() { 7 | System.out.println("Say Hello"); 8 | } 9 | } -------------------------------------------------------------------------------- /java-algorithms/target/classes/com/hks/eightsortingalgorithms/controller/sort/SelectHeapAlgorithmsController.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singgel/java-base/HEAD/java-algorithms/target/classes/com/hks/eightsortingalgorithms/controller/sort/SelectHeapAlgorithmsController.class -------------------------------------------------------------------------------- /java-algorithms/target/classes/com/hks/eightsortingalgorithms/method/sort/impl/StraightInsertAlgorithmsImpl.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singgel/java-base/HEAD/java-algorithms/target/classes/com/hks/eightsortingalgorithms/method/sort/impl/StraightInsertAlgorithmsImpl.class -------------------------------------------------------------------------------- /java-intercept/src/main/java/com/hks/intercept/Client.java: -------------------------------------------------------------------------------- 1 | package com.hks.intercept; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | /** 7 | * 主调用接口 8 | */ 9 | public abstract class Client { 10 | public abstract void start(String say); 11 | } 12 | -------------------------------------------------------------------------------- /java-algorithms/target/classes/com/hks/eightsortingalgorithms/controller/sort/StraightInsertAlgorithmsController.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singgel/java-base/HEAD/java-algorithms/target/classes/com/hks/eightsortingalgorithms/controller/sort/StraightInsertAlgorithmsController.class -------------------------------------------------------------------------------- /java-classloader/delombok/src-bak/src/main/java/com/hks/classLoader/ClassLoaderLeakExample.java: -------------------------------------------------------------------------------- 1 | package com.hks.classLoader; 2 | 3 | /** 4 | * @author heks 5 | * @description: TODO 6 | * @date 2020/11/16 7 | */ 8 | public final class ClassLoaderLeakExample { 9 | 10 | } 11 | -------------------------------------------------------------------------------- /java-lock/src/main/java/com/hks/lock/Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 文件名:Test.java 3 | * 版权:Copyright by www.yiche.com 4 | * 描述: 5 | * 修改人:hekuangsheng 6 | * 修改时间:2019/3/26 7 | * 跟踪单号: 8 | * 修改单号: 9 | * 修改内容: 10 | */ 11 | package com.hks.lock; 12 | 13 | public class Test { 14 | } 15 | -------------------------------------------------------------------------------- /java-agent/delombok/src-bak/src/test/java/TestJVM.java: -------------------------------------------------------------------------------- 1 | public class TestJVM { 2 | public static void main(String[] args) { 3 | TestJVM testJVM = new TestJVM(); 4 | testJVM.say(); 5 | } 6 | public void say() { 7 | System.out.println("Say Hello"); 8 | } 9 | } -------------------------------------------------------------------------------- /java-intercept/src/main/java/com/hks/intercept/ClientImp.java: -------------------------------------------------------------------------------- 1 | package com.hks.intercept; 2 | 3 | /** 4 | * 上述接口实现类 5 | */ 6 | public class ClientImp extends Client { 7 | @Override 8 | public void start(String say) { 9 | System.out.println(say); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /java-jmx/src/main/java/com/heks/jmx/HelloWorldMBean.java: -------------------------------------------------------------------------------- 1 | package com.heks.jmx; 2 | 3 | public interface HelloWorldMBean { 4 | 5 | String getHello(); 6 | 7 | void setHello(String hello); 8 | 9 | Object getInstance(); 10 | 11 | String message(String msg); 12 | } 13 | -------------------------------------------------------------------------------- /java-intercept/delombok/src-bak/src/main/java/com/hks/intercept/Client.java: -------------------------------------------------------------------------------- 1 | package com.hks.intercept; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | /** 7 | * 主调用接口 8 | */ 9 | public abstract class Client { 10 | public abstract void start(String say); 11 | } 12 | -------------------------------------------------------------------------------- /java-lock/delombok/src-bak/src/main/java/com/hks/lock/Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 文件名:Test.java 3 | * 版权:Copyright by www.yiche.com 4 | * 描述: 5 | * 修改人:hekuangsheng 6 | * 修改时间:2019/3/26 7 | * 跟踪单号: 8 | * 修改单号: 9 | * 修改内容: 10 | */ 11 | package com.hks.lock; 12 | 13 | public class Test { 14 | } 15 | -------------------------------------------------------------------------------- /java-annotation/src/main/java/com/hks/annotation/FruitName.java: -------------------------------------------------------------------------------- 1 | package com.hks.annotation; 2 | 3 | import java.lang.annotation.*; 4 | 5 | @Target(ElementType.FIELD) 6 | @Retention(RetentionPolicy.RUNTIME) 7 | @Documented 8 | public @interface FruitName { 9 | String value() default ""; 10 | } 11 | -------------------------------------------------------------------------------- /java-intercept/delombok/src-bak/src/main/java/com/hks/intercept/ClientImp.java: -------------------------------------------------------------------------------- 1 | package com.hks.intercept; 2 | 3 | /** 4 | * 上述接口实现类 5 | */ 6 | public class ClientImp extends Client { 7 | @Override 8 | public void start(String say) { 9 | System.out.println(say); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /java-jmx/delombok/src-bak/src/main/java/com/heks/jmx/HelloWorldMBean.java: -------------------------------------------------------------------------------- 1 | package com.heks.jmx; 2 | 3 | public interface HelloWorldMBean { 4 | 5 | String getHello(); 6 | 7 | void setHello(String hello); 8 | 9 | Object getInstance(); 10 | 11 | String message(String msg); 12 | } 13 | -------------------------------------------------------------------------------- /java-agent/target/surefire-reports/TestJVM.txt: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | Test set: TestJVM 3 | ------------------------------------------------------------------------------- 4 | Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.001 sec 5 | -------------------------------------------------------------------------------- /java-annotation/src/main/java/com/hks/annotation/MyTest.java: -------------------------------------------------------------------------------- 1 | package com.hks.annotation; 2 | 3 | public class MyTest { 4 | 5 | @MyAnnotation(hello = "Hello,Beijing",world = "Hello,world") 6 | public void output() { 7 | System.out.println("method output is running "); 8 | } 9 | 10 | } 11 | -------------------------------------------------------------------------------- /java-annotation/delombok/src-bak/src/main/java/com/hks/annotation/FruitName.java: -------------------------------------------------------------------------------- 1 | package com.hks.annotation; 2 | 3 | import java.lang.annotation.*; 4 | 5 | @Target(ElementType.FIELD) 6 | @Retention(RetentionPolicy.RUNTIME) 7 | @Documented 8 | public @interface FruitName { 9 | String value() default ""; 10 | } 11 | -------------------------------------------------------------------------------- /java-object/src/main/java/com/hks/QiangZhiZhuanHuan.java: -------------------------------------------------------------------------------- 1 | package com.hks; 2 | 3 | public class QiangZhiZhuanHuan{ 4 | 5 | public static void main(String[] args){ 6 | int i1 = 123; 7 | byte b = (byte)i1;//强制类型转换为byte 8 | System.out.println("int强制类型转换为byte后的值等于"+b); 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /java-annotation/delombok/src-bak/src/main/java/com/hks/annotation/MyTest.java: -------------------------------------------------------------------------------- 1 | package com.hks.annotation; 2 | 3 | public class MyTest { 4 | 5 | @MyAnnotation(hello = "Hello,Beijing",world = "Hello,world") 6 | public void output() { 7 | System.out.println("method output is running "); 8 | } 9 | 10 | } 11 | -------------------------------------------------------------------------------- /java-object/delombok/src-bak/src/main/java/com/hks/QiangZhiZhuanHuan.java: -------------------------------------------------------------------------------- 1 | package com.hks; 2 | 3 | public class QiangZhiZhuanHuan{ 4 | 5 | public static void main(String[] args){ 6 | int i1 = 123; 7 | byte b = (byte)i1;//强制类型转换为byte 8 | System.out.println("int强制类型转换为byte后的值等于"+b); 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /java-factory/src/main/java/com/hks/factory/Fish.java: -------------------------------------------------------------------------------- 1 | package com.hks.factory; 2 | 3 | /** 4 | * @Author: hekuangsheng 5 | * @Date: 2018/10/23 6 | 7 | * 定义食物的子类:鱼 8 | */ 9 | public class Fish implements Food{ 10 | 11 | @Override 12 | public void introduce() { 13 | System.out.println("i am a fish"); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /java-factory/src/main/java/com/hks/factory/Fruit.java: -------------------------------------------------------------------------------- 1 | package com.hks.factory; 2 | 3 | /** 4 | * @Author: hekuangsheng 5 | * @Date: 2018/10/23 6 | 7 | * 食物的子类,水果 8 | */ 9 | public class Fruit implements Food { 10 | @Override 11 | public void introduce() { 12 | System.out.println("i am the fruit"); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /java-factory/src/main/java/com/hks/factory/StaticFactoryClass.java: -------------------------------------------------------------------------------- 1 | package com.hks.factory; 2 | 3 | /** 4 | * @Author: hekuangsheng 5 | * @Date: 2018/10/23 6 | */ 7 | public class StaticFactoryClass { 8 | 9 | public static Boolean valueOf(Boolean b) { 10 | return b ? Boolean.TRUE : Boolean.FALSE; 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /java-annotation/src/main/java/com/hks/annotation/NoDBColumn.java: -------------------------------------------------------------------------------- 1 | package com.hks.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Target; 5 | 6 | /** 7 | * 注解Table 可以用于注解类、接口(包括注解类型) 或enum声明,而注解NoDBColumn仅可用于注解类的成员变量。 8 | */ 9 | @Target(ElementType.FIELD) 10 | public @interface NoDBColumn { 11 | } 12 | -------------------------------------------------------------------------------- /java-8stream/src/main/java/com/heks/stream/ForEach.java: -------------------------------------------------------------------------------- 1 | package com.heks.stream; 2 | 3 | /** 4 | * @author heks 5 | * @description: TODO 6 | * @date 2020/11/11 7 | */ 8 | @FunctionalInterface 9 | public interface ForEach { 10 | 11 | /** 12 | * 迭代器遍历 13 | * @param item 被迭代的每一项 14 | * */ 15 | void apply(T item); 16 | } 17 | -------------------------------------------------------------------------------- /java-factory/delombok/src-bak/src/main/java/com/hks/factory/Fish.java: -------------------------------------------------------------------------------- 1 | package com.hks.factory; 2 | 3 | /** 4 | * @Author: hekuangsheng 5 | * @Date: 2018/10/23 6 | 7 | * 定义食物的子类:鱼 8 | */ 9 | public class Fish implements Food{ 10 | 11 | @Override 12 | public void introduce() { 13 | System.out.println("i am a fish"); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /java-factory/delombok/src-bak/src/main/java/com/hks/factory/Fruit.java: -------------------------------------------------------------------------------- 1 | package com.hks.factory; 2 | 3 | /** 4 | * @Author: hekuangsheng 5 | * @Date: 2018/10/23 6 | 7 | * 食物的子类,水果 8 | */ 9 | public class Fruit implements Food { 10 | @Override 11 | public void introduce() { 12 | System.out.println("i am the fruit"); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /java-factory/delombok/src-bak/src/main/java/com/hks/factory/StaticFactoryClass.java: -------------------------------------------------------------------------------- 1 | package com.hks.factory; 2 | 3 | /** 4 | * @Author: hekuangsheng 5 | * @Date: 2018/10/23 6 | */ 7 | public class StaticFactoryClass { 8 | 9 | public static Boolean valueOf(Boolean b) { 10 | return b ? Boolean.TRUE : Boolean.FALSE; 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /java-annotation/delombok/src-bak/src/main/java/com/hks/annotation/NoDBColumn.java: -------------------------------------------------------------------------------- 1 | package com.hks.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Target; 5 | 6 | /** 7 | * 注解Table 可以用于注解类、接口(包括注解类型) 或enum声明,而注解NoDBColumn仅可用于注解类的成员变量。 8 | */ 9 | @Target(ElementType.FIELD) 10 | public @interface NoDBColumn { 11 | } 12 | -------------------------------------------------------------------------------- /java-8stream/delombok/src-bak/src/main/java/com/heks/stream/ForEach.java: -------------------------------------------------------------------------------- 1 | package com.heks.stream; 2 | 3 | /** 4 | * @author heks 5 | * @description: TODO 6 | * @date 2020/11/11 7 | */ 8 | @FunctionalInterface 9 | public interface ForEach { 10 | 11 | /** 12 | * 迭代器遍历 13 | * @param item 被迭代的每一项 14 | * */ 15 | void apply(T item); 16 | } 17 | -------------------------------------------------------------------------------- /java-8stream/src/main/java/com/heks/stream/EvalFunction.java: -------------------------------------------------------------------------------- 1 | package com.heks.stream; 2 | 3 | /** 4 | * @author heks 5 | * @description: TODO 6 | * @date 2020/11/11 7 | */ 8 | @FunctionalInterface 9 | public interface EvalFunction { 10 | 11 | /** 12 | * stream流的强制求值方法 13 | * @return 求值返回一个新的stream 14 | * */ 15 | MyStream apply(); 16 | } 17 | -------------------------------------------------------------------------------- /java-classloader/src/main/java/com/hks/classLoader/TestBeLoader.java: -------------------------------------------------------------------------------- 1 | package com.hks.classLoader; 2 | 3 | /** 4 | * 第二步,定义一个类,专门用于被装载,这里我们定义了一个静态代码块,待会用到它 5 | */ 6 | public class TestBeLoader { 7 | 8 | static{ 9 | System.out.println("TestBeLoader init"); 10 | } 11 | public void sayHello(){ 12 | System.out.println("hello"); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /java-factory/src/main/java/com/hks/factory/FoodFactoryTest.java: -------------------------------------------------------------------------------- 1 | package com.hks.factory; 2 | 3 | import org.junit.Test; 4 | 5 | /** 6 | * @Author: hekuangsheng 7 | * @Date: 2018/10/23 8 | */ 9 | public class FoodFactoryTest { 10 | 11 | @Test 12 | public void test(){ 13 | Food food = FoodFactory.getFood("Fish"); 14 | food.introduce(); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /java-intercept/src/main/java/com/hks/intercept/ForwardingClient.java: -------------------------------------------------------------------------------- 1 | package com.hks.intercept; 2 | 3 | /** 4 | * 用于包装Client到另一个Client 5 | */ 6 | public abstract class ForwardingClient extends Client{ 7 | //要包装的对象 8 | protected abstract Client delegate(); 9 | 10 | @Override 11 | public void start(String say) { 12 | delegate().start(say); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /java-8stream/delombok/src-bak/src/main/java/com/heks/stream/EvalFunction.java: -------------------------------------------------------------------------------- 1 | package com.heks.stream; 2 | 3 | /** 4 | * @author heks 5 | * @description: TODO 6 | * @date 2020/11/11 7 | */ 8 | @FunctionalInterface 9 | public interface EvalFunction { 10 | 11 | /** 12 | * stream流的强制求值方法 13 | * @return 求值返回一个新的stream 14 | * */ 15 | MyStream apply(); 16 | } 17 | -------------------------------------------------------------------------------- /java-classloader/delombok/src-bak/src/main/java/com/hks/classLoader/TestBeLoader.java: -------------------------------------------------------------------------------- 1 | package com.hks.classLoader; 2 | 3 | /** 4 | * 第二步,定义一个类,专门用于被装载,这里我们定义了一个静态代码块,待会用到它 5 | */ 6 | public class TestBeLoader { 7 | 8 | static{ 9 | System.out.println("TestBeLoader init"); 10 | } 11 | public void sayHello(){ 12 | System.out.println("hello"); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /java-intercept/delombok/src-bak/src/main/java/com/hks/intercept/ForwardingClient.java: -------------------------------------------------------------------------------- 1 | package com.hks.intercept; 2 | 3 | /** 4 | * 用于包装Client到另一个Client 5 | */ 6 | public abstract class ForwardingClient extends Client{ 7 | //要包装的对象 8 | protected abstract Client delegate(); 9 | 10 | @Override 11 | public void start(String say) { 12 | delegate().start(say); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /java-factory/delombok/src-bak/src/main/java/com/hks/factory/FoodFactoryTest.java: -------------------------------------------------------------------------------- 1 | package com.hks.factory; 2 | 3 | import org.junit.Test; 4 | 5 | /** 6 | * @Author: hekuangsheng 7 | * @Date: 2018/10/23 8 | */ 9 | public class FoodFactoryTest { 10 | 11 | @Test 12 | public void test(){ 13 | Food food = FoodFactory.getFood("Fish"); 14 | food.introduce(); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /java-jmx/src/main/java/com/heks/jmx/JmxApplication.java: -------------------------------------------------------------------------------- 1 | package com.heks.jmx; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class JmxApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(JmxApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /java-jmx/delombok/src-bak/src/main/java/com/heks/jmx/JmxApplication.java: -------------------------------------------------------------------------------- 1 | package com.heks.jmx; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class JmxApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(JmxApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /java-aspect/src/main/java/com/hks/asm/AopInteceptor.java: -------------------------------------------------------------------------------- 1 | package com.hks.asm; 2 | 3 | /** 4 | * @Author: hekuangsheng 5 | * @Date: 2018/10/19 6 | */ 7 | public class AopInteceptor { 8 | 9 | public static void before(){ 10 | System.out.println(".......before()......."); 11 | } 12 | 13 | public static void after(){ 14 | System.out.println(".......after()......."); 15 | } 16 | 17 | 18 | } 19 | -------------------------------------------------------------------------------- /java-sysEnv/src/main/java/com/heks/jj/JavaSysEnvApplication.java: -------------------------------------------------------------------------------- 1 | package com.heks.jj; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class JavaSysEnvApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(JavaSysEnvApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /java-proxy/src/main/java/com/hks/proxy/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.hks.proxy; 2 | 3 | public class UserServiceImpl implements UserService { 4 | 5 | public String getName(int id) { 6 | System.out.println("-------getName-------"); 7 | return "Tom"; 8 | } 9 | 10 | public Integer getAge(int id) { 11 | System.out.println("-------getAge-------"); 12 | return 10; 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /java-aspect/delombok/src-bak/src/main/java/com/hks/asm/AopInteceptor.java: -------------------------------------------------------------------------------- 1 | package com.hks.asm; 2 | 3 | /** 4 | * @Author: hekuangsheng 5 | * @Date: 2018/10/19 6 | */ 7 | public class AopInteceptor { 8 | 9 | public static void before(){ 10 | System.out.println(".......before()......."); 11 | } 12 | 13 | public static void after(){ 14 | System.out.println(".......after()......."); 15 | } 16 | 17 | 18 | } 19 | -------------------------------------------------------------------------------- /java-sysEnv/delombok/src-bak/src/main/java/com/heks/jj/JavaSysEnvApplication.java: -------------------------------------------------------------------------------- 1 | package com.heks.jj; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class JavaSysEnvApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(JavaSysEnvApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | */target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### VS code ### 5 | .history 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | .DS_Store 22 | *.csv 23 | 24 | ### NetBeans ### 25 | /nbproject/private/ 26 | /build/ 27 | /nbbuild/ 28 | /dist/ 29 | /nbdist/ 30 | /.nb-gradle/ -------------------------------------------------------------------------------- /java-jmx/src/test/java/com/heks/jmx/JmxApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.heks.jmx; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class JmxApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /java-proxy/delombok/src-bak/src/main/java/com/hks/proxy/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.hks.proxy; 2 | 3 | public class UserServiceImpl implements UserService { 4 | 5 | public String getName(int id) { 6 | System.out.println("-------getName-------"); 7 | return "Tom"; 8 | } 9 | 10 | public Integer getAge(int id) { 11 | System.out.println("-------getAge-------"); 12 | return 10; 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /java-annotation/src/main/java/com/hks/annotation/Test.java: -------------------------------------------------------------------------------- 1 | package com.hks.annotation; 2 | 3 | @Column(name = "heks",setFuncName = "heksFunc") 4 | 5 | public class Test { 6 | 7 | @FruitColor 8 | private String colnum; 9 | 10 | @org.junit.Test 11 | public void test(){ 12 | Apple apple = new Apple(); 13 | System.out.print(apple.getAppleColor()); 14 | System.out.print(apple.getAppleName()); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /java-object/src/main/java/com/hks/ZiDongLeiZhuan.java: -------------------------------------------------------------------------------- 1 | package com.hks; 2 | 3 | public class ZiDongLeiZhuan{ 4 | 5 | public static void main(String[] args){ 6 | char c1='a';//定义一个char类型 7 | int i1 = c1;//char自动类型转换为int 8 | System.out.println("char自动类型转换为int后的值等于"+i1); 9 | char c2 = 'A';//定义一个char类型 10 | int i2 = c2+1;//char 类型和 int 类型计算 11 | System.out.println("char类型和int计算后的值等于"+i2); 12 | } 13 | 14 | } -------------------------------------------------------------------------------- /java-jvmpre/src/main/java/som/hks/oom/PutInEden.java: -------------------------------------------------------------------------------- 1 | package som.hks.oom; 2 | 3 | /** 4 | * 所示代码尝试分配 4MB 内存空间,观察一下它的内存使用情况 5 | */ 6 | public class PutInEden { 7 | 8 | public static void main(String[] args){ 9 | byte[] b1,b2,b3,b4;//定义变量 10 | //分配 1MB 堆空间,考察堆空间的使用情况 11 | b1=new byte[1024*1024]; 12 | b2=new byte[1024*1024]; 13 | b3=new byte[1024*1024]; 14 | b4=new byte[1024*1024]; 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /java-algorithms/src/main/java/com/hks/eightsortingalgorithms/leetcode/maxProfit.java: -------------------------------------------------------------------------------- 1 | package com.hks.eightsortingalgorithms.leetcode; 2 | 3 | public class maxProfit { 4 | public int maxProfit(int[] prices) { 5 | int res=0, min = Integer.MAX_VALUE; 6 | for (int i = 0; i < prices.length; i++) { 7 | min = Math.min(min, prices[i]); 8 | res = Math.max(res, prices[i]-min); 9 | } 10 | return res; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /java-jmx/delombok/src-bak/src/test/java/com/heks/jmx/JmxApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.heks.jmx; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class JmxApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /java-annotation/delombok/src-bak/src/main/java/com/hks/annotation/Test.java: -------------------------------------------------------------------------------- 1 | package com.hks.annotation; 2 | 3 | @Column(name = "heks",setFuncName = "heksFunc") 4 | 5 | public class Test { 6 | 7 | @FruitColor 8 | private String colnum; 9 | 10 | @org.junit.Test 11 | public void test(){ 12 | Apple apple = new Apple(); 13 | System.out.print(apple.getAppleColor()); 14 | System.out.print(apple.getAppleName()); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /java-jvmpre/delombok/src-bak/src/main/java/som/hks/oom/PutInEden.java: -------------------------------------------------------------------------------- 1 | package som.hks.oom; 2 | 3 | /** 4 | * 所示代码尝试分配 4MB 内存空间,观察一下它的内存使用情况 5 | */ 6 | public class PutInEden { 7 | 8 | public static void main(String[] args){ 9 | byte[] b1,b2,b3,b4;//定义变量 10 | //分配 1MB 堆空间,考察堆空间的使用情况 11 | b1=new byte[1024*1024]; 12 | b2=new byte[1024*1024]; 13 | b3=new byte[1024*1024]; 14 | b4=new byte[1024*1024]; 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /java-jvmpre/src/test/java/com/hks/RuntimeConstantPoolOOM.java: -------------------------------------------------------------------------------- 1 | package com.hks; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | //-XX:PermSize=10M -XX:MaxPermSize=10M 7 | public class RuntimeConstantPoolOOM { 8 | public static void main(String[] args) { 9 | List list = new ArrayList(); 10 | int i =0; 11 | while (true){ 12 | list.add(String.valueOf(i).intern()); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /java-object/delombok/src-bak/src/main/java/com/hks/ZiDongLeiZhuan.java: -------------------------------------------------------------------------------- 1 | package com.hks; 2 | 3 | public class ZiDongLeiZhuan{ 4 | 5 | public static void main(String[] args){ 6 | char c1='a';//定义一个char类型 7 | int i1 = c1;//char自动类型转换为int 8 | System.out.println("char自动类型转换为int后的值等于"+i1); 9 | char c2 = 'A';//定义一个char类型 10 | int i2 = c2+1;//char 类型和 int 类型计算 11 | System.out.println("char类型和int计算后的值等于"+i2); 12 | } 13 | 14 | } -------------------------------------------------------------------------------- /java-annotation/src/main/java/com/hks/annotation/MyAnnotation.java: -------------------------------------------------------------------------------- 1 | package com.hks.annotation; 2 | 3 | 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | @Target(ElementType.METHOD) 10 | @Retention(RetentionPolicy.RUNTIME) 11 | public @interface MyAnnotation 12 | { 13 | 14 | String hello () default "hello"; 15 | String world(); 16 | } 17 | -------------------------------------------------------------------------------- /java-lock/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.hks 8 | java-lock 9 | 1.0-SNAPSHOT 10 | 11 | 12 | -------------------------------------------------------------------------------- /java-8stream/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | org.example 8 | java-8stream 9 | 1.0-SNAPSHOT 10 | 11 | 12 | -------------------------------------------------------------------------------- /java-intercept/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.hks 8 | intercept 9 | 1.0-SNAPSHOT 10 | 11 | 12 | -------------------------------------------------------------------------------- /java-intercept/src/main/java/com/hks/intercept/ForwardingClientImpl.java: -------------------------------------------------------------------------------- 1 | package com.hks.intercept; 2 | 3 | /** 4 | * 一个简单的包装实现类,必须要传入要包装的对象 5 | */ 6 | public class ForwardingClientImpl extends ForwardingClient{ 7 | 8 | //被委托对象 9 | private final Client client; 10 | 11 | public ForwardingClientImpl(Client client) { 12 | this.client = client; 13 | } 14 | 15 | @Override 16 | protected Client delegate() { 17 | return client; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /java-jvmpre/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.hks 8 | java-jvmpre 9 | 1.0-SNAPSHOT 10 | 11 | 12 | -------------------------------------------------------------------------------- /java-jvmpre/src/test/java/com/hks/HeapOOM.java: -------------------------------------------------------------------------------- 1 | package com.hks; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | //-Xms20M -Xmx20M -Xmn10M -XX:+PrintGCDetails -XX:SurvivorRatio=8 7 | public class HeapOOM { 8 | static class OOMObject{} 9 | 10 | public static void main(String[] args) { 11 | List list = new ArrayList(); 12 | while (true){ 13 | list.add(new OOMObject()); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /java-lambda/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.hks 8 | java-lambda 9 | 1.0-SNAPSHOT 10 | 11 | 12 | -------------------------------------------------------------------------------- /java-object/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.hks 8 | java-object 9 | 1.0-SNAPSHOT 10 | 11 | 12 | -------------------------------------------------------------------------------- /java-proxy/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.hks 8 | java-proxy 9 | 1.0-SNAPSHOT 10 | 11 | 12 | -------------------------------------------------------------------------------- /java-recall/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.hks 8 | java-recall 9 | 1.0-SNAPSHOT 10 | 11 | 12 | -------------------------------------------------------------------------------- /java-thread/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.hks 8 | java-thread 9 | 1.0-SNAPSHOT 10 | 11 | 12 | -------------------------------------------------------------------------------- /java-jmx/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/** 5 | !**/src/test/** 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | 30 | ### VS Code ### 31 | .vscode/ 32 | -------------------------------------------------------------------------------- /java-jvmpre/delombok/src-bak/src/test/java/com/hks/RuntimeConstantPoolOOM.java: -------------------------------------------------------------------------------- 1 | package com.hks; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | //-XX:PermSize=10M -XX:MaxPermSize=10M 7 | public class RuntimeConstantPoolOOM { 8 | public static void main(String[] args) { 9 | List list = new ArrayList(); 10 | int i =0; 11 | while (true){ 12 | list.add(String.valueOf(i).intern()); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /java-object/src/main/java/com/hks/builder/BuilderTest.java: -------------------------------------------------------------------------------- 1 | package com.hks.builder; 2 | 3 | import static java.lang.System.out; 4 | /** 5 | * @Author: hekuangsheng 6 | * @Date: 2018/10/23 7 | */ 8 | public class BuilderTest { 9 | 10 | public static void main(String[] args) { 11 | User.Builder builder = new User.Builder(); 12 | User user = builder.setName("corn").setAge(100).setAddress("广州").build(); 13 | out.print(user.toString()); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /java-object/src/main/java/com/hks/cloneClass/ReferenceCopy.java: -------------------------------------------------------------------------------- 1 | package com.hks.cloneClass; 2 | 3 | import org.junit.Test; 4 | 5 | /** 6 | * 引用拷贝 7 | * 8 | * 可以看到,打印的结果是一样的, 9 | * 也就是说,二者的引用是同一个对象,并没有创建出一个新的对象 10 | */ 11 | public class ReferenceCopy { 12 | 13 | @Test 14 | public void copyReferenceObject(){ 15 | Person p = new Person(23, "zhang"); 16 | Person p1 = p; 17 | System.out.println(p); 18 | System.out.println(p1); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /java-annotation/delombok/src-bak/src/main/java/com/hks/annotation/MyAnnotation.java: -------------------------------------------------------------------------------- 1 | package com.hks.annotation; 2 | 3 | 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | @Target(ElementType.METHOD) 10 | @Retention(RetentionPolicy.RUNTIME) 11 | public @interface MyAnnotation 12 | { 13 | 14 | String hello () default "hello"; 15 | String world(); 16 | } 17 | -------------------------------------------------------------------------------- /java-classloader/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.hks 8 | java-classloader 9 | 1.0-SNAPSHOT 10 | 11 | 12 | -------------------------------------------------------------------------------- /java-collectors/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.hks 8 | java-collectors 9 | 1.0-SNAPSHOT 10 | 11 | 12 | -------------------------------------------------------------------------------- /java-jvmpre/src/test/java/com/hks/HeapAllocation.java: -------------------------------------------------------------------------------- 1 | package com.hks; 2 | 3 | public class HeapAllocation { 4 | 5 | private static final int _1MB = 1024 * 1024; 6 | 7 | public static void main(String[] args) { 8 | byte[] allocation1, allocation2, allocation3, allocation4; 9 | allocation1 = new byte[2 * _1MB]; 10 | allocation2 = new byte[2 * _1MB]; 11 | allocation3 = new byte[2 * _1MB]; 12 | allocation4 = new byte[4 * _1MB]; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /java-sysEnv/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/** 5 | !**/src/test/** 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | 30 | ### VS Code ### 31 | .vscode/ 32 | -------------------------------------------------------------------------------- /java-algorithms/src/main/java/com/hks/eightsortingalgorithms/EightSortingAlgorithmsApplication.java: -------------------------------------------------------------------------------- 1 | package com.hks.eightsortingalgorithms; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class EightSortingAlgorithmsApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(EightSortingAlgorithmsApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /java-btrace/src/main/java/com/hks/btrace/BTraceOnMethodDemoTracer.java: -------------------------------------------------------------------------------- 1 | package com.hks.btrace; 2 | 3 | import com.sun.btrace.annotations.BTrace; 4 | import com.sun.btrace.annotations.OnMethod; 5 | 6 | import static com.sun.btrace.BTraceUtils.println; 7 | 8 | @BTrace 9 | public class BTraceOnMethodDemoTracer { 10 | 11 | @OnMethod(clazz = "java.lang.Thread", method = "start") 12 | public static void onThreadStart() { 13 | println("tracing method start"); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /java-jvmpre/delombok/src-bak/src/test/java/com/hks/HeapOOM.java: -------------------------------------------------------------------------------- 1 | package com.hks; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | //-Xms20M -Xmx20M -Xmn10M -XX:+PrintGCDetails -XX:SurvivorRatio=8 7 | public class HeapOOM { 8 | static class OOMObject{} 9 | 10 | public static void main(String[] args) { 11 | List list = new ArrayList(); 12 | while (true){ 13 | list.add(new OOMObject()); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /java-annotation/src/main/java/com/hks/annotation/FruitColor.java: -------------------------------------------------------------------------------- 1 | package com.hks.annotation; 2 | 3 | import java.lang.annotation.*; 4 | 5 | @Target(ElementType.FIELD) 6 | @Retention(RetentionPolicy.RUNTIME) 7 | @Documented 8 | public @interface FruitColor { 9 | /** 10 | * 颜色枚举 11 | * @author peida 12 | * 13 | */ 14 | public enum Color{ BULE,RED,GREEN}; 15 | 16 | /** 17 | * 颜色属性 18 | * @return 19 | */ 20 | Color fruitColor() default Color.GREEN; 21 | } 22 | -------------------------------------------------------------------------------- /java-intercept/delombok/src-bak/src/main/java/com/hks/intercept/ForwardingClientImpl.java: -------------------------------------------------------------------------------- 1 | package com.hks.intercept; 2 | 3 | /** 4 | * 一个简单的包装实现类,必须要传入要包装的对象 5 | */ 6 | public class ForwardingClientImpl extends ForwardingClient{ 7 | 8 | //被委托对象 9 | private final Client client; 10 | 11 | public ForwardingClientImpl(Client client) { 12 | this.client = client; 13 | } 14 | 15 | @Override 16 | protected Client delegate() { 17 | return client; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /java-object/delombok/src-bak/src/main/java/com/hks/builder/BuilderTest.java: -------------------------------------------------------------------------------- 1 | package com.hks.builder; 2 | 3 | import static java.lang.System.out; 4 | /** 5 | * @Author: hekuangsheng 6 | * @Date: 2018/10/23 7 | */ 8 | public class BuilderTest { 9 | 10 | public static void main(String[] args) { 11 | User.Builder builder = new User.Builder(); 12 | User user = builder.setName("corn").setAge(100).setAddress("广州").build(); 13 | out.print(user.toString()); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /java-object/delombok/src-bak/src/main/java/com/hks/cloneClass/ReferenceCopy.java: -------------------------------------------------------------------------------- 1 | package com.hks.cloneClass; 2 | 3 | import org.junit.Test; 4 | 5 | /** 6 | * 引用拷贝 7 | * 8 | * 可以看到,打印的结果是一样的, 9 | * 也就是说,二者的引用是同一个对象,并没有创建出一个新的对象 10 | */ 11 | public class ReferenceCopy { 12 | 13 | @Test 14 | public void copyReferenceObject(){ 15 | Person p = new Person(23, "zhang"); 16 | Person p1 = p; 17 | System.out.println(p); 18 | System.out.println(p1); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /java-jvmpre/delombok/src-bak/src/test/java/com/hks/HeapAllocation.java: -------------------------------------------------------------------------------- 1 | package com.hks; 2 | 3 | public class HeapAllocation { 4 | 5 | private static final int _1MB = 1024 * 1024; 6 | 7 | public static void main(String[] args) { 8 | byte[] allocation1, allocation2, allocation3, allocation4; 9 | allocation1 = new byte[2 * _1MB]; 10 | allocation2 = new byte[2 * _1MB]; 11 | allocation3 = new byte[2 * _1MB]; 12 | allocation4 = new byte[4 * _1MB]; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /java-object/src/main/java/com/hks/serializable/Employee.java: -------------------------------------------------------------------------------- 1 | package com.hks.serializable; 2 | 3 | /** 4 | * @Author: hekuangsheng 5 | * @Date: 2018/10/15 6 | */ 7 | public class Employee implements java.io.Serializable 8 | { 9 | public String name; 10 | public String address; 11 | public transient int SSN; 12 | public int number; 13 | public void mailCheck() 14 | { 15 | System.out.println("Mailing a check to " + name 16 | + " " + address); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /java-btrace/delombok/src-bak/src/main/java/com/hks/btrace/BTraceOnMethodDemoTracer.java: -------------------------------------------------------------------------------- 1 | package com.hks.btrace; 2 | 3 | import com.sun.btrace.annotations.BTrace; 4 | import com.sun.btrace.annotations.OnMethod; 5 | 6 | import static com.sun.btrace.BTraceUtils.println; 7 | 8 | @BTrace 9 | public class BTraceOnMethodDemoTracer { 10 | 11 | @OnMethod(clazz = "java.lang.Thread", method = "start") 12 | public static void onThreadStart() { 13 | println("tracing method start"); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /java-jvmpre/src/main/java/som/hks/oom/ReferenceTest.java: -------------------------------------------------------------------------------- 1 | package som.hks.oom; 2 | 3 | public class ReferenceTest { 4 | 5 | public static void main(String[] args){ 6 | String a = "1"; 7 | String b = "2"; 8 | String c = "3"; 9 | a=b; 10 | System.out.println(a+"\n"); 11 | a=c; 12 | System.out.println(a+"\n"); 13 | c=null; 14 | System.out.println(a+"\n"); 15 | a=null; 16 | System.out.println(a+"\n"); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /java-annotation/delombok/src-bak/src/main/java/com/hks/annotation/FruitColor.java: -------------------------------------------------------------------------------- 1 | package com.hks.annotation; 2 | 3 | import java.lang.annotation.*; 4 | 5 | @Target(ElementType.FIELD) 6 | @Retention(RetentionPolicy.RUNTIME) 7 | @Documented 8 | public @interface FruitColor { 9 | /** 10 | * 颜色枚举 11 | * @author peida 12 | * 13 | */ 14 | public enum Color{ BULE,RED,GREEN}; 15 | 16 | /** 17 | * 颜色属性 18 | * @return 19 | */ 20 | Color fruitColor() default Color.GREEN; 21 | } 22 | -------------------------------------------------------------------------------- /java-jvmpre/src/main/java/som/hks/aceessControler/MySecurityManager.java: -------------------------------------------------------------------------------- 1 | package som.hks.aceessControler; 2 | 3 | /** 4 | * 第一步:实现一个自己的类MySecurityManager,它继承自SecurityManager, 5 | * 重写它的checkRead方法,我们直接让他抛出一个SecurityException异常。 6 | * (copy吧少年,要的是你知识的储备,不是要你把代码背下来) 7 | */ 8 | public class MySecurityManager extends SecurityManager{ 9 | 10 | @Override 11 | public void checkRead(String file) { 12 | //super.checkRead(file, context); 13 | throw new SecurityException("你没有的权限"); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /java-jvmpre/src/main/java/som/hks/oom/PutInEden2.java: -------------------------------------------------------------------------------- 1 | package som.hks.oom; 2 | 3 | /** 4 | * -XX:+PrintGCDetails -Xmx1000M -Xms500M -Xmn100M -XX:SurvivorRatio=8 5 | * 6 | */ 7 | public class PutInEden2 { 8 | public static void main(String[] args){ 9 | byte[] b1,b2,b3; 10 | b1=new byte[1024*512];//分配 0.5MB 堆空间 11 | b2=new byte[1024*1024*4];//分配 4MB 堆空间 12 | b3=new byte[1024*1024*4]; 13 | b3=null; //使 b3 可以被回收 14 | b3=new byte[1024*1024*4];//分配 4MB 堆空间 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /java-jvmpre/src/main/java/som/hks/securityManager/MySecurityManager.java: -------------------------------------------------------------------------------- 1 | package som.hks.securityManager; 2 | 3 | /** 4 | * 第一步,定义一个类继承自SecurityManger重写它的checkRead方(如果你有兴趣可以先跳到super.checkRead(file, context); 5 | * 6 | */ 7 | public class MySecurityManager extends SecurityManager{ 8 | 9 | @Override 10 | public void checkRead(String file) { 11 | //super.checkRead(file, context); 12 | if (file.endsWith("test")) 13 | throw new SecurityException("你没有读取的本文件的权限"); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /java-algorithms/src/test/java/com/hks/eightsortingalgorithms/EightSortingAlgorithmsApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.hks.eightsortingalgorithms; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class EightSortingAlgorithmsApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /java-jvmpre/delombok/src-bak/src/main/java/som/hks/oom/ReferenceTest.java: -------------------------------------------------------------------------------- 1 | package som.hks.oom; 2 | 3 | public class ReferenceTest { 4 | 5 | public static void main(String[] args){ 6 | String a = "1"; 7 | String b = "2"; 8 | String c = "3"; 9 | a=b; 10 | System.out.println(a+"\n"); 11 | a=c; 12 | System.out.println(a+"\n"); 13 | c=null; 14 | System.out.println(a+"\n"); 15 | a=null; 16 | System.out.println(a+"\n"); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /java-object/delombok/src-bak/src/main/java/com/hks/serializable/Employee.java: -------------------------------------------------------------------------------- 1 | package com.hks.serializable; 2 | 3 | /** 4 | * @Author: hekuangsheng 5 | * @Date: 2018/10/15 6 | */ 7 | public class Employee implements java.io.Serializable 8 | { 9 | public String name; 10 | public String address; 11 | public transient int SSN; 12 | public int number; 13 | public void mailCheck() 14 | { 15 | System.out.println("Mailing a check to " + name 16 | + " " + address); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /java-algorithms/src/main/java/com/hks/eightsortingalgorithms/leetcode/maxProfit2.java: -------------------------------------------------------------------------------- 1 | package com.hks.eightsortingalgorithms.leetcode; 2 | 3 | public class maxProfit2 { 4 | public int maxProfit(int[] prices) { 5 | if(prices.length<=1) { 6 | return 0; 7 | } 8 | int res = 0; 9 | for (int i = 1; i < prices.length; ++i) { 10 | if(prices[i]>prices[i-1]) { 11 | res += prices[i] - prices[i-1]; 12 | } 13 | } 14 | return res; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /java-algorithms/src/main/java/com/hks/eightsortingalgorithms/leetcode/myPow.java: -------------------------------------------------------------------------------- 1 | package com.hks.eightsortingalgorithms.leetcode; 2 | 3 | public class myPow { 4 | public double myPow(double x, int n) { 5 | long N = n; 6 | return N > 0 ? quickMul(x, N) : 1 / quickMul(x, -N); 7 | } 8 | 9 | public double quickMul(double x, long N) { 10 | if (N == 0) { 11 | return 1; 12 | } 13 | double y = quickMul(x, N / 2); 14 | return N % 2 == 0 ? y * y : y * y * x; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /java-jvmpre/delombok/src-bak/src/main/java/som/hks/securityManager/MySecurityManager.java: -------------------------------------------------------------------------------- 1 | package som.hks.securityManager; 2 | 3 | /** 4 | * 第一步,定义一个类继承自SecurityManger重写它的checkRead方(如果你有兴趣可以先跳到super.checkRead(file, context); 5 | * 6 | */ 7 | public class MySecurityManager extends SecurityManager{ 8 | 9 | @Override 10 | public void checkRead(String file) { 11 | //super.checkRead(file, context); 12 | if (file.endsWith("test")) 13 | throw new SecurityException("你没有读取的本文件的权限"); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /java-jvmpre/delombok/src-bak/src/main/java/som/hks/aceessControler/MySecurityManager.java: -------------------------------------------------------------------------------- 1 | package som.hks.aceessControler; 2 | 3 | /** 4 | * 第一步:实现一个自己的类MySecurityManager,它继承自SecurityManager, 5 | * 重写它的checkRead方法,我们直接让他抛出一个SecurityException异常。 6 | * (copy吧少年,要的是你知识的储备,不是要你把代码背下来) 7 | */ 8 | public class MySecurityManager extends SecurityManager{ 9 | 10 | @Override 11 | public void checkRead(String file) { 12 | //super.checkRead(file, context); 13 | throw new SecurityException("你没有的权限"); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /java-jvmpre/delombok/src-bak/src/main/java/som/hks/oom/PutInEden2.java: -------------------------------------------------------------------------------- 1 | package som.hks.oom; 2 | 3 | /** 4 | * -XX:+PrintGCDetails -Xmx1000M -Xms500M -Xmn100M -XX:SurvivorRatio=8 5 | * 6 | */ 7 | public class PutInEden2 { 8 | public static void main(String[] args){ 9 | byte[] b1,b2,b3; 10 | b1=new byte[1024*512];//分配 0.5MB 堆空间 11 | b2=new byte[1024*1024*4];//分配 4MB 堆空间 12 | b3=new byte[1024*1024*4]; 13 | b3=null; //使 b3 可以被回收 14 | b3=new byte[1024*1024*4];//分配 4MB 堆空间 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /java-object/src/main/java/com/hks/enumClass/Sample.java: -------------------------------------------------------------------------------- 1 | package com.hks.enumClass; 2 | 3 | public class Sample { 4 | enum Size { 5 | Small(0.8), 6 | Medium(1.0), 7 | Large(1.2); 8 | double pricingFactor; 9 | Size(double p) { 10 | pricingFactor = p; 11 | } 12 | } 13 | public static void main(String args[]) { 14 | Size s = Size.Large; 15 | double d = s.pricingFactor; 16 | System.out.println(s + " Size has pricing factor of " + d); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /java-algorithms/src/main/java/com/hks/eightsortingalgorithms/leetcode/firstUniqChar.java: -------------------------------------------------------------------------------- 1 | package com.hks.eightsortingalgorithms.leetcode; 2 | 3 | import java.util.HashMap; 4 | 5 | public class firstUniqChar { 6 | public char firstUniqChar(String s) { 7 | HashMap dic = new HashMap<>(); 8 | char[] sc = s.toCharArray(); 9 | for(char c : sc) 10 | dic.put(c, !dic.containsKey(c)); 11 | for(char c : sc) 12 | if(dic.get(c)) return c; 13 | return ' '; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /java-algorithms/src/main/java/com/hks/eightsortingalgorithms/leetcode/mySqrt.java: -------------------------------------------------------------------------------- 1 | package com.hks.eightsortingalgorithms.leetcode; 2 | 3 | public class mySqrt { 4 | 5 | public int mySqrt(int x) { 6 | int l = 0, r = x, ans = -1; 7 | while (l <= r) { 8 | int mid = l + (r - l) / 2; 9 | if ((long) mid * mid <= x) { 10 | ans = mid; 11 | l = mid + 1; 12 | } else { 13 | r = mid - 1; 14 | } 15 | } 16 | return ans; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /java-object/delombok/src-bak/src/main/java/com/hks/enumClass/Sample.java: -------------------------------------------------------------------------------- 1 | package com.hks.enumClass; 2 | 3 | public class Sample { 4 | enum Size { 5 | Small(0.8), 6 | Medium(1.0), 7 | Large(1.2); 8 | double pricingFactor; 9 | Size(double p) { 10 | pricingFactor = p; 11 | } 12 | } 13 | public static void main(String args[]) { 14 | Size s = Size.Large; 15 | double d = s.pricingFactor; 16 | System.out.println(s + " Size has pricing factor of " + d); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /java-8stream/src/main/java/com/heks/stream/NextItemEvalProcess.java: -------------------------------------------------------------------------------- 1 | package com.heks.stream; 2 | 3 | /** 4 | * @author heks 5 | * @description: TODO 6 | * @date 2020/11/11 7 | */ 8 | /** 9 | * 下一个元素求值过程 10 | */ 11 | public class NextItemEvalProcess { 12 | 13 | /** 14 | * 求值方法 15 | * */ 16 | private EvalFunction evalFunction; 17 | 18 | public NextItemEvalProcess(EvalFunction evalFunction) { 19 | this.evalFunction = evalFunction; 20 | } 21 | 22 | MyStream eval(){ 23 | return evalFunction.apply(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /java-algorithms/src/main/java/com/hks/eightsortingalgorithms/method/search/BinarySearch.java: -------------------------------------------------------------------------------- 1 | package com.hks.eightsortingalgorithms.method.search; 2 | 3 | /** 4 | * @Author: hekuangsheng 5 | * @Date: 2018/11/21 6 | */ 7 | public interface BinarySearch { 8 | 9 | /** 10 | * 二分查找又称折半查找,它是一种效率较高的查找方法。 【二分查找要求】:1.必须采用顺序存储结构 2.必须按关键字大小有序排列。 11 | * 12 | * @param intArr 13 | * 有序数组 * 14 | * @param key 15 | * 查找元素 * 16 | * @return searchKey的数组下标,没找到返回-1 17 | */ 18 | int search(int[] intArr, int key); 19 | } 20 | -------------------------------------------------------------------------------- /java-algorithms/src/main/java/com/hks/eightsortingalgorithms/leetcode/maxSubArray.java: -------------------------------------------------------------------------------- 1 | package com.hks.eightsortingalgorithms.leetcode; 2 | 3 | public class maxSubArray { 4 | public int maxSubArray(int[] nums) { 5 | if(nums==null||nums.length==0) { 6 | return -1; 7 | } 8 | 9 | int sumSub = 0; 10 | int max = nums[0]; 11 | for (int i = 0; i < nums.length; i++) { 12 | sumSub = Math.max(sumSub+nums[i], nums[i]); 13 | max = Math.max(max, sumSub); 14 | } 15 | return max; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /java-8stream/delombok/src-bak/src/main/java/com/heks/stream/NextItemEvalProcess.java: -------------------------------------------------------------------------------- 1 | package com.heks.stream; 2 | 3 | /** 4 | * @author heks 5 | * @description: TODO 6 | * @date 2020/11/11 7 | */ 8 | /** 9 | * 下一个元素求值过程 10 | */ 11 | public class NextItemEvalProcess { 12 | 13 | /** 14 | * 求值方法 15 | * */ 16 | private EvalFunction evalFunction; 17 | 18 | public NextItemEvalProcess(EvalFunction evalFunction) { 19 | this.evalFunction = evalFunction; 20 | } 21 | 22 | MyStream eval(){ 23 | return evalFunction.apply(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /java-8stream/src/main/java/com/heks/stream/Person.java: -------------------------------------------------------------------------------- 1 | package com.heks.stream; 2 | 3 | /** 4 | * @author heks 5 | * @description: TODO 6 | * @date 2020/11/11 7 | */ 8 | public class Person { 9 | private int age; 10 | 11 | private String name; 12 | 13 | public int getAge() { 14 | return age; 15 | } 16 | 17 | public void setAge(int age) { 18 | this.age = age; 19 | } 20 | 21 | public String getName() { 22 | return name; 23 | } 24 | 25 | public void setName(String name) { 26 | this.name = name; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /java-object/src/main/java/com/hks/valuePass/Person.java: -------------------------------------------------------------------------------- 1 | package com.hks.valuePass; 2 | 3 | /** 4 | * @Author: hekuangsheng 5 | * @Date: 2018/10/29 6 | */ 7 | public class Person { 8 | 9 | private int age; 10 | 11 | private String name; 12 | 13 | public int getAge() { 14 | return age; 15 | } 16 | 17 | public void setAge(int age) { 18 | this.age = age; 19 | } 20 | 21 | public String getName() { 22 | return name; 23 | } 24 | 25 | public void setName(String name) { 26 | this.name = name; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /java-collectors/src/main/java/com/hks/hashmap/HashMapKeyTest.java: -------------------------------------------------------------------------------- 1 | package com.hks.hashmap; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | public class HashMapKeyTest { 7 | 8 | public static void main(String[] args) { 9 | Map map = new HashMap(); 10 | A a1 = new A(); 11 | a1.setCode("123"); 12 | a1.setName("456"); 13 | map.put(a1, "test1"); 14 | System.out.println(map); 15 | a1.setCode("789"); 16 | map.put(a1, "test2"); 17 | System.out.println(map); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /java-jvmpre/src/main/java/som/hks/oom/BigObj2Old.java: -------------------------------------------------------------------------------- 1 | package som.hks.oom; 2 | 3 | /** 4 | * 软件开发过程中,应该尽可能避免使用短命的大对象。 5 | * 可以使用参数-XX:PetenureSizeThreshold 设置大对象直接进入年老代的阈值。 6 | * 当对象的大小超过这个值时,将直接在年老代分配。 7 | * 参数-XX:PetenureSizeThreshold 只对串行收集器和年轻代并行收集器有效,并行回收收集器不识别这个参数 8 | * 9 | * -XX:+PrintGCDetails –Xmx20M –Xms20MB 10 | * -XX:+PrintGCDetails –Xmx20M –Xms20MB -XX:PetenureSizeThreshold=1000000 11 | */ 12 | public class BigObj2Old { 13 | 14 | public static void main(String[] args){ 15 | byte[] b; 16 | b = new byte[1024*1024];//分配一个 1MB 的对象 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /java-algorithms/src/main/java/com/hks/eightsortingalgorithms/leetcode/findPeakElement.java: -------------------------------------------------------------------------------- 1 | package com.hks.eightsortingalgorithms.leetcode; 2 | 3 | public class findPeakElement { 4 | 5 | public int findPeakElement(int[] nums) { 6 | int left = 0, right = nums.length - 1; 7 | while (left < right) { 8 | int mid = left + (right - left) / 2; 9 | if (nums[mid] > nums[mid + 1]) { 10 | right = mid; 11 | } else { 12 | left = mid + 1; 13 | } 14 | } 15 | return left; 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /java-jvmpre/src/test/java/com/hks/JavaVMStackSOF.java: -------------------------------------------------------------------------------- 1 | package com.hks; 2 | 3 | //-Xss160k 4 | public class JavaVMStackSOF { 5 | private int stackLength = 1; 6 | 7 | public void stackLeak(){ 8 | stackLength++; 9 | stackLeak(); 10 | } 11 | 12 | public static void main(String[] args) throws Throwable{ 13 | JavaVMStackSOF oom = new JavaVMStackSOF(); 14 | try{ 15 | oom.stackLeak(); 16 | } catch (Exception ex){ 17 | System.out.println(ex.getStackTrace().length); 18 | throw ex; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /java-8stream/delombok/src-bak/src/main/java/com/heks/stream/Person.java: -------------------------------------------------------------------------------- 1 | package com.heks.stream; 2 | 3 | /** 4 | * @author heks 5 | * @description: TODO 6 | * @date 2020/11/11 7 | */ 8 | public class Person { 9 | private int age; 10 | 11 | private String name; 12 | 13 | public int getAge() { 14 | return age; 15 | } 16 | 17 | public void setAge(int age) { 18 | this.age = age; 19 | } 20 | 21 | public String getName() { 22 | return name; 23 | } 24 | 25 | public void setName(String name) { 26 | this.name = name; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /java-annotation/src/main/java/com/hks/annotation/Greeting.java: -------------------------------------------------------------------------------- 1 | package com.hks.annotation; 2 | 3 | 4 | import java.lang.annotation.Inherited; 5 | 6 | /** 7 | * @Inherited 元注解是一个标记注解,@Inherited阐述了某个被标注的类型是被继承的。 8 | * 如果一个使用了@Inherited修饰的annotation类型被用于一个class,则这个annotation将被用于该class的子类。 9 | 10 |   注意:@Inherited annotation类型是被标注过的class的子类所继承。 11 | 类并不从它所实现的接口继承annotation,方法并不从它所重载的方法继承annotation。 12 | */ 13 | @Inherited 14 | public @interface Greeting { 15 | 16 | enum FontColor{ BULE,RED,GREEN}; 17 | String name(); 18 | FontColor fontColor() default FontColor.GREEN; 19 | 20 | } 21 | -------------------------------------------------------------------------------- /java-object/delombok/src-bak/src/main/java/com/hks/valuePass/Person.java: -------------------------------------------------------------------------------- 1 | package com.hks.valuePass; 2 | 3 | /** 4 | * @Author: hekuangsheng 5 | * @Date: 2018/10/29 6 | */ 7 | public class Person { 8 | 9 | private int age; 10 | 11 | private String name; 12 | 13 | public int getAge() { 14 | return age; 15 | } 16 | 17 | public void setAge(int age) { 18 | this.age = age; 19 | } 20 | 21 | public String getName() { 22 | return name; 23 | } 24 | 25 | public void setName(String name) { 26 | this.name = name; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /java-collectors/delombok/src-bak/src/main/java/com/hks/hashmap/HashMapKeyTest.java: -------------------------------------------------------------------------------- 1 | package com.hks.hashmap; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | public class HashMapKeyTest { 7 | 8 | public static void main(String[] args) { 9 | Map map = new HashMap(); 10 | A a1 = new A(); 11 | a1.setCode("123"); 12 | a1.setName("456"); 13 | map.put(a1, "test1"); 14 | System.out.println(map); 15 | a1.setCode("789"); 16 | map.put(a1, "test2"); 17 | System.out.println(map); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /java-jvmpre/delombok/src-bak/src/main/java/som/hks/oom/BigObj2Old.java: -------------------------------------------------------------------------------- 1 | package som.hks.oom; 2 | 3 | /** 4 | * 软件开发过程中,应该尽可能避免使用短命的大对象。 5 | * 可以使用参数-XX:PetenureSizeThreshold 设置大对象直接进入年老代的阈值。 6 | * 当对象的大小超过这个值时,将直接在年老代分配。 7 | * 参数-XX:PetenureSizeThreshold 只对串行收集器和年轻代并行收集器有效,并行回收收集器不识别这个参数 8 | * 9 | * -XX:+PrintGCDetails –Xmx20M –Xms20MB 10 | * -XX:+PrintGCDetails –Xmx20M –Xms20MB -XX:PetenureSizeThreshold=1000000 11 | */ 12 | public class BigObj2Old { 13 | 14 | public static void main(String[] args){ 15 | byte[] b; 16 | b = new byte[1024*1024];//分配一个 1MB 的对象 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /java-algorithms/src/main/java/com/hks/eightsortingalgorithms/leetcode/minimumTotal.java: -------------------------------------------------------------------------------- 1 | package com.hks.eightsortingalgorithms.leetcode; 2 | 3 | import java.util.List; 4 | 5 | public class minimumTotal { 6 | public int minimumTotal(List> triangle) { 7 | int n = triangle.size(); 8 | int[][] dp = new int[n + 1][n + 1]; 9 | for (int i = n - 1; i >= 0; i--) { 10 | for (int j = 0; j <= i; j++) { 11 | dp[i][j] = Math.min(dp[i+1][j], dp[i+1][j+1])+triangle.get(i).get(j); 12 | } 13 | } 14 | return dp[0][0]; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /java-annotation/delombok/src-bak/src/main/java/com/hks/annotation/Greeting.java: -------------------------------------------------------------------------------- 1 | package com.hks.annotation; 2 | 3 | 4 | import java.lang.annotation.Inherited; 5 | 6 | /** 7 | * @Inherited 元注解是一个标记注解,@Inherited阐述了某个被标注的类型是被继承的。 8 | * 如果一个使用了@Inherited修饰的annotation类型被用于一个class,则这个annotation将被用于该class的子类。 9 | 10 |   注意:@Inherited annotation类型是被标注过的class的子类所继承。 11 | 类并不从它所实现的接口继承annotation,方法并不从它所重载的方法继承annotation。 12 | */ 13 | @Inherited 14 | public @interface Greeting { 15 | 16 | enum FontColor{ BULE,RED,GREEN}; 17 | String name(); 18 | FontColor fontColor() default FontColor.GREEN; 19 | 20 | } 21 | -------------------------------------------------------------------------------- /java-jvmpre/delombok/src-bak/src/test/java/com/hks/JavaVMStackSOF.java: -------------------------------------------------------------------------------- 1 | package com.hks; 2 | 3 | //-Xss160k 4 | public class JavaVMStackSOF { 5 | private int stackLength = 1; 6 | 7 | public void stackLeak(){ 8 | stackLength++; 9 | stackLeak(); 10 | } 11 | 12 | public static void main(String[] args) throws Throwable{ 13 | JavaVMStackSOF oom = new JavaVMStackSOF(); 14 | try{ 15 | oom.stackLeak(); 16 | } catch (Exception ex){ 17 | System.out.println(ex.getStackTrace().length); 18 | throw ex; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /java-classloader/src/test/java/IntegerTest.java: -------------------------------------------------------------------------------- 1 | public class IntegerTest { 2 | 3 | public static void main(String[] args) { 4 | Integer a = 1; 5 | Integer b = 2; 6 | Integer c = 3; 7 | Integer d = 3; 8 | Integer e = 321; 9 | Integer f = 321; 10 | Long g = 3L; 11 | 12 | System.out.println(c == d); 13 | System.out.println(e == f); 14 | System.out.println(c == (a + b)); 15 | System.out.println(c.equals(a + b)); 16 | System.out.println(g == (a + b)); 17 | System.out.println(g.equals(a + b)); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /java-jvmpre/src/test/java/com/hks/DirectMemoryOOM.java: -------------------------------------------------------------------------------- 1 | package com.hks; 2 | 3 | import sun.misc.Unsafe; 4 | 5 | import java.lang.reflect.Field; 6 | 7 | //-XX:MaxDirectMemorySize=10M 8 | public class DirectMemoryOOM { 9 | private static final int _1MB = 1024*1024; 10 | 11 | public static void main(String[] args) throws Exception{ 12 | Field unsafefield = Unsafe.class.getDeclaredFields()[0]; 13 | unsafefield.setAccessible(true); 14 | Unsafe unsafe = (Unsafe) unsafefield.get(null); 15 | while (true){ 16 | unsafe.allocateMemory(_1MB); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /java-lambda/src/main/java/com/hks/lambda/FilterTest.java: -------------------------------------------------------------------------------- 1 | package com.hks.lambda; 2 | 3 | import org.junit.Test; 4 | 5 | import java.util.Arrays; 6 | import java.util.stream.Stream; 7 | 8 | public class FilterTest { 9 | 10 | /** 11 | * filter 对原始 Stream 进行某项测试,通过测试的元素被留下来生成一个新 Stream。 12 | */ 13 | @Test 14 | public void simpleFilterTest(){ 15 | Integer[] sixNums = {1, 2, 3, 4, 5, 6}; 16 | Integer[] evens = 17 | Stream.of(sixNums).filter(n -> n%2 == 0).toArray(Integer[]::new); 18 | 19 | Arrays.stream(evens).forEach(System.out::println); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /java-annotation/src/main/java/com/hks/annotation/FruitProvider.java: -------------------------------------------------------------------------------- 1 | package com.hks.annotation; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * 水果供应者注解 7 | * @author peida 8 | * 9 | */ 10 | @Target(ElementType.FIELD) 11 | @Retention(RetentionPolicy.RUNTIME) 12 | @Documented 13 | public @interface FruitProvider { 14 | /** 15 | * 供应商编号 16 | * @return 17 | */ 18 | int id() default -1; 19 | 20 | /** 21 | * 供应商名称 22 | * @return 23 | */ 24 | String name() default ""; 25 | 26 | /** 27 | * 供应商地址 28 | * @return 29 | */ 30 | String address() default ""; 31 | } 32 | -------------------------------------------------------------------------------- /java-aspect/src/main/java/com/hks/agent/Agent.java: -------------------------------------------------------------------------------- 1 | package com.hks.agent; 2 | 3 | import java.lang.instrument.Instrumentation; 4 | 5 | /** 6 | * Agent 类必须打成jar包,然后里面的 META-INF/MAINIFEST.MF 必须包含 Premain-Class这个属性。 7 | 下面是一个MANIFEST.MF的例子: 8 | --------------------- 9 | Manifest-Version: 1.0 10 | Premain-Class:MyAgent1 11 | Created-By:1.6.0_06 12 | --------------------- 13 | 然后把MANIFEST.MF 加入到你的jar包中。 14 | */ 15 | public class Agent { 16 | public static void premain(String args, Instrumentation inst){ 17 | System.out.println("Hi, I'm agent!"); 18 | inst.addTransformer(new TestTransformer()); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /java-classloader/delombok/src-bak/src/test/java/IntegerTest.java: -------------------------------------------------------------------------------- 1 | public class IntegerTest { 2 | 3 | public static void main(String[] args) { 4 | Integer a = 1; 5 | Integer b = 2; 6 | Integer c = 3; 7 | Integer d = 3; 8 | Integer e = 321; 9 | Integer f = 321; 10 | Long g = 3L; 11 | 12 | System.out.println(c == d); 13 | System.out.println(e == f); 14 | System.out.println(c == (a + b)); 15 | System.out.println(c.equals(a + b)); 16 | System.out.println(g == (a + b)); 17 | System.out.println(g.equals(a + b)); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /java-jvmpre/delombok/src-bak/src/test/java/com/hks/DirectMemoryOOM.java: -------------------------------------------------------------------------------- 1 | package com.hks; 2 | 3 | import sun.misc.Unsafe; 4 | 5 | import java.lang.reflect.Field; 6 | 7 | //-XX:MaxDirectMemorySize=10M 8 | public class DirectMemoryOOM { 9 | private static final int _1MB = 1024*1024; 10 | 11 | public static void main(String[] args) throws Exception{ 12 | Field unsafefield = Unsafe.class.getDeclaredFields()[0]; 13 | unsafefield.setAccessible(true); 14 | Unsafe unsafe = (Unsafe) unsafefield.get(null); 15 | while (true){ 16 | unsafe.allocateMemory(_1MB); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /java-lambda/delombok/src-bak/src/main/java/com/hks/lambda/FilterTest.java: -------------------------------------------------------------------------------- 1 | package com.hks.lambda; 2 | 3 | import org.junit.Test; 4 | 5 | import java.util.Arrays; 6 | import java.util.stream.Stream; 7 | 8 | public class FilterTest { 9 | 10 | /** 11 | * filter 对原始 Stream 进行某项测试,通过测试的元素被留下来生成一个新 Stream。 12 | */ 13 | @Test 14 | public void simpleFilterTest(){ 15 | Integer[] sixNums = {1, 2, 3, 4, 5, 6}; 16 | Integer[] evens = 17 | Stream.of(sixNums).filter(n -> n%2 == 0).toArray(Integer[]::new); 18 | 19 | Arrays.stream(evens).forEach(System.out::println); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /java-algorithms/src/main/java/com/hks/eightsortingalgorithms/leetcode/convertToTitle.java: -------------------------------------------------------------------------------- 1 | package com.hks.eightsortingalgorithms.leetcode; 2 | 3 | public class convertToTitle { 4 | 5 | public static void main(String[] args) { 6 | String s = convertToTitle(77); 7 | System.out.println(s); 8 | } 9 | 10 | public static String convertToTitle(int cn) { 11 | StringBuilder sb = new StringBuilder(); 12 | while(cn>0) { 13 | cn--; 14 | sb.append((char)(cn%26 + 'A')); 15 | cn = cn /26; 16 | } 17 | sb.reverse(); 18 | return sb.toString(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /java-annotation/delombok/src-bak/src/main/java/com/hks/annotation/FruitProvider.java: -------------------------------------------------------------------------------- 1 | package com.hks.annotation; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * 水果供应者注解 7 | * @author peida 8 | * 9 | */ 10 | @Target(ElementType.FIELD) 11 | @Retention(RetentionPolicy.RUNTIME) 12 | @Documented 13 | public @interface FruitProvider { 14 | /** 15 | * 供应商编号 16 | * @return 17 | */ 18 | int id() default -1; 19 | 20 | /** 21 | * 供应商名称 22 | * @return 23 | */ 24 | String name() default ""; 25 | 26 | /** 27 | * 供应商地址 28 | * @return 29 | */ 30 | String address() default ""; 31 | } 32 | -------------------------------------------------------------------------------- /java-aspect/delombok/src-bak/src/main/java/com/hks/agent/Agent.java: -------------------------------------------------------------------------------- 1 | package com.hks.agent; 2 | 3 | import java.lang.instrument.Instrumentation; 4 | 5 | /** 6 | * Agent 类必须打成jar包,然后里面的 META-INF/MAINIFEST.MF 必须包含 Premain-Class这个属性。 7 | 下面是一个MANIFEST.MF的例子: 8 | --------------------- 9 | Manifest-Version: 1.0 10 | Premain-Class:MyAgent1 11 | Created-By:1.6.0_06 12 | --------------------- 13 | 然后把MANIFEST.MF 加入到你的jar包中。 14 | */ 15 | public class Agent { 16 | public static void premain(String args, Instrumentation inst){ 17 | System.out.println("Hi, I'm agent!"); 18 | inst.addTransformer(new TestTransformer()); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /java-object/src/main/java/com/hks/enumClass/Sample2.java: -------------------------------------------------------------------------------- 1 | package com.hks.enumClass; 2 | 3 | public class Sample2 { 4 | enum Size { 5 | Small(0.8), 6 | Medium(1.0), 7 | Large(1.2); 8 | private double pricingFactor; 9 | Size(double p) { 10 | pricingFactor = p; 11 | } 12 | public double getPricingFactor() { 13 | return pricingFactor; 14 | } 15 | } 16 | public static void main(String args[]) { 17 | Size s = Size.Large; 18 | double d = s.getPricingFactor(); 19 | System.out.println(s + " Size has pricing factor of " + d); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /java-collectors/src/main/java/com/hks/genericity/Dog.java: -------------------------------------------------------------------------------- 1 | package com.hks.genericity; 2 | 3 | public class Dog extends Animal { 4 | private String name; 5 | private int age; 6 | public Dog(String type,String describe,String name,int age){ 7 | super(type,describe); 8 | this.name = name; 9 | this.age = age; 10 | } 11 | public String getName() { 12 | return name; 13 | } 14 | public void setName(String name) { 15 | this.name = name; 16 | } 17 | public int getAge() { 18 | return age; 19 | } 20 | public void setAge(int age) { 21 | this.age = age; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /java-object/delombok/src-bak/src/main/java/com/hks/enumClass/Sample2.java: -------------------------------------------------------------------------------- 1 | package com.hks.enumClass; 2 | 3 | public class Sample2 { 4 | enum Size { 5 | Small(0.8), 6 | Medium(1.0), 7 | Large(1.2); 8 | private double pricingFactor; 9 | Size(double p) { 10 | pricingFactor = p; 11 | } 12 | public double getPricingFactor() { 13 | return pricingFactor; 14 | } 15 | } 16 | public static void main(String args[]) { 17 | Size s = Size.Large; 18 | double d = s.getPricingFactor(); 19 | System.out.println(s + " Size has pricing factor of " + d); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /java-agent/readme.md: -------------------------------------------------------------------------------- 1 | # javaagent-example 2 | Example of how to instrument the java class files on class loading. 3 | You can change(instrument) the byte code without changing the java source file and recompiling. 4 | # Usage 5 | Package the agent jar file. 6 | ``` 7 | mvn clean package 8 | ``` 9 | 10 | Find the packaged jar file in target directory and add it to the java command line options. 11 | For example. 12 | ```$xslt 13 | java -javaagent:/Users/xueqiu/github/java-base/java-agent/target/java-agent-1.0-SNAPSHOT-jar-with-dependencies.jar Test 14 | ``` 15 | 16 | Most processing happens in `com.hks.agent.AgentMain`, you can change it and add your own logic. 17 | 18 | Have Fun! -------------------------------------------------------------------------------- /java-collectors/delombok/src-bak/src/main/java/com/hks/genericity/Dog.java: -------------------------------------------------------------------------------- 1 | package com.hks.genericity; 2 | 3 | public class Dog extends Animal { 4 | private String name; 5 | private int age; 6 | public Dog(String type,String describe,String name,int age){ 7 | super(type,describe); 8 | this.name = name; 9 | this.age = age; 10 | } 11 | public String getName() { 12 | return name; 13 | } 14 | public void setName(String name) { 15 | this.name = name; 16 | } 17 | public int getAge() { 18 | return age; 19 | } 20 | public void setAge(int age) { 21 | this.age = age; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /java-object/src/main/java/com/hks/PrecisionDemo.java: -------------------------------------------------------------------------------- 1 | package com.hks; 2 | 3 | public class PrecisionDemo { 4 | 5 | public static void main(String[] args){ 6 | float calNum1; 7 | double calNum2; 8 | calNum1 = (float)(1.03-.42); 9 | calNum2 = 1.03-.42; 10 | System.out.println("calNum1="+ calNum1); 11 | System.out.println("calNum2="+ calNum2); 12 | System.out.println(1.03-.42); 13 | calNum1 = (float)(1.00-9*.10); 14 | calNum2 = 1.00-9*.10; 15 | System.out.println("calNum1="+ calNum1); 16 | System.out.println("calNum2="+ calNum2); 17 | System.out.println(1.00-9*.10); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /java-algorithms/src/main/java/com/hks/eightsortingalgorithms/leetcode/findDuplicate.java: -------------------------------------------------------------------------------- 1 | package com.hks.eightsortingalgorithms.leetcode; 2 | 3 | public class findDuplicate { 4 | public int findDuplicate(int[] nums) { 5 | int slow = 0; 6 | int fast = 0; 7 | slow = nums[slow]; 8 | fast = nums[nums[fast]]; 9 | while(slow != fast){ 10 | slow = nums[slow]; 11 | fast = nums[nums[fast]]; 12 | } 13 | int pre1 = 0; 14 | int pre2 = slow; 15 | while(pre1 != pre2){ 16 | pre1 = nums[pre1]; 17 | pre2 = nums[pre2]; 18 | } 19 | return pre1; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /java-object/delombok/src-bak/src/main/java/com/hks/PrecisionDemo.java: -------------------------------------------------------------------------------- 1 | package com.hks; 2 | 3 | public class PrecisionDemo { 4 | 5 | public static void main(String[] args){ 6 | float calNum1; 7 | double calNum2; 8 | calNum1 = (float)(1.03-.42); 9 | calNum2 = 1.03-.42; 10 | System.out.println("calNum1="+ calNum1); 11 | System.out.println("calNum2="+ calNum2); 12 | System.out.println(1.03-.42); 13 | calNum1 = (float)(1.00-9*.10); 14 | calNum2 = 1.00-9*.10; 15 | System.out.println("calNum1="+ calNum1); 16 | System.out.println("calNum2="+ calNum2); 17 | System.out.println(1.00-9*.10); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /java-collectors/src/main/java/com/hks/genericity/Animal.java: -------------------------------------------------------------------------------- 1 | package com.hks.genericity; 2 | 3 | public class Animal { 4 | 5 | private String type; 6 | private String describe; 7 | public Animal(){ 8 | 9 | } 10 | public Animal(String type,String describe){ 11 | this.type = type; 12 | this.describe = describe; 13 | } 14 | public String getType() { 15 | return type; 16 | } 17 | public void setType(String type) { 18 | this.type = type; 19 | } 20 | public String getDescribe() { 21 | return describe; 22 | } 23 | public void setDescribe(String describe) { 24 | this.describe = describe; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /java-proxy/src/main/java/com/hks/proxy/cglib/CglibProxyTest.java: -------------------------------------------------------------------------------- 1 | package com.hks.proxy.cglib; 2 | 3 | import com.hks.proxy.UserService; 4 | import com.hks.proxy.UserServiceImpl; 5 | 6 | import net.sf.cglib.proxy.Enhancer; 7 | 8 | public class CglibProxyTest { 9 | 10 | public static void main(String[] args) { 11 | MyMethodInterceptor myMethodInterceptor = new MyMethodInterceptor(); 12 | 13 | Enhancer enhancer = new Enhancer(); 14 | enhancer.setSuperclass(UserServiceImpl.class); 15 | enhancer.setCallback(myMethodInterceptor); 16 | 17 | UserService o = (UserService)enhancer.create(); 18 | o.getName(1); 19 | o.getAge(1); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /java-algorithms/src/main/java/com/hks/eightsortingalgorithms/leetcode/coinChange.java: -------------------------------------------------------------------------------- 1 | package com.hks.eightsortingalgorithms.leetcode; 2 | 3 | import java.util.Arrays; 4 | 5 | public class coinChange { 6 | public int coinChange(int[] coins, int amount) { 7 | int[] dp = new int[amount + 1]; 8 | Arrays.fill(dp, amount + 1); 9 | dp[0] = 0; 10 | for (int i = 1; i <= amount; i++) { 11 | for (int j = 0; j < coins.length; j++) { 12 | if (coins[i] <= i) { 13 | dp[i] = Math.min(dp[i], dp[i - coins[j]] + 1); 14 | } 15 | } 16 | } 17 | return (dp[amount] > amount) ? -1 : dp[amount]; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /java-collectors/delombok/src-bak/src/main/java/com/hks/genericity/Animal.java: -------------------------------------------------------------------------------- 1 | package com.hks.genericity; 2 | 3 | public class Animal { 4 | 5 | private String type; 6 | private String describe; 7 | public Animal(){ 8 | 9 | } 10 | public Animal(String type,String describe){ 11 | this.type = type; 12 | this.describe = describe; 13 | } 14 | public String getType() { 15 | return type; 16 | } 17 | public void setType(String type) { 18 | this.type = type; 19 | } 20 | public String getDescribe() { 21 | return describe; 22 | } 23 | public void setDescribe(String describe) { 24 | this.describe = describe; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /java-factory/src/main/java/com/hks/factory/FoodFactory.java: -------------------------------------------------------------------------------- 1 | package com.hks.factory; 2 | 3 | /** 4 | * @Author: hekuangsheng 5 | * @Date: 2018/10/23 6 | 7 | * 通过反射机制实现的工厂 8 | */ 9 | public class FoodFactory { 10 | 11 | public static Food getFood(String type) { 12 | Food food = null; 13 | try { 14 | food = (Food) Class.forName("com.hks.factory." + type).newInstance(); 15 | } catch (ClassNotFoundException e) { 16 | e.printStackTrace(); 17 | } catch (InstantiationException e) { 18 | e.printStackTrace(); 19 | } catch (IllegalAccessException e) { 20 | e.printStackTrace(); 21 | } 22 | return food; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /java-proxy/delombok/src-bak/src/main/java/com/hks/proxy/cglib/CglibProxyTest.java: -------------------------------------------------------------------------------- 1 | package com.hks.proxy.cglib; 2 | 3 | import com.hks.proxy.UserService; 4 | import com.hks.proxy.UserServiceImpl; 5 | 6 | import net.sf.cglib.proxy.Enhancer; 7 | 8 | public class CglibProxyTest { 9 | 10 | public static void main(String[] args) { 11 | MyMethodInterceptor myMethodInterceptor = new MyMethodInterceptor(); 12 | 13 | Enhancer enhancer = new Enhancer(); 14 | enhancer.setSuperclass(UserServiceImpl.class); 15 | enhancer.setCallback(myMethodInterceptor); 16 | 17 | UserService o = (UserService)enhancer.create(); 18 | o.getName(1); 19 | o.getAge(1); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /java-jvmpre/src/main/java/som/hks/securityManager/TestMySecurityManager.java: -------------------------------------------------------------------------------- 1 | package som.hks.securityManager; 2 | 3 | import java.io.FileInputStream; 4 | import java.io.IOException; 5 | 6 | /** 7 | * 第二步,定义一个有main函数的public类来验证自己的安全管理器是不是器作用了。 8 | */ 9 | public class TestMySecurityManager { 10 | 11 | public static void main(String[] args) { 12 | System.setSecurityManager(new MySecurityManager()); 13 | try { 14 | FileInputStream fis = new FileInputStream("test"); 15 | System.out.println(fis.read()); 16 | } catch (IOException e) { 17 | e.printStackTrace(); 18 | } 19 | 20 | } 21 | 22 | /** 23 | * 第三步,运行代码查看控制台输出 24 | */ 25 | 26 | 27 | } 28 | -------------------------------------------------------------------------------- /java-proxy/src/main/java/com/hks/proxy/cglib/MyMethodInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.hks.proxy.cglib; 2 | 3 | import net.sf.cglib.proxy.MethodInterceptor; 4 | import net.sf.cglib.proxy.MethodProxy; 5 | 6 | import java.lang.reflect.Method; 7 | 8 | public class MyMethodInterceptor implements MethodInterceptor { 9 | 10 | @Override 11 | public Object intercept(Object o, Method method, Object[] args, MethodProxy methodProxy) throws Throwable { 12 | System.out.println("++++++before " + methodProxy.getSuperName() + "++++++"); 13 | Object o1 = methodProxy.invokeSuper(o, args); 14 | System.out.println("++++++after " + methodProxy.getSuperName() + "++++++"); 15 | return o1; 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /java-factory/delombok/src-bak/src/main/java/com/hks/factory/FoodFactory.java: -------------------------------------------------------------------------------- 1 | package com.hks.factory; 2 | 3 | /** 4 | * @Author: hekuangsheng 5 | * @Date: 2018/10/23 6 | 7 | * 通过反射机制实现的工厂 8 | */ 9 | public class FoodFactory { 10 | 11 | public static Food getFood(String type) { 12 | Food food = null; 13 | try { 14 | food = (Food) Class.forName("com.hks.factory." + type).newInstance(); 15 | } catch (ClassNotFoundException e) { 16 | e.printStackTrace(); 17 | } catch (InstantiationException e) { 18 | e.printStackTrace(); 19 | } catch (IllegalAccessException e) { 20 | e.printStackTrace(); 21 | } 22 | return food; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /java-object/src/main/java/com/hks/enumClass/EnumMapSample.java: -------------------------------------------------------------------------------- 1 | package com.hks.enumClass; 2 | 3 | import java.util.*; 4 | public class EnumMapSample { 5 | enum Size { 6 | Small, 7 | Medium, 8 | Large; 9 | } 10 | public static void main(String args[]) { 11 | Map map = new EnumMap(Size.class); 12 | map.put(Size.Small, 0.8); 13 | map.put(Size.Medium, 1.0); 14 | map.put(Size.Large, 1.2); 15 | for (Map.Entry entry : map.entrySet()) { 16 | helper(entry); 17 | } 18 | } 19 | private static void helper(Map.Entry entry) { 20 | System.out.println("Map entry: " + entry); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /java-proxy/delombok/src-bak/src/main/java/com/hks/proxy/cglib/MyMethodInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.hks.proxy.cglib; 2 | 3 | import net.sf.cglib.proxy.MethodInterceptor; 4 | import net.sf.cglib.proxy.MethodProxy; 5 | 6 | import java.lang.reflect.Method; 7 | 8 | public class MyMethodInterceptor implements MethodInterceptor { 9 | 10 | @Override 11 | public Object intercept(Object o, Method method, Object[] args, MethodProxy methodProxy) throws Throwable { 12 | System.out.println("++++++before " + methodProxy.getSuperName() + "++++++"); 13 | Object o1 = methodProxy.invokeSuper(o, args); 14 | System.out.println("++++++after " + methodProxy.getSuperName() + "++++++"); 15 | return o1; 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /java-algorithms/src/main/java/com/hks/eightsortingalgorithms/nowcoder/StackToQueue.java: -------------------------------------------------------------------------------- 1 | package com.hks.eightsortingalgorithms.nowcoder; 2 | 3 | import java.util.Stack; 4 | 5 | public class StackToQueue { 6 | public Stack stackPush; 7 | public Stack stackPop; 8 | 9 | public StackToQueue() { 10 | stackPush = new Stack<>(); 11 | stackPop = new Stack<>(); 12 | } 13 | 14 | public void add(int val){ 15 | stackPush.add(val); 16 | } 17 | 18 | public Integer poll(){ 19 | if(stackPop.empty()){ 20 | while(!stackPush.empty()){ 21 | stackPop.add(stackPush.pop()); 22 | } 23 | } 24 | return stackPop.pop(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /java-jvmpre/delombok/src-bak/src/main/java/som/hks/securityManager/TestMySecurityManager.java: -------------------------------------------------------------------------------- 1 | package som.hks.securityManager; 2 | 3 | import java.io.FileInputStream; 4 | import java.io.IOException; 5 | 6 | /** 7 | * 第二步,定义一个有main函数的public类来验证自己的安全管理器是不是器作用了。 8 | */ 9 | public class TestMySecurityManager { 10 | 11 | public static void main(String[] args) { 12 | System.setSecurityManager(new MySecurityManager()); 13 | try { 14 | FileInputStream fis = new FileInputStream("test"); 15 | System.out.println(fis.read()); 16 | } catch (IOException e) { 17 | e.printStackTrace(); 18 | } 19 | 20 | } 21 | 22 | /** 23 | * 第三步,运行代码查看控制台输出 24 | */ 25 | 26 | 27 | } 28 | -------------------------------------------------------------------------------- /java-algorithms/src/main/java/com/hks/eightsortingalgorithms/leetcode/longestCommonSubsequence.java: -------------------------------------------------------------------------------- 1 | package com.hks.eightsortingalgorithms.leetcode; 2 | 3 | public class longestCommonSubsequence { 4 | public int longestCommonSubsequence(String s1, String s2) { 5 | int m = s1.length(), n = s2.length(); 6 | int[][] dp = new int[m+1][n+1]; 7 | 8 | for (int i = 1; i <= m; i++) { 9 | for (int j = 1; j <= n; j++) { 10 | if(s1.charAt(i) == s2.charAt(j)) { 11 | dp[i][j] = dp[i-1][j-1] + 1; 12 | } else { 13 | dp[i][j] = Math.max(dp[i-1][j], dp[i][j-1]); 14 | } 15 | } 16 | } 17 | return dp[m][n]; 18 | } 19 | } -------------------------------------------------------------------------------- /java-algorithms/src/main/java/com/hks/eightsortingalgorithms/leetcode/merge.java: -------------------------------------------------------------------------------- 1 | package com.hks.eightsortingalgorithms.leetcode; 2 | 3 | public class merge { 4 | public void merge(int[] nums1, int m, int[] nums2, int n) { 5 | int p1 = m - 1, p2 = n - 1; 6 | int tail = m + n - 1; 7 | int cur; 8 | while (p1 >= 0 || p2 >= 0) { 9 | if (p1 == -1) { 10 | cur = nums2[p2--]; 11 | } else if (p2 == -1) { 12 | cur = nums1[p1--]; 13 | } else if (nums1[p1] > nums2[p2]) { 14 | cur = nums1[p1--]; 15 | } else { 16 | cur = nums2[p2--]; 17 | } 18 | nums1[tail--] = cur; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /java-annotation/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.hks 8 | java-annotation 9 | 1.0-SNAPSHOT 10 | 11 | 12 | junit 13 | junit 14 | 4.13.1 15 | compile 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /java-object/delombok/src-bak/src/main/java/com/hks/enumClass/EnumMapSample.java: -------------------------------------------------------------------------------- 1 | package com.hks.enumClass; 2 | 3 | import java.util.*; 4 | public class EnumMapSample { 5 | enum Size { 6 | Small, 7 | Medium, 8 | Large; 9 | } 10 | public static void main(String args[]) { 11 | Map map = new EnumMap(Size.class); 12 | map.put(Size.Small, 0.8); 13 | map.put(Size.Medium, 1.0); 14 | map.put(Size.Large, 1.2); 15 | for (Map.Entry entry : map.entrySet()) { 16 | helper(entry); 17 | } 18 | } 19 | private static void helper(Map.Entry entry) { 20 | System.out.println("Map entry: " + entry); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /java-algorithms/src/main/java/com/hks/eightsortingalgorithms/leetcode/getKthFromEnd.java: -------------------------------------------------------------------------------- 1 | package com.hks.eightsortingalgorithms.leetcode; 2 | 3 | public class getKthFromEnd { 4 | public class ListNode { 5 | int val; 6 | ListNode next; 7 | 8 | ListNode(int x) { 9 | val = x; 10 | } 11 | } 12 | 13 | public ListNode getKthFromEnd(ListNode head, int k) { 14 | ListNode fast = head; 15 | ListNode slow = head; 16 | 17 | while (fast != null && k > 0) { 18 | fast = fast.next; 19 | k--; 20 | } 21 | while (fast != null) { 22 | fast = fast.next; 23 | slow = slow.next; 24 | } 25 | 26 | return slow; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /java-btrace/src/main/java/com/hks/btrace/BTraceOnMethodDemo.java: -------------------------------------------------------------------------------- 1 | package com.hks.btrace; 2 | 3 | import java.util.concurrent.TimeUnit; 4 | 5 | public class BTraceOnMethodDemo { 6 | public static void main(String[] args) { 7 | try { 8 | TimeUnit.SECONDS.sleep(15); 9 | } catch (InterruptedException e) { 10 | e.printStackTrace(); 11 | } 12 | System.out.println("start main method..."); 13 | new Thread(() -> { 14 | while (true) { 15 | try { 16 | TimeUnit.SECONDS.sleep(1); 17 | } catch (InterruptedException e) { 18 | e.printStackTrace(); 19 | } 20 | } 21 | }).start(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /java-algorithms/src/main/java/com/hks/eightsortingalgorithms/leetcode/subsets.java: -------------------------------------------------------------------------------- 1 | package com.hks.eightsortingalgorithms.leetcode; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class subsets { 7 | 8 | List> res = new ArrayList<>(); 9 | public List> subsets(int[] nums) { 10 | backtrack(0, nums, new ArrayList()); 11 | return res; 12 | 13 | } 14 | 15 | private void backtrack(int i, int[] nums, ArrayList tmp) { 16 | res.add(new ArrayList<>(tmp)); 17 | for (int j = i; j < nums.length; j++) { 18 | tmp.add(nums[j]); 19 | backtrack(j + 1, nums, tmp); 20 | tmp.remove(tmp.size() - 1); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /java-annotation/src/main/java/com/hks/annotation/Apple.java: -------------------------------------------------------------------------------- 1 | package com.hks.annotation; 2 | 3 | public class Apple { 4 | 5 | @FruitName("Apple") 6 | private String appleName; 7 | 8 | @FruitColor(fruitColor= FruitColor.Color.RED) 9 | private String appleColor; 10 | 11 | public void setAppleColor(String appleColor) { 12 | this.appleColor = appleColor; 13 | } 14 | public String getAppleColor() { 15 | return appleColor; 16 | } 17 | 18 | public void setAppleName(String appleName) { 19 | this.appleName = appleName; 20 | } 21 | 22 | public String getAppleName() { 23 | return appleName; 24 | } 25 | 26 | public void displayName(){ 27 | System.out.println("水果的名字是:苹果"); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /java-jvmpre/src/main/java/som/hks/aceessControler/TestMySecurityManager.java: -------------------------------------------------------------------------------- 1 | package som.hks.aceessControler; 2 | 3 | import java.io.IOException; 4 | 5 | /** 6 | * 第二步:实现一个简单的类,主要用来测试我们自己定义的安全管理器起作用了没有, 7 | * 我们这里借助了FileInputStream,因为FileInputStream会调用安全管理器去校验权限 8 | * 所以用FileInputStream测试我们自己的安全管理器非常的适合。 9 | */ 10 | public class TestMySecurityManager { 11 | 12 | public static void main(String[] args) { 13 | System.setSecurityManager(new MySecurityManager()); 14 | try { 15 | //FileInputStream fis = new FileInputStream("test"); 16 | MyFileInputStream myFileInputStream = new MyFileInputStream("test"); 17 | } catch (IOException e) { 18 | e.printStackTrace(); 19 | } 20 | 21 | } 22 | 23 | 24 | } 25 | -------------------------------------------------------------------------------- /java-jvmpre/src/main/java/som/hks/oom/EqualsOOMTest.java: -------------------------------------------------------------------------------- 1 | package som.hks.oom; 2 | 3 | public class EqualsOOMTest { 4 | 5 | /** 6 | 说明: 对于 Integer var=? 7 | 在-128 至 127 之间的赋值, Integer 对象是在IntegerCache.cache 产生,会复用已有对象, 8 | 这个区间内的 Integer 值可以直接使用==进行判断, 9 | 10 | 但是这个区间之外的所有数据, 11 | 都会在堆上产生,并不会复用已有对象 12 | */ 13 | public static void main(String[] args){ 14 | Integer i1 = 123; 15 | Integer i2 = 123; 16 | System.out.println(i1==i2); 17 | Integer i3 = 129; 18 | Integer i4 = 129; 19 | System.out.println(i3==i4); 20 | System.out.println(i3.equals(i4)); 21 | int i5 = 130; 22 | int i6 = 130; 23 | System.out.println(i5==i6); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /java-algorithms/src/main/java/com/hks/eightsortingalgorithms/leetcode/lengthOfLongestSubstring.java: -------------------------------------------------------------------------------- 1 | package com.hks.eightsortingalgorithms.leetcode; 2 | 3 | import java.util.HashMap; 4 | 5 | public class lengthOfLongestSubstring { 6 | public int lengthOfLongestSubstring(String s) { 7 | if (s.length()==0) return 0; 8 | HashMap map = new HashMap<>(); 9 | int max = 0; 10 | int left = 0; 11 | for(int i = 0; i < s.length(); i ++){ 12 | if(map.containsKey(s.charAt(i))){ 13 | left = Math.max(left, map.get(s.charAt(i)) + 1); 14 | } 15 | map.put(s.charAt(i),i); 16 | max = Math.max(max,i-left+1); 17 | } 18 | return max; 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /java-algorithms/src/main/java/com/hks/eightsortingalgorithms/leetcode/sortColors.java: -------------------------------------------------------------------------------- 1 | package com.hks.eightsortingalgorithms.leetcode; 2 | 3 | public class sortColors { 4 | 5 | public void sortColors(int[] nums) { 6 | int left = 0, right = nums.length - 1; 7 | for (int i = 0; i <= right; i++) { 8 | if (nums[i] == 0) { 9 | swap(nums, left, i); 10 | left++; 11 | } 12 | if (nums[i] == 2) { 13 | swap(nums, right, i); 14 | right--; 15 | i--; 16 | } 17 | } 18 | } 19 | 20 | void swap(int[] nums, int l, int r) { 21 | int tep = nums[l]; 22 | nums[l] = nums[r]; 23 | nums[r] = tep; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /java-aspect/src/main/java/com/hks/asm/MyClassLoader.java: -------------------------------------------------------------------------------- 1 | package com.hks.asm; 2 | 3 | import org.objectweb.asm.Opcodes; 4 | /** 5 | * @Author: hekuangsheng 6 | * @Date: 2018/10/19 7 | * 8 | * 自定义ClassLoader 9 | */ 10 | public class MyClassLoader extends ClassLoader implements Opcodes { 11 | 12 | 13 | public MyClassLoader() { 14 | super(); 15 | } 16 | 17 | public MyClassLoader(ClassLoader parent) { 18 | super(parent); 19 | } 20 | 21 | @Override 22 | public Class loadClass(String name) throws ClassNotFoundException { 23 | return super.loadClass(name); 24 | } 25 | 26 | public Class defineClass(String name, byte[] b){ 27 | return super.defineClass(name, b, 0, b.length); 28 | } 29 | 30 | } 31 | 32 | -------------------------------------------------------------------------------- /java-jvmpre/src/main/java/som/hks/aceessControler/MyFileInputStream.java: -------------------------------------------------------------------------------- 1 | package som.hks.aceessControler; 2 | 3 | import java.io.File; 4 | import java.io.FileNotFoundException; 5 | 6 | /** 7 | * 第一步:编写MyFileInputStream 8 | * (copy吧少年,不要自己狂敲) 9 | */ 10 | public class MyFileInputStream { 11 | 12 | public MyFileInputStream(String name) throws FileNotFoundException { 13 | this(name != null ? new File(name) : null); 14 | } 15 | 16 | public MyFileInputStream(File file) throws FileNotFoundException { 17 | String name = (file != null ? file.getPath() : null); 18 | SecurityManager security = System.getSecurityManager(); 19 | if (security != null) { 20 | security.checkRead(name); 21 | } 22 | } 23 | 24 | 25 | } 26 | -------------------------------------------------------------------------------- /java-object/src/main/java/com/hks/staticClass/ThisClass.java: -------------------------------------------------------------------------------- 1 | package com.hks.staticClass; 2 | 3 | /** 4 | * @Author: hekuangsheng 5 | * @Date: 2018/10/23 6 | * 7 | * 33 8 | * 9 | * 这里面主要考察队this和static的理解。this代表什么? 10 | * this代表当前对象,那么通过new ThisClass()来调用printValue的话,当前对象就是通过new ThisClass()生成的对象。 11 | * 而static变量是被对象所享有的,因此在printValue中的this.value的值毫无疑问是33。 12 | * 13 | * 静态成员变量虽然独立于对象,但是不代表不可以通过对象去访问,所有的静态方法和静态变量都可以通过对象访问(只要访问权限足够) 14 | */ 15 | public class ThisClass { 16 | 17 | static int value = 33; 18 | 19 | public static void main(String[] args) throws Exception { 20 | new ThisClass().printValue(); 21 | } 22 | 23 | private void printValue() { 24 | int value = 3; 25 | System.out.println(this.value); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /java-btrace/delombok/src-bak/src/main/java/com/hks/btrace/BTraceOnMethodDemo.java: -------------------------------------------------------------------------------- 1 | package com.hks.btrace; 2 | 3 | import java.util.concurrent.TimeUnit; 4 | 5 | public class BTraceOnMethodDemo { 6 | public static void main(String[] args) { 7 | try { 8 | TimeUnit.SECONDS.sleep(15); 9 | } catch (InterruptedException e) { 10 | e.printStackTrace(); 11 | } 12 | System.out.println("start main method..."); 13 | new Thread(() -> { 14 | while (true) { 15 | try { 16 | TimeUnit.SECONDS.sleep(1); 17 | } catch (InterruptedException e) { 18 | e.printStackTrace(); 19 | } 20 | } 21 | }).start(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /java-jvmpre/delombok/src-bak/src/main/java/som/hks/oom/EqualsOOMTest.java: -------------------------------------------------------------------------------- 1 | package som.hks.oom; 2 | 3 | public class EqualsOOMTest { 4 | 5 | /** 6 | 说明: 对于 Integer var=? 7 | 在-128 至 127 之间的赋值, Integer 对象是在IntegerCache.cache 产生,会复用已有对象, 8 | 这个区间内的 Integer 值可以直接使用==进行判断, 9 | 10 | 但是这个区间之外的所有数据, 11 | 都会在堆上产生,并不会复用已有对象 12 | */ 13 | public static void main(String[] args){ 14 | Integer i1 = 123; 15 | Integer i2 = 123; 16 | System.out.println(i1==i2); 17 | Integer i3 = 129; 18 | Integer i4 = 129; 19 | System.out.println(i3==i4); 20 | System.out.println(i3.equals(i4)); 21 | int i5 = 130; 22 | int i6 = 130; 23 | System.out.println(i5==i6); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /java-annotation/delombok/src-bak/src/main/java/com/hks/annotation/Apple.java: -------------------------------------------------------------------------------- 1 | package com.hks.annotation; 2 | 3 | public class Apple { 4 | 5 | @FruitName("Apple") 6 | private String appleName; 7 | 8 | @FruitColor(fruitColor= FruitColor.Color.RED) 9 | private String appleColor; 10 | 11 | public void setAppleColor(String appleColor) { 12 | this.appleColor = appleColor; 13 | } 14 | public String getAppleColor() { 15 | return appleColor; 16 | } 17 | 18 | public void setAppleName(String appleName) { 19 | this.appleName = appleName; 20 | } 21 | 22 | public String getAppleName() { 23 | return appleName; 24 | } 25 | 26 | public void displayName(){ 27 | System.out.println("水果的名字是:苹果"); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /java-aspect/delombok/src-bak/src/main/java/com/hks/asm/MyClassLoader.java: -------------------------------------------------------------------------------- 1 | package com.hks.asm; 2 | 3 | import org.objectweb.asm.Opcodes; 4 | /** 5 | * @Author: hekuangsheng 6 | * @Date: 2018/10/19 7 | * 8 | * 自定义ClassLoader 9 | */ 10 | public class MyClassLoader extends ClassLoader implements Opcodes { 11 | 12 | 13 | public MyClassLoader() { 14 | super(); 15 | } 16 | 17 | public MyClassLoader(ClassLoader parent) { 18 | super(parent); 19 | } 20 | 21 | @Override 22 | public Class loadClass(String name) throws ClassNotFoundException { 23 | return super.loadClass(name); 24 | } 25 | 26 | public Class defineClass(String name, byte[] b){ 27 | return super.defineClass(name, b, 0, b.length); 28 | } 29 | 30 | } 31 | 32 | -------------------------------------------------------------------------------- /java-jvmpre/delombok/src-bak/src/main/java/som/hks/aceessControler/MyFileInputStream.java: -------------------------------------------------------------------------------- 1 | package som.hks.aceessControler; 2 | 3 | import java.io.File; 4 | import java.io.FileNotFoundException; 5 | 6 | /** 7 | * 第一步:编写MyFileInputStream 8 | * (copy吧少年,不要自己狂敲) 9 | */ 10 | public class MyFileInputStream { 11 | 12 | public MyFileInputStream(String name) throws FileNotFoundException { 13 | this(name != null ? new File(name) : null); 14 | } 15 | 16 | public MyFileInputStream(File file) throws FileNotFoundException { 17 | String name = (file != null ? file.getPath() : null); 18 | SecurityManager security = System.getSecurityManager(); 19 | if (security != null) { 20 | security.checkRead(name); 21 | } 22 | } 23 | 24 | 25 | } 26 | -------------------------------------------------------------------------------- /java-jvmpre/delombok/src-bak/src/main/java/som/hks/aceessControler/TestMySecurityManager.java: -------------------------------------------------------------------------------- 1 | package som.hks.aceessControler; 2 | 3 | import java.io.IOException; 4 | 5 | /** 6 | * 第二步:实现一个简单的类,主要用来测试我们自己定义的安全管理器起作用了没有, 7 | * 我们这里借助了FileInputStream,因为FileInputStream会调用安全管理器去校验权限 8 | * 所以用FileInputStream测试我们自己的安全管理器非常的适合。 9 | */ 10 | public class TestMySecurityManager { 11 | 12 | public static void main(String[] args) { 13 | System.setSecurityManager(new MySecurityManager()); 14 | try { 15 | //FileInputStream fis = new FileInputStream("test"); 16 | MyFileInputStream myFileInputStream = new MyFileInputStream("test"); 17 | } catch (IOException e) { 18 | e.printStackTrace(); 19 | } 20 | 21 | } 22 | 23 | 24 | } 25 | -------------------------------------------------------------------------------- /java-algorithms/src/main/java/com/hks/eightsortingalgorithms/leetcode/isValidSerialization.java: -------------------------------------------------------------------------------- 1 | package com.hks.eightsortingalgorithms.leetcode; 2 | 3 | import java.util.LinkedList; 4 | 5 | public class isValidSerialization { 6 | public boolean isValidSerialization(String preorder) { 7 | int edge = 1; 8 | for(String node : preorder.split(",")) { 9 | if(node.equals("#")) { 10 | edge -= 1; 11 | if(edge < 0) { 12 | return false; 13 | } 14 | } else { 15 | edge -= 1; 16 | if(edge < 0) { 17 | return false; 18 | } 19 | edge += 2; 20 | } 21 | } 22 | return edge == 0; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /java-object/delombok/src-bak/src/main/java/com/hks/staticClass/ThisClass.java: -------------------------------------------------------------------------------- 1 | package com.hks.staticClass; 2 | 3 | /** 4 | * @Author: hekuangsheng 5 | * @Date: 2018/10/23 6 | * 7 | * 33 8 | * 9 | * 这里面主要考察队this和static的理解。this代表什么? 10 | * this代表当前对象,那么通过new ThisClass()来调用printValue的话,当前对象就是通过new ThisClass()生成的对象。 11 | * 而static变量是被对象所享有的,因此在printValue中的this.value的值毫无疑问是33。 12 | * 13 | * 静态成员变量虽然独立于对象,但是不代表不可以通过对象去访问,所有的静态方法和静态变量都可以通过对象访问(只要访问权限足够) 14 | */ 15 | public class ThisClass { 16 | 17 | static int value = 33; 18 | 19 | public static void main(String[] args) throws Exception { 20 | new ThisClass().printValue(); 21 | } 22 | 23 | private void printValue() { 24 | int value = 3; 25 | System.out.println(this.value); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /java-collectors/src/main/java/com/hks/hashmap/A.java: -------------------------------------------------------------------------------- 1 | package com.hks.hashmap; 2 | 3 | public class A { 4 | 5 | private String code; 6 | private String name; 7 | @Override 8 | public int hashCode() { 9 | // TODO Auto-generated method stub 10 | return code.hashCode()+name.hashCode(); 11 | } 12 | public String getCode() { 13 | return code; 14 | } 15 | public void setCode(String code) { 16 | this.code = code; 17 | } 18 | public String getName() { 19 | return name; 20 | } 21 | public void setName(String name) { 22 | this.name = name; 23 | } 24 | @Override 25 | public String toString() { 26 | // TODO Auto-generated method stub 27 | return code.toString()+name.toString(); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /java-algorithms/src/main/java/com/hks/eightsortingalgorithms/leetcode/lengthOfLIS.java: -------------------------------------------------------------------------------- 1 | package com.hks.eightsortingalgorithms.leetcode; 2 | 3 | import java.util.Arrays; 4 | 5 | public class lengthOfLIS { 6 | 7 | public int lengthOfLIS(int[] nums) { 8 | if (nums.length == 0) { 9 | return 0; 10 | } 11 | int[] dp = new int[nums.length]; 12 | Arrays.fill(dp, 1); 13 | dp[0] = 1; 14 | int maxans = 1; 15 | for (int i = 1; i < nums.length; i++) { 16 | for (int j = 0; j < i; j++) { 17 | if(nums[j] < nums[i] && dp[j] + 1 > dp[i]) { 18 | dp[i] = dp[j] + 1; 19 | } 20 | } 21 | maxans = Math.max(maxans, dp[i]); 22 | } 23 | return maxans; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /java-algorithms/src/main/java/com/hks/eightsortingalgorithms/leetcode/maxDepth.java: -------------------------------------------------------------------------------- 1 | package com.hks.eightsortingalgorithms.leetcode; 2 | 3 | public class maxDepth { 4 | public class TreeNode { 5 | int val; 6 | TreeNode left; 7 | TreeNode right; 8 | 9 | TreeNode(int x) { 10 | val = x; 11 | } 12 | } 13 | 14 | int deep = 0, maxDepth = 0; 15 | 16 | public int maxDepth(TreeNode root) { 17 | traverTree(root); 18 | return maxDepth; 19 | } 20 | 21 | void traverTree(TreeNode node) { 22 | if (node == null) { 23 | maxDepth = Math.max(maxDepth, deep); 24 | return; 25 | } 26 | deep++; 27 | traverTree(node.left); 28 | traverTree(node.right); 29 | deep--; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /java-collectors/delombok/src-bak/src/main/java/com/hks/hashmap/A.java: -------------------------------------------------------------------------------- 1 | package com.hks.hashmap; 2 | 3 | public class A { 4 | 5 | private String code; 6 | private String name; 7 | @Override 8 | public int hashCode() { 9 | // TODO Auto-generated method stub 10 | return code.hashCode()+name.hashCode(); 11 | } 12 | public String getCode() { 13 | return code; 14 | } 15 | public void setCode(String code) { 16 | this.code = code; 17 | } 18 | public String getName() { 19 | return name; 20 | } 21 | public void setName(String name) { 22 | this.name = name; 23 | } 24 | @Override 25 | public String toString() { 26 | // TODO Auto-generated method stub 27 | return code.toString()+name.toString(); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /java-lambda/src/main/java/com/hks/lambda/PeekTest.java: -------------------------------------------------------------------------------- 1 | package com.hks.lambda; 2 | 3 | import org.junit.Test; 4 | 5 | import java.util.stream.Collectors; 6 | import java.util.stream.Stream; 7 | 8 | public class PeekTest { 9 | 10 | 11 | 12 | /** 13 | * forEach 是 terminal 操作,因此它执行后,Stream 的元素就被“消费”掉了,你无法对一个 Stream 进行两次 terminal 运算。 14 | * 15 | * 相反,具有相似功能的 intermediate 操作 peek 可以达到上述目的。 16 | */ 17 | @Test 18 | public void foreachPeekTest(){ 19 | Stream.of("one", "two", "three", "four") 20 | .filter(e -> e.length() > 3) 21 | .peek(e -> System.out.println("Filtered value: " + e)) 22 | .map(String::toUpperCase) 23 | .peek(e -> System.out.println("Mapped value: " + e)) 24 | .collect(Collectors.toList()); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /java-proxy/src/main/java/com/hks/proxy/jdk/JDKProxyTest.java: -------------------------------------------------------------------------------- 1 | package com.hks.proxy.jdk; 2 | 3 | import com.hks.proxy.UserService; 4 | import com.hks.proxy.UserServiceImpl; 5 | 6 | import java.lang.reflect.InvocationHandler; 7 | import java.lang.reflect.Proxy; 8 | 9 | public class JDKProxyTest { 10 | 11 | public static void main(String[] args) { 12 | UserService userService = new UserServiceImpl(); 13 | InvocationHandler invocationHandler = new MyInvocationHandler(userService); 14 | UserService userServiceProxy = (UserService) Proxy.newProxyInstance(userService.getClass().getClassLoader(), 15 | userService.getClass().getInterfaces(), invocationHandler); 16 | System.out.println(userServiceProxy.getName(1)); 17 | System.out.println(userServiceProxy.getAge(1)); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /java-algorithms/src/main/java/com/hks/eightsortingalgorithms/leetcode/getIntersectionNode.java: -------------------------------------------------------------------------------- 1 | package com.hks.eightsortingalgorithms.leetcode; 2 | 3 | public class getIntersectionNode { 4 | class ListNode { 5 | int val; 6 | ListNode next; 7 | 8 | ListNode() { 9 | } 10 | 11 | ListNode(int val) { 12 | this.val = val; 13 | } 14 | 15 | ListNode(int val, ListNode next) { 16 | this.val = val; 17 | this.next = next; 18 | } 19 | } 20 | 21 | public ListNode getIntersectionNode(ListNode headA, ListNode headB) { 22 | ListNode pA = headA, pB = headB; 23 | while(pA != pB){ 24 | pA = pA == null? headB : pA.next; 25 | pB = pB == null? headA : pB.next; 26 | } 27 | return pA; 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /java-annotation/src/main/java/com/hks/annotation/Table.java: -------------------------------------------------------------------------------- 1 | package com.hks.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Target; 5 | 6 | /** 7 | * @Target说明了Annotation所修饰的对象范围:Annotation可被用于 8 | * packages、types(类、接口、枚举、Annotation类型)、 9 | * 类型成员(方法、构造方法、成员变量、枚举值)、 10 | * 方法参数和本地变量(如循环变量、catch参数)。 11 | * 12 | * 在Annotation类型的声明中使用了target可更加明晰其修饰的目标。 13 | * 14 | * 取值(ElementType)有: 15 | 16 |     1.CONSTRUCTOR:用于描述构造器 17 |     2.FIELD:用于描述域 18 |     3.LOCAL_VARIABLE:用于描述局部变量 19 |     4.METHOD:用于描述方法 20 |     5.PACKAGE:用于描述包 21 |     6.PARAMETER:用于描述参数 22 |     7.TYPE:用于描述类、接口(包括注解类型) 或enum声明 23 | */ 24 | @Target(ElementType.TYPE) 25 | public @interface Table { 26 | 27 | /** 28 | * 数据表名称注解,默认值为类名称 29 | * @return 30 | */ 31 | String tableName() default "className"; 32 | 33 | } 34 | -------------------------------------------------------------------------------- /java-aspect/src/main/java/com/hks/asm/AopClassAdapter.java: -------------------------------------------------------------------------------- 1 | package com.hks.asm; 2 | 3 | import org.objectweb.asm.ClassVisitor; 4 | import org.objectweb.asm.MethodVisitor; 5 | import org.objectweb.asm.Opcodes; 6 | 7 | /** 8 | * 用来处理哪些方法需要进行修改 9 | */ 10 | public class AopClassAdapter extends ClassVisitor implements Opcodes { 11 | 12 | public AopClassAdapter(int api, ClassVisitor cv) { 13 | super(api, cv); 14 | } 15 | 16 | @Override 17 | public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { 18 | MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions); 19 | // 对test开头的方法进行特殊处理 20 | if (name.startsWith("test")) { 21 | mv = new AopMethodVisitor(this.api, mv); 22 | } 23 | return mv; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /java-jvmpre/src/main/java/som/hks/oom/MaxTenuringThreshold.java: -------------------------------------------------------------------------------- 1 | package som.hks.oom; 2 | 3 | /** 4 | * 这个阈值的最大值可以通过参数-XX:MaxTenuringThreshold 来设置,默认值是 15。 5 | * 虽然-XX:MaxTenuringThreshold 的值可能是 15 或者更大,但这不意味着新对象非要达到这个年龄才能进入年老代。 6 | * 事实上,对象实际进入年老代的年龄是虚拟机在运行时根据内存使用情况动态计算的,这个参数指定的是阈值年龄的最大值。 7 | * 即,实际晋升年老代年龄等于动态计算所得的年龄与-XX:MaxTenuringThreshold 中较小的那个 8 | * 9 | * -XX:+PrintGCDetails -Xmx20M -Xms20M -Xmn10M -XX:SurvivorRatio=2 10 | * 11 | * -XX:+PrintGCDetails -Xmx20M -Xms20M -Xmn10M -XX:SurvivorRatio=2 -XX:MaxTenuringThreshold=1 12 | */ 13 | public class MaxTenuringThreshold { 14 | public static void main(String args[]){ 15 | byte[] b1,b2,b3; 16 | b1 = new byte[1024*512]; 17 | b2 = new byte[1024*1024*2]; 18 | b3 = new byte[1024*1024*4]; 19 | b3 = null; 20 | b3 = new byte[1024*1024*4]; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /java-lambda/delombok/src-bak/src/main/java/com/hks/lambda/PeekTest.java: -------------------------------------------------------------------------------- 1 | package com.hks.lambda; 2 | 3 | import org.junit.Test; 4 | 5 | import java.util.stream.Collectors; 6 | import java.util.stream.Stream; 7 | 8 | public class PeekTest { 9 | 10 | 11 | 12 | /** 13 | * forEach 是 terminal 操作,因此它执行后,Stream 的元素就被“消费”掉了,你无法对一个 Stream 进行两次 terminal 运算。 14 | * 15 | * 相反,具有相似功能的 intermediate 操作 peek 可以达到上述目的。 16 | */ 17 | @Test 18 | public void foreachPeekTest(){ 19 | Stream.of("one", "two", "three", "four") 20 | .filter(e -> e.length() > 3) 21 | .peek(e -> System.out.println("Filtered value: " + e)) 22 | .map(String::toUpperCase) 23 | .peek(e -> System.out.println("Mapped value: " + e)) 24 | .collect(Collectors.toList()); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /java-proxy/delombok/src-bak/src/main/java/com/hks/proxy/jdk/JDKProxyTest.java: -------------------------------------------------------------------------------- 1 | package com.hks.proxy.jdk; 2 | 3 | import com.hks.proxy.UserService; 4 | import com.hks.proxy.UserServiceImpl; 5 | 6 | import java.lang.reflect.InvocationHandler; 7 | import java.lang.reflect.Proxy; 8 | 9 | public class JDKProxyTest { 10 | 11 | public static void main(String[] args) { 12 | UserService userService = new UserServiceImpl(); 13 | InvocationHandler invocationHandler = new MyInvocationHandler(userService); 14 | UserService userServiceProxy = (UserService) Proxy.newProxyInstance(userService.getClass().getClassLoader(), 15 | userService.getClass().getInterfaces(), invocationHandler); 16 | System.out.println(userServiceProxy.getName(1)); 17 | System.out.println(userServiceProxy.getAge(1)); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /java-algorithms/src/main/java/com/hks/eightsortingalgorithms/leetcode/maxProduct.java: -------------------------------------------------------------------------------- 1 | package com.hks.eightsortingalgorithms.leetcode; 2 | 3 | public class maxProduct { 4 | public int maxProduct(int[] nums) { 5 | if(nums==null||nums.length==0) { 6 | return 0; 7 | } 8 | int len = nums.length; 9 | int res = nums[0]; 10 | 11 | int[][] dp = new int[len][2]; 12 | dp[0][0] = nums[0]; 13 | dp[0][1] = nums[0]; 14 | 15 | for (int i = 1; i < len; i++) { 16 | dp[i][0] = Math.min(Math.min(dp[i-1][0]*nums[i],dp[i-1][1]*nums[i]),nums[i]); 17 | dp[i][1] = Math.max(Math.max(dp[i-1][0]*nums[i],dp[i-1][1]*nums[i]),nums[i]); 18 | 19 | if(dp[i][1]>res) { 20 | res = dp[i][1]; 21 | } 22 | } 23 | return res; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /java-algorithms/src/main/java/com/hks/eightsortingalgorithms/method/sort/impl/BubbleAlgorithmsImpl.java: -------------------------------------------------------------------------------- 1 | package com.hks.eightsortingalgorithms.method.sort.impl; 2 | 3 | import com.hks.eightsortingalgorithms.method.sort.BubbleAlgorithms; 4 | import org.springframework.stereotype.Service; 5 | 6 | @Service 7 | public class BubbleAlgorithmsImpl implements BubbleAlgorithms { 8 | 9 | @Override 10 | public int[] sort(int[] intArr) { 11 | for (int i = 0; i < intArr.length - 1; i++) { 12 | for (int j = 0; j < intArr.length - 1 - i; j++) { 13 | if (intArr[j] > intArr[j + 1]) { 14 | int temp = intArr[j]; 15 | intArr[j] = intArr[j + 1]; 16 | intArr[j + 1] = temp; 17 | } 18 | } 19 | } 20 | return intArr; 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /java-algorithms/src/main/java/com/hks/eightsortingalgorithms/method/sort/impl/StraightInsertAlgorithmsImpl.java: -------------------------------------------------------------------------------- 1 | package com.hks.eightsortingalgorithms.method.sort.impl; 2 | 3 | import com.hks.eightsortingalgorithms.method.sort.StraightInsertAlgorithms; 4 | import org.springframework.stereotype.Service; 5 | 6 | @Service 7 | public class StraightInsertAlgorithmsImpl implements StraightInsertAlgorithms { 8 | 9 | @Override 10 | public int[] sort(int[] args) { 11 | int tmp; 12 | for (int i = 1; i < args.length; i++) { 13 | for (int j = i; j > 0; j--) { 14 | if (args[j] < args[j - 1]) { 15 | tmp = args[j - 1]; 16 | args[j - 1] = args[j]; 17 | args[j] = tmp; 18 | } 19 | } 20 | } 21 | return args; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /java-annotation/delombok/src-bak/src/main/java/com/hks/annotation/Table.java: -------------------------------------------------------------------------------- 1 | package com.hks.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Target; 5 | 6 | /** 7 | * @Target说明了Annotation所修饰的对象范围:Annotation可被用于 8 | * packages、types(类、接口、枚举、Annotation类型)、 9 | * 类型成员(方法、构造方法、成员变量、枚举值)、 10 | * 方法参数和本地变量(如循环变量、catch参数)。 11 | * 12 | * 在Annotation类型的声明中使用了target可更加明晰其修饰的目标。 13 | * 14 | * 取值(ElementType)有: 15 | 16 |     1.CONSTRUCTOR:用于描述构造器 17 |     2.FIELD:用于描述域 18 |     3.LOCAL_VARIABLE:用于描述局部变量 19 |     4.METHOD:用于描述方法 20 |     5.PACKAGE:用于描述包 21 |     6.PARAMETER:用于描述参数 22 |     7.TYPE:用于描述类、接口(包括注解类型) 或enum声明 23 | */ 24 | @Target(ElementType.TYPE) 25 | public @interface Table { 26 | 27 | /** 28 | * 数据表名称注解,默认值为类名称 29 | * @return 30 | */ 31 | String tableName() default "className"; 32 | 33 | } 34 | -------------------------------------------------------------------------------- /java-algorithms/src/main/java/com/hks/eightsortingalgorithms/leetcode/longestPalindrome.java: -------------------------------------------------------------------------------- 1 | package com.hks.eightsortingalgorithms.leetcode; 2 | 3 | public class longestPalindrome { 4 | 5 | String palinerome(String s, int l, int r) { 6 | while (l >= 0 && r < s.length() && s.charAt(l) == s.charAt(r)) { 7 | l--; 8 | r++; 9 | } 10 | return s.substring(l + 1, r); 11 | } 12 | 13 | public String longestPalindrome(String s) { 14 | String res = ""; 15 | int len = s.length(); 16 | for (int i = 0; i < len; i++) { 17 | String s1 = palinerome(s, i, i); 18 | String s2 = palinerome(s, i, i + 1); 19 | res = res.length() > s1.length() ? res : s1; 20 | res = res.length() > s2.length() ? res : s2; 21 | } 22 | return res; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /java-aspect/delombok/src-bak/src/main/java/com/hks/asm/AopClassAdapter.java: -------------------------------------------------------------------------------- 1 | package com.hks.asm; 2 | 3 | import org.objectweb.asm.ClassVisitor; 4 | import org.objectweb.asm.MethodVisitor; 5 | import org.objectweb.asm.Opcodes; 6 | 7 | /** 8 | * 用来处理哪些方法需要进行修改 9 | */ 10 | public class AopClassAdapter extends ClassVisitor implements Opcodes { 11 | 12 | public AopClassAdapter(int api, ClassVisitor cv) { 13 | super(api, cv); 14 | } 15 | 16 | @Override 17 | public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { 18 | MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions); 19 | // 对test开头的方法进行特殊处理 20 | if (name.startsWith("test")) { 21 | mv = new AopMethodVisitor(this.api, mv); 22 | } 23 | return mv; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /java-jvmpre/delombok/src-bak/src/main/java/som/hks/oom/MaxTenuringThreshold.java: -------------------------------------------------------------------------------- 1 | package som.hks.oom; 2 | 3 | /** 4 | * 这个阈值的最大值可以通过参数-XX:MaxTenuringThreshold 来设置,默认值是 15。 5 | * 虽然-XX:MaxTenuringThreshold 的值可能是 15 或者更大,但这不意味着新对象非要达到这个年龄才能进入年老代。 6 | * 事实上,对象实际进入年老代的年龄是虚拟机在运行时根据内存使用情况动态计算的,这个参数指定的是阈值年龄的最大值。 7 | * 即,实际晋升年老代年龄等于动态计算所得的年龄与-XX:MaxTenuringThreshold 中较小的那个 8 | * 9 | * -XX:+PrintGCDetails -Xmx20M -Xms20M -Xmn10M -XX:SurvivorRatio=2 10 | * 11 | * -XX:+PrintGCDetails -Xmx20M -Xms20M -Xmn10M -XX:SurvivorRatio=2 -XX:MaxTenuringThreshold=1 12 | */ 13 | public class MaxTenuringThreshold { 14 | public static void main(String args[]){ 15 | byte[] b1,b2,b3; 16 | b1 = new byte[1024*512]; 17 | b2 = new byte[1024*1024*2]; 18 | b3 = new byte[1024*1024*4]; 19 | b3 = null; 20 | b3 = new byte[1024*1024*4]; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /java-algorithms/src/main/java/com/hks/eightsortingalgorithms/leetcode/invertTree.java: -------------------------------------------------------------------------------- 1 | package com.hks.eightsortingalgorithms.leetcode; 2 | 3 | public class invertTree { 4 | public class TreeNode { 5 | int val; 6 | TreeNode left; 7 | TreeNode right; 8 | TreeNode() {} 9 | TreeNode(int val) { this.val = val; } 10 | TreeNode(int val, TreeNode left, TreeNode right) { 11 | this.val = val; 12 | this.left = left; 13 | this.right = right; 14 | } 15 | } 16 | 17 | public TreeNode invertTree(TreeNode root) { 18 | if(root==null) { 19 | return root; 20 | } 21 | invertTree(root.left); 22 | TreeNode tmp = root.left; 23 | root.left = root.right; 24 | root.right = tmp; 25 | invertTree(root.right); 26 | return root; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /java-algorithms/src/main/java/com/hks/eightsortingalgorithms/leetcode/generateParenthesis.java: -------------------------------------------------------------------------------- 1 | package com.hks.eightsortingalgorithms.leetcode; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class generateParenthesis { 7 | public List generateParenthesis(int n) { 8 | List res = new ArrayList<>(); 9 | if (n <= 0) return res; 10 | dfs(n, "", res, 0, 0); 11 | return res; 12 | } 13 | 14 | private void dfs(int n, String path, List res, int open, int close) { 15 | if (path.length() == 2 * n) { 16 | res.add(path); 17 | return; 18 | } 19 | if (open < n) { 20 | dfs(n, path + "(", res, open + 1, close); 21 | } 22 | if (close < open) { 23 | dfs(n, path + ")", res, open, close + 1); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /java-algorithms/src/main/java/com/hks/eightsortingalgorithms/leetcode/minDistance.java: -------------------------------------------------------------------------------- 1 | package com.hks.eightsortingalgorithms.leetcode; 2 | 3 | public class minDistance { 4 | public int minDistance(String word1, String word2) { 5 | int m = word1.length(), n = word2.length(); 6 | int[][] dp = new int[m][n]; 7 | for (int i = 0; i <= m; ++i) dp[i][0] = i; 8 | for (int i = 0; i <= n; ++i) dp[0][i] = i; 9 | 10 | for (int i = 1; i <= m; ++i) { 11 | for (int j = 1; j <= n; ++j) { 12 | if (word1.charAt(i - 1) == word2.charAt(j - 1)) { 13 | dp[i][j] = dp[i - 1][j - 1]; 14 | } else { 15 | dp[i][j] = Math.min(dp[i - 1][j - 1], Math.min(dp[i - 1][j], dp[i][j - 1])) + 1; 16 | } 17 | } 18 | } 19 | return dp[m][n]; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /java-algorithms/src/main/java/com/hks/eightsortingalgorithms/leetcode/uniquePaths.java: -------------------------------------------------------------------------------- 1 | package com.hks.eightsortingalgorithms.leetcode; 2 | 3 | public class uniquePaths { 4 | // 备忘录 5 | int[][] memo; 6 | 7 | public int uniquePaths(int m, int n) { 8 | memo = new int[m][n]; 9 | return dp(m - 1, n - 1); 10 | } 11 | 12 | // 定义:从 (0, 0) 到 (x, y) 有 dp(x, y) 条路径 13 | int dp(int x, int y) { 14 | // base case 15 | if (x == 0 && y == 0) { 16 | return 1; 17 | } 18 | if (x < 0 || y < 0) { 19 | return 0; 20 | } 21 | // 避免冗余计算 22 | if (memo[x][y] > 0) { 23 | return memo[x][y]; 24 | } 25 | // 状态转移方程: 26 | // 到达 (x, y) 的路径数等于到达 (x - 1, y) 和 (x, y - 1) 路径数之和 27 | memo[x][y] = dp(x - 1, y) + dp(x, y - 1); 28 | return memo[x][y]; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /java-intercept/src/main/java/com/hks/intercept/InterceptTest.java: -------------------------------------------------------------------------------- 1 | package com.hks.intercept; 2 | 3 | public class InterceptTest { 4 | public static void main(String[] args) { 5 | //主要想执行的方法 6 | Client client = new ClientImp(); 7 | //构造第一个拦截器 8 | Client intercept1 = new ForwardingClientImpl(client){ 9 | @Override 10 | public void start(String say) { 11 | System.out.println("拦截器1"); 12 | super.start(say); 13 | } 14 | }; 15 | //构造第二个拦截器 16 | Client intercept2 = new ForwardingClientImpl(intercept1){ 17 | @Override 18 | public void start(String say) { 19 | System.out.println("拦截器2"); 20 | super.start(say); 21 | } 22 | }; 23 | //执行主方法 24 | intercept2.start("这是要执行的方法"); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /java-lock/src/main/java/com/hks/lock/reentrant/SynchronizedTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 文件名:SynchrosizedTest.java 3 | * 版权:Copyright by www.yiche.com 4 | * 描述: 5 | * 修改人:hekuangsheng 6 | * 修改时间:2019/3/26 7 | * 跟踪单号: 8 | * 修改单号: 9 | * 修改内容: 10 | */ 11 | package com.hks.lock.reentrant; 12 | 13 | public class SynchronizedTest implements Runnable { 14 | public synchronized void get() { 15 | System.out.println(Thread.currentThread().getId()); 16 | set(); 17 | } 18 | 19 | public synchronized void set() { 20 | System.out.println(Thread.currentThread().getId()); 21 | } 22 | 23 | public void run() { 24 | get(); 25 | } 26 | 27 | public static void main(String[] args) { 28 | SynchronizedTest ss = new SynchronizedTest(); 29 | new Thread(ss).start(); 30 | new Thread(ss).start(); 31 | new Thread(ss).start(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /java-cache/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.hks 8 | java-cache 9 | 1.0-SNAPSHOT 10 | 11 | 12 | com.google.guava 13 | guava 14 | RELEASE 15 | 16 | 17 | org.slf4j 18 | slf4j-api 19 | RELEASE 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /java-object/src/main/java/com/hks/cloneClass/Person.java: -------------------------------------------------------------------------------- 1 | package com.hks.cloneClass; 2 | 3 | public class Person implements Cloneable{ 4 | 5 | private Integer age; 6 | 7 | private String name; 8 | 9 | public Person(Integer age, String name) { 10 | this.age = age; 11 | this.name = name; 12 | } 13 | 14 | public Integer getAge() { 15 | return age; 16 | } 17 | 18 | public void setAge(Integer age) { 19 | this.age = age; 20 | } 21 | 22 | public String getName() { 23 | return name; 24 | } 25 | 26 | public void setName(String name) { 27 | this.name = name; 28 | } 29 | 30 | @Override 31 | public String toString() { 32 | return super.toString(); 33 | } 34 | 35 | @Override 36 | protected Object clone() throws CloneNotSupportedException { 37 | return super.clone(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /java-intercept/delombok/src-bak/src/main/java/com/hks/intercept/InterceptTest.java: -------------------------------------------------------------------------------- 1 | package com.hks.intercept; 2 | 3 | public class InterceptTest { 4 | public static void main(String[] args) { 5 | //主要想执行的方法 6 | Client client = new ClientImp(); 7 | //构造第一个拦截器 8 | Client intercept1 = new ForwardingClientImpl(client){ 9 | @Override 10 | public void start(String say) { 11 | System.out.println("拦截器1"); 12 | super.start(say); 13 | } 14 | }; 15 | //构造第二个拦截器 16 | Client intercept2 = new ForwardingClientImpl(intercept1){ 17 | @Override 18 | public void start(String say) { 19 | System.out.println("拦截器2"); 20 | super.start(say); 21 | } 22 | }; 23 | //执行主方法 24 | intercept2.start("这是要执行的方法"); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /java-algorithms/src/main/java/com/hks/eightsortingalgorithms/controller/sort/ShellAlgorithmsController.java: -------------------------------------------------------------------------------- 1 | package com.hks.eightsortingalgorithms.controller.sort; 2 | 3 | import com.hks.eightsortingalgorithms.method.sort.ShellAlgorithms; 4 | import io.swagger.annotations.Api; 5 | import io.swagger.annotations.ApiOperation; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RestController; 9 | 10 | @RestController 11 | @Api(description = "平均O(n²)、最好O(n)、最坏O(n²);空间复杂度:O(1);稳定性:不稳定") 12 | public class ShellAlgorithmsController { 13 | 14 | @Autowired 15 | ShellAlgorithms shellAlgorithms; 16 | 17 | @RequestMapping("/shellSorting") 18 | @ApiOperation("希尔排序") 19 | public int[] shellSorting(int[] args){ 20 | return shellAlgorithms.sort(args); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /java-lock/delombok/src-bak/src/main/java/com/hks/lock/reentrant/SynchronizedTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 文件名:SynchrosizedTest.java 3 | * 版权:Copyright by www.yiche.com 4 | * 描述: 5 | * 修改人:hekuangsheng 6 | * 修改时间:2019/3/26 7 | * 跟踪单号: 8 | * 修改单号: 9 | * 修改内容: 10 | */ 11 | package com.hks.lock.reentrant; 12 | 13 | public class SynchronizedTest implements Runnable { 14 | public synchronized void get() { 15 | System.out.println(Thread.currentThread().getId()); 16 | set(); 17 | } 18 | 19 | public synchronized void set() { 20 | System.out.println(Thread.currentThread().getId()); 21 | } 22 | 23 | public void run() { 24 | get(); 25 | } 26 | 27 | public static void main(String[] args) { 28 | SynchronizedTest ss = new SynchronizedTest(); 29 | new Thread(ss).start(); 30 | new Thread(ss).start(); 31 | new Thread(ss).start(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /java-object/delombok/src-bak/src/main/java/com/hks/cloneClass/Person.java: -------------------------------------------------------------------------------- 1 | package com.hks.cloneClass; 2 | 3 | public class Person implements Cloneable{ 4 | 5 | private Integer age; 6 | 7 | private String name; 8 | 9 | public Person(Integer age, String name) { 10 | this.age = age; 11 | this.name = name; 12 | } 13 | 14 | public Integer getAge() { 15 | return age; 16 | } 17 | 18 | public void setAge(Integer age) { 19 | this.age = age; 20 | } 21 | 22 | public String getName() { 23 | return name; 24 | } 25 | 26 | public void setName(String name) { 27 | this.name = name; 28 | } 29 | 30 | @Override 31 | public String toString() { 32 | return super.toString(); 33 | } 34 | 35 | @Override 36 | protected Object clone() throws CloneNotSupportedException { 37 | return super.clone(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /java-algorithms/src/main/java/com/hks/eightsortingalgorithms/leetcode/rotate.java: -------------------------------------------------------------------------------- 1 | package com.hks.eightsortingalgorithms.leetcode; 2 | 3 | public class rotate { 4 | public void rotate(int[][] matrix) { 5 | int n = matrix.length; 6 | for (int i = 0; i < n; i++) { 7 | for (int j = i; j < n; j++) { 8 | int tmp = matrix[i][j]; 9 | matrix[i][j] = matrix[j][i]; 10 | matrix[j][i] = tmp; 11 | } 12 | } 13 | for (int[] row : matrix) { 14 | reverse(row); 15 | } 16 | } 17 | 18 | // 反转一维数组 19 | void reverse(int[] arr) { 20 | int i = 0, j = arr.length - 1; 21 | while (j > i) { 22 | // swap(arr[i], arr[j]); 23 | int temp = arr[i]; 24 | arr[i] = arr[j]; 25 | arr[j] = temp; 26 | i++; 27 | j--; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /java-jvmpre/src/main/java/som/hks/stackAccess/Friend.java: -------------------------------------------------------------------------------- 1 | package som.hks.stackAccess; 2 | 3 | import java.security.AccessController; 4 | import java.security.PrivilegedAction; 5 | 6 | public class Friend implements Doer{ 7 | 8 | private Doer next; 9 | private boolean direct; 10 | 11 | public Friend(Doer next,boolean direct){ 12 | this.next=next; 13 | this.direct=direct; 14 | } 15 | 16 | @Override 17 | public void doYourThing() { 18 | System.out.println("Im a Friend"); 19 | 20 | if (direct) { 21 | next.doYourThing(); 22 | } else { 23 | AccessController.doPrivileged(new PrivilegedAction() { 24 | 25 | @Override 26 | public Object run() { 27 | next.doYourThing(); 28 | return null; 29 | } 30 | 31 | }); 32 | 33 | } 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /java-jvmpre/src/main/java/som/hks/oom/GCTimeTest.java: -------------------------------------------------------------------------------- 1 | package som.hks.oom; 2 | 3 | import java.util.HashMap; 4 | 5 | /** 6 | * 所示代码运行 1 万次循环,每次分配 512*100B 空间, 7 | * 采用不同的垃圾回收器,输出程序运行所消耗的时间 8 | */ 9 | public class GCTimeTest { 10 | 11 | static HashMap map = new HashMap(); 12 | 13 | public static void main(String[] args){ 14 | long begintime = System.currentTimeMillis(); 15 | for(int i=0;i<10000;i++){ 16 | if(map.size()*512/1024/1024>=400){ 17 | //保护内存不溢出 18 | map.clear(); 19 | System.out.println("clean map"); 20 | } 21 | byte[] b1; 22 | for(int j=0;j<100;j++){ 23 | b1 = new byte[512]; 24 | map.put(System.nanoTime(), b1);//不断消耗内存 25 | } 26 | } 27 | long endtime = System.currentTimeMillis(); 28 | System.out.println(endtime-begintime); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /java-jvmpre/delombok/src-bak/src/main/java/som/hks/stackAccess/Friend.java: -------------------------------------------------------------------------------- 1 | package som.hks.stackAccess; 2 | 3 | import java.security.AccessController; 4 | import java.security.PrivilegedAction; 5 | 6 | public class Friend implements Doer{ 7 | 8 | private Doer next; 9 | private boolean direct; 10 | 11 | public Friend(Doer next,boolean direct){ 12 | this.next=next; 13 | this.direct=direct; 14 | } 15 | 16 | @Override 17 | public void doYourThing() { 18 | System.out.println("Im a Friend"); 19 | 20 | if (direct) { 21 | next.doYourThing(); 22 | } else { 23 | AccessController.doPrivileged(new PrivilegedAction() { 24 | 25 | @Override 26 | public Object run() { 27 | next.doYourThing(); 28 | return null; 29 | } 30 | 31 | }); 32 | 33 | } 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /java-jvmpre/src/main/java/som/hks/stackAccess/Stranger.java: -------------------------------------------------------------------------------- 1 | package som.hks.stackAccess; 2 | 3 | import java.security.AccessController; 4 | import java.security.PrivilegedAction; 5 | 6 | public class Stranger implements Doer { 7 | 8 | private Doer next; 9 | private boolean direct; 10 | 11 | public Stranger(Doer next, boolean direct) { 12 | this.next = next; 13 | this.direct = direct; 14 | } 15 | 16 | @Override 17 | public void doYourThing() { 18 | System.out.println("Im a Stranger"); 19 | 20 | if (direct) { 21 | next.doYourThing(); 22 | } else { 23 | AccessController.doPrivileged(new PrivilegedAction() { 24 | 25 | @Override 26 | public Object run() { 27 | next.doYourThing(); 28 | return null; 29 | } 30 | 31 | }); 32 | 33 | } 34 | } 35 | 36 | 37 | } 38 | -------------------------------------------------------------------------------- /java-object/src/main/java/com/hks/enumClass/Sample3.java: -------------------------------------------------------------------------------- 1 | package com.hks.enumClass; 2 | 3 | public class Sample3 { 4 | enum Size { 5 | Small { 6 | public double getPricingFactor() { 7 | return 0.8; 8 | } 9 | }, 10 | Medium, 11 | Large, 12 | ExtraLarge { 13 | public double getPricingFactor() { 14 | return 1.2; 15 | } 16 | }, 17 | ExtraExtraLarge { 18 | public double getPricingFactor() { 19 | return 1.2; 20 | } 21 | }; 22 | public double getPricingFactor() { 23 | return 1.0; 24 | } 25 | } 26 | public static void main(String args[]) { 27 | for (Size s : Size.values()) { 28 | double d = s.getPricingFactor(); 29 | System.out.println(s + " Size has pricing factor of " + d); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /java-aspect/src/main/java/com/hks/asm/AopMethodVisitor.java: -------------------------------------------------------------------------------- 1 | package com.hks.asm; 2 | 3 | import org.objectweb.asm.MethodVisitor; 4 | import org.objectweb.asm.Opcodes; 5 | /** 6 | * @Author: hekuangsheng 7 | * @Date: 2018/10/19 8 | * 9 | * 修改字节码 10 | */ 11 | public class AopMethodVisitor extends MethodVisitor implements Opcodes { 12 | 13 | public AopMethodVisitor(int api, MethodVisitor mv) { 14 | super(api, mv); 15 | } 16 | 17 | @Override 18 | public void visitCode() { 19 | super.visitCode(); 20 | this.visitMethodInsn(INVOKESTATIC, "com/hks/asm/AopInteceptor", "before", "()V", false); 21 | } 22 | 23 | @Override 24 | public void visitInsn(int opcode) { 25 | if (opcode >= IRETURN && opcode <= RETURN) 26 | // 在返回之前安插after 代码。 27 | this.visitMethodInsn(INVOKESTATIC, "com/hks/asm/AopInteceptor", "after", "()V", false); 28 | super.visitInsn(opcode); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /java-jvmpre/delombok/src-bak/src/main/java/som/hks/oom/GCTimeTest.java: -------------------------------------------------------------------------------- 1 | package som.hks.oom; 2 | 3 | import java.util.HashMap; 4 | 5 | /** 6 | * 所示代码运行 1 万次循环,每次分配 512*100B 空间, 7 | * 采用不同的垃圾回收器,输出程序运行所消耗的时间 8 | */ 9 | public class GCTimeTest { 10 | 11 | static HashMap map = new HashMap(); 12 | 13 | public static void main(String[] args){ 14 | long begintime = System.currentTimeMillis(); 15 | for(int i=0;i<10000;i++){ 16 | if(map.size()*512/1024/1024>=400){ 17 | //保护内存不溢出 18 | map.clear(); 19 | System.out.println("clean map"); 20 | } 21 | byte[] b1; 22 | for(int j=0;j<100;j++){ 23 | b1 = new byte[512]; 24 | map.put(System.nanoTime(), b1);//不断消耗内存 25 | } 26 | } 27 | long endtime = System.currentTimeMillis(); 28 | System.out.println(endtime-begintime); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /java-lock/src/main/java/com/hks/lock/spinLock/SpinLock.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 文件名:SpinLock.java 3 | * 版权:Copyright by www.yiche.com 4 | * 描述: 5 | * 修改人:hekuangsheng 6 | * 修改时间:2019/3/26 7 | * 跟踪单号: 8 | * 修改单号: 9 | * 修改内容: 10 | */ 11 | package com.hks.lock.spinLock; 12 | 13 | import java.util.concurrent.atomic.AtomicReference; 14 | 15 | /** 16 | * 对于自旋锁来说, 17 | 1、若有同一线程两调用lock() ,会导致第二次调用lock位置进行自旋,产生了死锁 18 | 说明这个锁并不是可重入的。(在lock函数内,应验证线程是否为已经获得锁的线程) 19 | 2、若1问题已经解决,当unlock()第一次调用时,就已经将锁释放了。实际上不应释放锁。 20 | (采用计数次进行统计) 21 | */ 22 | public class SpinLock { 23 | private AtomicReference owner =new AtomicReference(); 24 | 25 | public void lock(){ 26 | Thread current = Thread.currentThread(); 27 | while(!owner.compareAndSet(null, current)){ 28 | } 29 | } 30 | 31 | public void unlock (){ 32 | Thread current = Thread.currentThread(); 33 | owner.compareAndSet(current, null); 34 | } 35 | } 36 | 37 | -------------------------------------------------------------------------------- /java-object/delombok/src-bak/src/main/java/com/hks/enumClass/Sample3.java: -------------------------------------------------------------------------------- 1 | package com.hks.enumClass; 2 | 3 | public class Sample3 { 4 | enum Size { 5 | Small { 6 | public double getPricingFactor() { 7 | return 0.8; 8 | } 9 | }, 10 | Medium, 11 | Large, 12 | ExtraLarge { 13 | public double getPricingFactor() { 14 | return 1.2; 15 | } 16 | }, 17 | ExtraExtraLarge { 18 | public double getPricingFactor() { 19 | return 1.2; 20 | } 21 | }; 22 | public double getPricingFactor() { 23 | return 1.0; 24 | } 25 | } 26 | public static void main(String args[]) { 27 | for (Size s : Size.values()) { 28 | double d = s.getPricingFactor(); 29 | System.out.println(s + " Size has pricing factor of " + d); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /java-algorithms/src/main/java/com/hks/eightsortingalgorithms/leetcode/DuplicateZeros.java: -------------------------------------------------------------------------------- 1 | package com.hks.eightsortingalgorithms.leetcode; 2 | 3 | public class DuplicateZeros { 4 | 5 | public void duplicateZeros(int[] arr) { 6 | int zeroNum = 0; 7 | int arrLen = arr.length - 1; 8 | for (int i = 0; i <= arrLen - zeroNum; i++) { 9 | if (arr[i] == 0) { 10 | if (i == arrLen - zeroNum) { 11 | arr[arrLen] = 0; 12 | arrLen = arrLen - 1; 13 | break; 14 | } 15 | zeroNum++; 16 | } 17 | } 18 | 19 | for (int i = arrLen; i >= 0; i--) { 20 | if (arr[i] == 0) { 21 | arr[i + zeroNum] = 0; 22 | zeroNum--; 23 | arr[i + zeroNum] = 0; 24 | } else { 25 | arr[i + zeroNum] = arr[i]; 26 | } 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /java-algorithms/src/main/java/com/hks/eightsortingalgorithms/leetcode/triangleNumber.java: -------------------------------------------------------------------------------- 1 | package com.hks.eightsortingalgorithms.leetcode; 2 | 3 | import java.util.Arrays; 4 | 5 | public class triangleNumber { 6 | public int triangleNumber(int[] nums) { 7 | int n = nums.length; 8 | Arrays.sort(nums); 9 | int ans = 0; 10 | for (int i = 0; i < n; ++i) { 11 | for (int j = i+1; j < n; j++) { 12 | int left = j+1, right = n-1, k = j; 13 | while(left < right) { 14 | int mid = left + (right - left) / 2; 15 | if(nums[mid] < nums[i] + nums[j]) { 16 | k = mid; 17 | left = mid + 1; 18 | } else { 19 | right = mid - 1; 20 | } 21 | } 22 | ans += k - j; 23 | } 24 | } 25 | return ans; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /java-algorithms/src/main/java/com/hks/eightsortingalgorithms/method/search/impl/BinarySearchImpl.java: -------------------------------------------------------------------------------- 1 | package com.hks.eightsortingalgorithms.method.search.impl; 2 | 3 | import com.hks.eightsortingalgorithms.method.search.BinarySearch; 4 | import org.springframework.stereotype.Service; 5 | 6 | /** 7 | * @Author: hekuangsheng 8 | * @Date: 2018/11/21 9 | */ 10 | @Service 11 | public class BinarySearchImpl implements BinarySearch { 12 | 13 | @Override 14 | public int search(int[] intArr, int key) { 15 | int low = 0; 16 | int high = intArr.length - 1; 17 | while (low <= high) { 18 | int middle = (low + high) / 2; 19 | if (key == intArr[middle]) { 20 | return middle; 21 | } else if (key < intArr[middle]) { 22 | high = middle - 1; 23 | } else { 24 | low = middle + 1; 25 | } 26 | } 27 | return -1; 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /java-jvmpre/delombok/src-bak/src/main/java/som/hks/stackAccess/Stranger.java: -------------------------------------------------------------------------------- 1 | package som.hks.stackAccess; 2 | 3 | import java.security.AccessController; 4 | import java.security.PrivilegedAction; 5 | 6 | public class Stranger implements Doer { 7 | 8 | private Doer next; 9 | private boolean direct; 10 | 11 | public Stranger(Doer next, boolean direct) { 12 | this.next = next; 13 | this.direct = direct; 14 | } 15 | 16 | @Override 17 | public void doYourThing() { 18 | System.out.println("Im a Stranger"); 19 | 20 | if (direct) { 21 | next.doYourThing(); 22 | } else { 23 | AccessController.doPrivileged(new PrivilegedAction() { 24 | 25 | @Override 26 | public Object run() { 27 | next.doYourThing(); 28 | return null; 29 | } 30 | 31 | }); 32 | 33 | } 34 | } 35 | 36 | 37 | } 38 | -------------------------------------------------------------------------------- /java-jvmpre/src/main/java/som/hks/oom/HeapSize.java: -------------------------------------------------------------------------------- 1 | package som.hks.oom; 2 | 3 | import java.util.Vector; 4 | 5 | /** 6 | * 7 | -XX:MinHeapFreeRatio 参数用来设置堆空间最小空闲比例,默认值是 40。 8 | 当堆空间的空闲内存小于这个数值时,JVM 便会扩展堆空间。 9 | 10 | -XX:MaxHeapFreeRatio 参数用来设置堆空间最大空闲比例,默认值是 70。 11 | 当堆空间的空闲内存大于这个数值时,便会压缩堆空间,得到一个较小的堆。 12 | 13 | 当-Xmx 和-Xms 相等时,-XX:MinHeapFreeRatio 和-XX:MaxHeapFreeRatio 两个参数无效 14 | * -XX:+PrintGCDetails -Xms10M -Xmx40M -XX:MinHeapFreeRatio=40 -XX:MaxHeapFreeRatio=50 15 | * -XX:+PrintGCDetails -Xms40M -Xmx40M -XX:MinHeapFreeRatio=40 -XX:MaxHeapFreeRatio=50 16 | */ 17 | public class HeapSize { 18 | public static void main(String args[]) throws InterruptedException{ 19 | Vector v = new Vector(); 20 | while(true){ 21 | byte[] b = new byte[1024*1024]; 22 | v.add(b); 23 | if(v.size() == 10){ 24 | v = new Vector(); 25 | } 26 | Thread.sleep(1); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /java-algorithms/src/main/java/com/hks/eightsortingalgorithms/leetcode/hasPathSum.java: -------------------------------------------------------------------------------- 1 | package com.hks.eightsortingalgorithms.leetcode; 2 | 3 | public class hasPathSum { 4 | public class TreeNode { 5 | int val; 6 | TreeNode left; 7 | TreeNode right; 8 | 9 | TreeNode() { 10 | } 11 | 12 | TreeNode(int val) { 13 | this.val = val; 14 | } 15 | 16 | TreeNode(int val, TreeNode left, TreeNode right) { 17 | this.val = val; 18 | this.left = left; 19 | this.right = right; 20 | } 21 | } 22 | 23 | public boolean hasPathSum(TreeNode root, int sum) { 24 | if (root == null) { 25 | return false; 26 | } 27 | if (root.left == null && root.right == null) { 28 | return sum == root.val; 29 | } 30 | return hasPathSum(root.left, sum - root.val) || hasPathSum(root.right, sum - root.val); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /java-aspect/delombok/src-bak/src/main/java/com/hks/asm/AopMethodVisitor.java: -------------------------------------------------------------------------------- 1 | package com.hks.asm; 2 | 3 | import org.objectweb.asm.MethodVisitor; 4 | import org.objectweb.asm.Opcodes; 5 | /** 6 | * @Author: hekuangsheng 7 | * @Date: 2018/10/19 8 | * 9 | * 修改字节码 10 | */ 11 | public class AopMethodVisitor extends MethodVisitor implements Opcodes { 12 | 13 | public AopMethodVisitor(int api, MethodVisitor mv) { 14 | super(api, mv); 15 | } 16 | 17 | @Override 18 | public void visitCode() { 19 | super.visitCode(); 20 | this.visitMethodInsn(INVOKESTATIC, "com/hks/asm/AopInteceptor", "before", "()V", false); 21 | } 22 | 23 | @Override 24 | public void visitInsn(int opcode) { 25 | if (opcode >= IRETURN && opcode <= RETURN) 26 | // 在返回之前安插after 代码。 27 | this.visitMethodInsn(INVOKESTATIC, "com/hks/asm/AopInteceptor", "after", "()V", false); 28 | super.visitInsn(opcode); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /java-collectors/src/main/java/com/hks/genericity/RelationTest.java: -------------------------------------------------------------------------------- 1 | package com.hks.genericity; 2 | 3 | import org.junit.Test; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | public class RelationTest { 9 | 10 | @Test 11 | public void relationTest(){ 12 | Content animalContent = new Content<>(); 13 | 14 | ///上界通配符 15 | /*List dogs = new ArrayList<>(); 16 | dogs.add(new Dog("dog","wangwang","wangcai",10)); 17 | animalContent.setContent(dogs);*/ 18 | 19 | ///下界通配符 20 | List animals = new ArrayList<>(); 21 | animals.add(new Dog("dog","wangwang","wangcai",10)); 22 | animalContent.setContent(animals); 23 | animalContent.add(new Dog("cat","miaomiao","mimi",5)); 24 | 25 | List animalList = animalContent.getContent(); 26 | Dog dog = (Dog)animalList.get(1); 27 | System.out.println(dog.getDescribe()); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /java-lock/delombok/src-bak/src/main/java/com/hks/lock/spinLock/SpinLock.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 文件名:SpinLock.java 3 | * 版权:Copyright by www.yiche.com 4 | * 描述: 5 | * 修改人:hekuangsheng 6 | * 修改时间:2019/3/26 7 | * 跟踪单号: 8 | * 修改单号: 9 | * 修改内容: 10 | */ 11 | package com.hks.lock.spinLock; 12 | 13 | import java.util.concurrent.atomic.AtomicReference; 14 | 15 | /** 16 | * 对于自旋锁来说, 17 | 1、若有同一线程两调用lock() ,会导致第二次调用lock位置进行自旋,产生了死锁 18 | 说明这个锁并不是可重入的。(在lock函数内,应验证线程是否为已经获得锁的线程) 19 | 2、若1问题已经解决,当unlock()第一次调用时,就已经将锁释放了。实际上不应释放锁。 20 | (采用计数次进行统计) 21 | */ 22 | public class SpinLock { 23 | private AtomicReference owner =new AtomicReference(); 24 | 25 | public void lock(){ 26 | Thread current = Thread.currentThread(); 27 | while(!owner.compareAndSet(null, current)){ 28 | } 29 | } 30 | 31 | public void unlock (){ 32 | Thread current = Thread.currentThread(); 33 | owner.compareAndSet(current, null); 34 | } 35 | } 36 | 37 | -------------------------------------------------------------------------------- /java-algorithms/src/main/java/com/hks/eightsortingalgorithms/leetcode/rotateMatrix.java: -------------------------------------------------------------------------------- 1 | package com.hks.eightsortingalgorithms.leetcode; 2 | 3 | public class rotateMatrix { 4 | 5 | // 将二维矩阵原地顺时针旋转 90 度 6 | public void rotate(int[][] matrix) { 7 | int n = matrix.length; 8 | for (int i = 0; i < n; i++) { 9 | for (int j = i; j < n; j++) { 10 | int tmp = matrix[i][j]; 11 | matrix[i][j] = matrix[j][i]; 12 | matrix[j][i] = tmp; 13 | } 14 | } 15 | for (int[] row : matrix) { 16 | reverse(row); 17 | } 18 | } 19 | 20 | // 反转一维数组 21 | void reverse(int[] arr) { 22 | int i = 0, j = arr.length - 1; 23 | while (j > i) { 24 | // swap(arr[i], arr[j]); 25 | int temp = arr[i]; 26 | arr[i] = arr[j]; 27 | arr[j] = temp; 28 | i++; 29 | j--; 30 | } 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # java-base都是些 2 | ## JVM的基础知识 3 | 4 | java-agent、在skywalking的APM监控中看到 5 | 6 | jvm-access、在jvm的安全管理看到:https://blog.csdn.net/singgel/article/details/81873561 7 | 8 | jvm-classloader、在spring热部署看到:https://blog.csdn.net/singgel/article/details/46867001 9 | 10 | ## JAVA测试知识: 11 | 12 | jUnitPerf、在进行单元测试看到:https://blog.csdn.net/singgel/article/details/89399232 13 | 14 | ## JAVA基础知识: 15 | 16 | 枚举、在mybatis的映射思考得到:https://blog.csdn.net/singgel/article/details/79784190 17 | 18 | 反射、在rmi的思考中得到:https://blog.csdn.net/singgel/article/details/51682878 19 | 20 | 异常、 21 | 22 | 泛型、在java8的特性回顾中写到:https://blog.csdn.net/singgel/article/details/54289874 23 | 24 | 集合、在集合迭代时对集合进行修改抛ConcurrentModificationException原因的深究:https://blog.csdn.net/singgel/article/details/52416356 25 | 26 | 线程、在线程数多少合适时思考得到 27 | 28 | 代理、cglib的代理实现具体实现细节,asm包是怎么改变字节码的看到:https://blog.csdn.net/singgel/article/details/83185827 29 | 30 | 算法在我的博客里面有相应的解释,以及动态的gif图片引导你理解:https://blog.csdn.net/singgel/article/details/80335658 31 | -------------------------------------------------------------------------------- /java-jvmpre/delombok/src-bak/src/main/java/som/hks/oom/HeapSize.java: -------------------------------------------------------------------------------- 1 | package som.hks.oom; 2 | 3 | import java.util.Vector; 4 | 5 | /** 6 | * 7 | -XX:MinHeapFreeRatio 参数用来设置堆空间最小空闲比例,默认值是 40。 8 | 当堆空间的空闲内存小于这个数值时,JVM 便会扩展堆空间。 9 | 10 | -XX:MaxHeapFreeRatio 参数用来设置堆空间最大空闲比例,默认值是 70。 11 | 当堆空间的空闲内存大于这个数值时,便会压缩堆空间,得到一个较小的堆。 12 | 13 | 当-Xmx 和-Xms 相等时,-XX:MinHeapFreeRatio 和-XX:MaxHeapFreeRatio 两个参数无效 14 | * -XX:+PrintGCDetails -Xms10M -Xmx40M -XX:MinHeapFreeRatio=40 -XX:MaxHeapFreeRatio=50 15 | * -XX:+PrintGCDetails -Xms40M -Xmx40M -XX:MinHeapFreeRatio=40 -XX:MaxHeapFreeRatio=50 16 | */ 17 | public class HeapSize { 18 | public static void main(String args[]) throws InterruptedException{ 19 | Vector v = new Vector(); 20 | while(true){ 21 | byte[] b = new byte[1024*1024]; 22 | v.add(b); 23 | if(v.size() == 10){ 24 | v = new Vector(); 25 | } 26 | Thread.sleep(1); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /java-thread/src/main/java/com/hks/threadpool/TestThreadPool.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 文件名:TestThreadPool.java 3 | * 版权:Copyright by www.yiche.com 4 | * 描述: 5 | * 修改人:hekuangsheng 6 | * 修改时间:2019/3/22 7 | * 跟踪单号: 8 | * 修改单号: 9 | * 修改内容: 10 | */ 11 | package com.hks.threadpool; 12 | 13 | //测试线程池 14 | public class TestThreadPool { 15 | public static void main(String[] args) { 16 | // 创建3个线程的线程池 17 | ThreadPool t = ThreadPool.getThreadPool(3); 18 | t.execute(new Runnable[] { new Task(), new Task(), new Task() }); 19 | t.execute(new Runnable[] { new Task(), new Task(), new Task() }); 20 | System.out.println(t); 21 | t.destroy();// 所有线程都执行完成才destory 22 | System.out.println(t); 23 | } 24 | 25 | // 任务类 26 | static class Task implements Runnable { 27 | private static volatile int i = 1; 28 | 29 | public void run() {// 执行任务 30 | System.out.println("任务 " + (i++) + " 完成"); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /java-collectors/delombok/src-bak/src/main/java/com/hks/genericity/RelationTest.java: -------------------------------------------------------------------------------- 1 | package com.hks.genericity; 2 | 3 | import org.junit.Test; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | public class RelationTest { 9 | 10 | @Test 11 | public void relationTest(){ 12 | Content animalContent = new Content<>(); 13 | 14 | ///上界通配符 15 | /*List dogs = new ArrayList<>(); 16 | dogs.add(new Dog("dog","wangwang","wangcai",10)); 17 | animalContent.setContent(dogs);*/ 18 | 19 | ///下界通配符 20 | List animals = new ArrayList<>(); 21 | animals.add(new Dog("dog","wangwang","wangcai",10)); 22 | animalContent.setContent(animals); 23 | animalContent.add(new Dog("cat","miaomiao","mimi",5)); 24 | 25 | List animalList = animalContent.getContent(); 26 | Dog dog = (Dog)animalList.get(1); 27 | System.out.println(dog.getDescribe()); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /java-lock/src/main/java/com/hks/lock/spinLock/SpinLockTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 文件名:SpinLockTest.java 3 | * 版权:Copyright by www.yiche.com 4 | * 描述: 5 | * 修改人:hekuangsheng 6 | * 修改时间:2019/3/26 7 | * 跟踪单号: 8 | * 修改单号: 9 | * 修改内容: 10 | */ 11 | package com.hks.lock.spinLock; 12 | 13 | public class SpinLockTest implements Runnable{ 14 | SpinLock lock = new SpinLock(); 15 | 16 | public void get() { 17 | lock.lock(); 18 | System.out.println(Thread.currentThread().getId()); 19 | set(); 20 | lock.unlock(); 21 | } 22 | 23 | public void set() { 24 | lock.lock(); 25 | System.out.println(Thread.currentThread().getId()); 26 | lock.unlock(); 27 | } 28 | 29 | public void run() { 30 | get(); 31 | } 32 | 33 | public static void main(String[] args) { 34 | SpinLockTest ss = new SpinLockTest(); 35 | new Thread(ss).start(); 36 | new Thread(ss).start(); 37 | new Thread(ss).start(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /java-thread/delombok/src-bak/src/main/java/com/hks/threadpool/TestThreadPool.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 文件名:TestThreadPool.java 3 | * 版权:Copyright by www.yiche.com 4 | * 描述: 5 | * 修改人:hekuangsheng 6 | * 修改时间:2019/3/22 7 | * 跟踪单号: 8 | * 修改单号: 9 | * 修改内容: 10 | */ 11 | package com.hks.threadpool; 12 | 13 | //测试线程池 14 | public class TestThreadPool { 15 | public static void main(String[] args) { 16 | // 创建3个线程的线程池 17 | ThreadPool t = ThreadPool.getThreadPool(3); 18 | t.execute(new Runnable[] { new Task(), new Task(), new Task() }); 19 | t.execute(new Runnable[] { new Task(), new Task(), new Task() }); 20 | System.out.println(t); 21 | t.destroy();// 所有线程都执行完成才destory 22 | System.out.println(t); 23 | } 24 | 25 | // 任务类 26 | static class Task implements Runnable { 27 | private static volatile int i = 1; 28 | 29 | public void run() {// 执行任务 30 | System.out.println("任务 " + (i++) + " 完成"); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /java-object/src/main/java/com/hks/valuePass/RefrencePassTest.java: -------------------------------------------------------------------------------- 1 | package com.hks.valuePass; 2 | 3 | /** 4 | * @Author: hekuangsheng 5 | * @Date: 2018/10/29 6 | *

7 | * 引用传递: 8 | * ”引用”也就是指向真实内容的地址值,在方法调用时, 9 | * 实参的地址通过方法调用被传递给相应的形参,在方法体内, 10 | * 形参和实参指向相同的内存地址,对形参的操作会影响的真实内容。 11 | */ 12 | public class RefrencePassTest { 13 | 14 | public static void PersonCrossTest(Person person) { 15 | System.out.println("传入的person的name:" + person.getName()); 16 | person.setName("我是张小龙"); 17 | 18 | //加多此行代码 19 | ///无论是基本类型和是引用类型,在实参传入形参时,都是值传递,也就是说传递的都是一个副本,而不是内容本身。 20 | person = new Person(); 21 | person.setName("啊哈"); 22 | System.out.println("方法内重新赋值后的name:" + person.getName()); 23 | } 24 | 25 | public static void main(String[] args) { 26 | Person p = new Person(); 27 | p.setName("我是马化腾"); 28 | p.setAge(45); 29 | PersonCrossTest(p); 30 | System.out.println("方法执行后的name:" + p.getName()); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /java-lock/src/main/java/com/hks/lock/spinLock/SpinLock1Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 文件名:SpinLock1Test.java 3 | * 版权:Copyright by www.yiche.com 4 | * 描述: 5 | * 修改人:hekuangsheng 6 | * 修改时间:2019/3/26 7 | * 跟踪单号: 8 | * 修改单号: 9 | * 修改内容: 10 | */ 11 | package com.hks.lock.spinLock; 12 | 13 | public class SpinLock1Test implements Runnable{ 14 | SpinLock1 lock = new SpinLock1(); 15 | 16 | public void get() { 17 | lock.lock(); 18 | System.out.println(Thread.currentThread().getId()); 19 | set(); 20 | lock.unlock(); 21 | } 22 | 23 | public void set() { 24 | lock.lock(); 25 | System.out.println(Thread.currentThread().getId()); 26 | lock.unlock(); 27 | } 28 | 29 | public void run() { 30 | get(); 31 | } 32 | 33 | public static void main(String[] args) { 34 | SpinLock1Test ss = new SpinLock1Test(); 35 | new Thread(ss).start(); 36 | new Thread(ss).start(); 37 | new Thread(ss).start(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /java-classloader/src/main/java/com/hks/classLoader/TestClassLoaderDemo.java: -------------------------------------------------------------------------------- 1 | package com.hks.classLoader; 2 | 3 | /** 4 | * 第三步,定义一个有main函数入口的public类来做验证 5 | */ 6 | public class TestClassLoaderDemo { 7 | 8 | public static void main(String[] args) throws InstantiationException, IllegalAccessException { 9 | Class thisCls = TestClassLoaderDemo.class; 10 | MyClassLoader myClassLoader = new MyClassLoader(); 11 | System.out.println(thisCls.getClassLoader()); 12 | System.out.println(myClassLoader.getParent()); 13 | try { 14 | //用自定义的类装载器来装载类,这是动态扩展的一种途径 15 | Class cls2 = myClassLoader.loadClass("com.hks.eightsortingalgorithms.classLoader.TestBeLoader"); 16 | System.out.println(cls2.getClassLoader()); 17 | TestBeLoader test=(TestBeLoader)cls2.newInstance(); 18 | } catch (ClassNotFoundException e) { 19 | e.printStackTrace(); 20 | } 21 | } 22 | 23 | /** 24 | * 第四步,查看运行结果 25 | */ 26 | 27 | } 28 | -------------------------------------------------------------------------------- /java-algorithms/src/main/java/com/hks/eightsortingalgorithms/leetcode/detectCycle.java: -------------------------------------------------------------------------------- 1 | package com.hks.eightsortingalgorithms.leetcode; 2 | 3 | public class detectCycle { 4 | class ListNode { 5 | int val; 6 | ListNode next; 7 | 8 | ListNode(int x) { 9 | val = x; 10 | next = null; 11 | } 12 | } 13 | 14 | public ListNode detectCycle(ListNode head) { 15 | ListNode fast, slow; 16 | fast = slow = head; 17 | while (fast != null && fast.next != null) { 18 | fast = fast.next.next; 19 | slow = slow.next; 20 | if (fast == slow) break; 21 | } 22 | // 上面的代码类似 hasCycle 函数 23 | if (fast == null || fast.next == null) { 24 | // fast 遇到空指针说明没有环 25 | return null; 26 | } 27 | 28 | slow = head; 29 | while (slow != fast) { 30 | fast = fast.next; 31 | slow = slow.next; 32 | } 33 | return slow; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /java-algorithms/src/main/java/com/hks/eightsortingalgorithms/leetcode/pruneTree.java: -------------------------------------------------------------------------------- 1 | package com.hks.eightsortingalgorithms.leetcode; 2 | 3 | public class pruneTree { 4 | public class TreeNode { 5 | int val; 6 | TreeNode left; 7 | TreeNode right; 8 | 9 | TreeNode() { 10 | } 11 | 12 | TreeNode(int val) { 13 | this.val = val; 14 | } 15 | 16 | TreeNode(int val, TreeNode left, TreeNode right) { 17 | this.val = val; 18 | this.left = left; 19 | this.right = right; 20 | } 21 | } 22 | 23 | // 定义:输入一棵二叉树,返回的二叉树叶子节点都是 1 24 | public TreeNode pruneTree(TreeNode root) { 25 | if(root == null) { 26 | return null; 27 | } 28 | root.left = pruneTree(root.left); 29 | root.right = pruneTree(root.right); 30 | if(root.val == 0 && root.left == null && root.right ==null) { 31 | return null; 32 | } 33 | return root; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /java-lock/delombok/src-bak/src/main/java/com/hks/lock/spinLock/SpinLockTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 文件名:SpinLockTest.java 3 | * 版权:Copyright by www.yiche.com 4 | * 描述: 5 | * 修改人:hekuangsheng 6 | * 修改时间:2019/3/26 7 | * 跟踪单号: 8 | * 修改单号: 9 | * 修改内容: 10 | */ 11 | package com.hks.lock.spinLock; 12 | 13 | public class SpinLockTest implements Runnable{ 14 | SpinLock lock = new SpinLock(); 15 | 16 | public void get() { 17 | lock.lock(); 18 | System.out.println(Thread.currentThread().getId()); 19 | set(); 20 | lock.unlock(); 21 | } 22 | 23 | public void set() { 24 | lock.lock(); 25 | System.out.println(Thread.currentThread().getId()); 26 | lock.unlock(); 27 | } 28 | 29 | public void run() { 30 | get(); 31 | } 32 | 33 | public static void main(String[] args) { 34 | SpinLockTest ss = new SpinLockTest(); 35 | new Thread(ss).start(); 36 | new Thread(ss).start(); 37 | new Thread(ss).start(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /java-object/delombok/src-bak/src/main/java/com/hks/valuePass/RefrencePassTest.java: -------------------------------------------------------------------------------- 1 | package com.hks.valuePass; 2 | 3 | /** 4 | * @Author: hekuangsheng 5 | * @Date: 2018/10/29 6 | *

7 | * 引用传递: 8 | * ”引用”也就是指向真实内容的地址值,在方法调用时, 9 | * 实参的地址通过方法调用被传递给相应的形参,在方法体内, 10 | * 形参和实参指向相同的内存地址,对形参的操作会影响的真实内容。 11 | */ 12 | public class RefrencePassTest { 13 | 14 | public static void PersonCrossTest(Person person) { 15 | System.out.println("传入的person的name:" + person.getName()); 16 | person.setName("我是张小龙"); 17 | 18 | //加多此行代码 19 | ///无论是基本类型和是引用类型,在实参传入形参时,都是值传递,也就是说传递的都是一个副本,而不是内容本身。 20 | person = new Person(); 21 | person.setName("啊哈"); 22 | System.out.println("方法内重新赋值后的name:" + person.getName()); 23 | } 24 | 25 | public static void main(String[] args) { 26 | Person p = new Person(); 27 | p.setName("我是马化腾"); 28 | p.setAge(45); 29 | PersonCrossTest(p); 30 | System.out.println("方法执行后的name:" + p.getName()); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /java-object/src/main/java/com/hks/valuePass/ValuePassTest.java: -------------------------------------------------------------------------------- 1 | package com.hks.valuePass; 2 | 3 | /** 4 | * @Author: hekuangsheng 5 | * @Date: 2018/10/29 6 | *

7 | * 值传递: 8 | * 在方法被调用时,实参通过形参把它的内容副本传入方法内部, 9 | * 此时形参接收到的内容是实参值的一个拷贝, 10 | * 因此在方法内对形参的任何操作,都仅仅是对这个副本的操作,不影响原始值的内容。 11 | */ 12 | public class ValuePassTest { 13 | 14 | public static void valueCrossTest(int age, float weight) { 15 | System.out.println("传入的age:" + age); 16 | System.out.println("传入的weight:" + weight); 17 | 18 | age = 33; 19 | weight = 89.3f; 20 | 21 | System.out.println("方法内重新赋值后的age:" + age); 22 | System.out.println("方法内重新赋值后的weight:" + weight); 23 | } 24 | 25 | // 值传递传递的是真实内容的一个副本,对副本的操作不影响原内容,也就是形参怎么变化,不会影响实参对应的内容。 26 | public static void main(String[] args) { 27 | int a = 25; 28 | float w = 77.5f; 29 | valueCrossTest(a, w); 30 | System.out.println("方法执行后的age:" + a); 31 | System.out.println("方法执行后的weight:" + w); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /java-8future/src/test/java/FunctionTest.java: -------------------------------------------------------------------------------- 1 | import org.junit.Test; 2 | 3 | import java.util.function.Function; 4 | import java.util.stream.Stream; 5 | 6 | /** 7 | * @author heks 8 | * @description: TODO 9 | * @date 2020/11/11 10 | */ 11 | public class FunctionTest { 12 | /** 13 | * Function测试,function的作用是转换,将一个值转为另外一个值 14 | */ 15 | @Test 16 | public void test_Function() { 17 | //① 使用map方法,泛型的第一个参数是转换前的类型,第二个是转化后的类型 18 | Function function = new Function() { 19 | @Override 20 | public Integer apply(String s) { 21 | return s.length();//获取每个字符串的长度,并且返回 22 | } 23 | }; 24 | 25 | Stream stream = Stream.of("aaa", "bbbbb", "ccccccv"); 26 | Stream stream1 = stream.map(function); 27 | stream1.forEach(System.out::println); 28 | 29 | System.out.println("********************"); 30 | 31 | System.out.println(function.apply("heks")); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /java-algorithms/src/main/java/com/hks/eightsortingalgorithms/nowcoder/StackReverse.java: -------------------------------------------------------------------------------- 1 | package com.hks.eightsortingalgorithms.nowcoder; 2 | 3 | import java.util.Stack; 4 | 5 | public class StackReverse { 6 | public static int getLastVal(Stack stack) { 7 | int val = stack.pop(); 8 | if (stack.empty()) { 9 | return val; 10 | } else { 11 | int last = getLastVal(stack); 12 | stack.push(val); 13 | return last; 14 | } 15 | } 16 | 17 | public static void reverse(Stack stack) { 18 | if (stack.empty()) { 19 | return; 20 | } 21 | int i = getLastVal(stack); 22 | reverse(stack); 23 | stack.push(i); 24 | } 25 | 26 | public static void main(String[] args) { 27 | Stack stack = new Stack<>(); 28 | stack.add(1); 29 | stack.add(2); 30 | stack.add(3); 31 | reverse(stack); 32 | System.out.println(stack); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /java-lock/delombok/src-bak/src/main/java/com/hks/lock/spinLock/SpinLock1Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 文件名:SpinLock1Test.java 3 | * 版权:Copyright by www.yiche.com 4 | * 描述: 5 | * 修改人:hekuangsheng 6 | * 修改时间:2019/3/26 7 | * 跟踪单号: 8 | * 修改单号: 9 | * 修改内容: 10 | */ 11 | package com.hks.lock.spinLock; 12 | 13 | public class SpinLock1Test implements Runnable{ 14 | SpinLock1 lock = new SpinLock1(); 15 | 16 | public void get() { 17 | lock.lock(); 18 | System.out.println(Thread.currentThread().getId()); 19 | set(); 20 | lock.unlock(); 21 | } 22 | 23 | public void set() { 24 | lock.lock(); 25 | System.out.println(Thread.currentThread().getId()); 26 | lock.unlock(); 27 | } 28 | 29 | public void run() { 30 | get(); 31 | } 32 | 33 | public static void main(String[] args) { 34 | SpinLock1Test ss = new SpinLock1Test(); 35 | new Thread(ss).start(); 36 | new Thread(ss).start(); 37 | new Thread(ss).start(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /java-algorithms/src/main/java/com/hks/eightsortingalgorithms/leetcode/deleteDuplicates.java: -------------------------------------------------------------------------------- 1 | package com.hks.eightsortingalgorithms.leetcode; 2 | 3 | import org.aspectj.weaver.loadtime.definition.Definition; 4 | 5 | public class deleteDuplicates { 6 | 7 | public static void main(String[] args) { 8 | 9 | } 10 | // [1,1,2,3,3] 11 | public class ListNode { 12 | int val; 13 | ListNode next; 14 | ListNode() {} 15 | ListNode(int val) { this.val = val; } 16 | ListNode(int val, ListNode next) { this.val = val; this.next = next; } 17 | } 18 | 19 | public ListNode deleteDuplicates(ListNode head) { 20 | if (head == null) { 21 | return head; 22 | } 23 | 24 | ListNode cur = head; 25 | while (cur.next != null) { 26 | if (cur.val == cur.next.val) { 27 | cur.next = cur.next.next; 28 | } else { 29 | cur = cur.next; 30 | } 31 | } 32 | 33 | return head; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /java-classloader/delombok/src-bak/src/main/java/com/hks/classLoader/TestClassLoaderDemo.java: -------------------------------------------------------------------------------- 1 | package com.hks.classLoader; 2 | 3 | /** 4 | * 第三步,定义一个有main函数入口的public类来做验证 5 | */ 6 | public class TestClassLoaderDemo { 7 | 8 | public static void main(String[] args) throws InstantiationException, IllegalAccessException { 9 | Class thisCls = TestClassLoaderDemo.class; 10 | MyClassLoader myClassLoader = new MyClassLoader(); 11 | System.out.println(thisCls.getClassLoader()); 12 | System.out.println(myClassLoader.getParent()); 13 | try { 14 | //用自定义的类装载器来装载类,这是动态扩展的一种途径 15 | Class cls2 = myClassLoader.loadClass("com.hks.eightsortingalgorithms.classLoader.TestBeLoader"); 16 | System.out.println(cls2.getClassLoader()); 17 | TestBeLoader test=(TestBeLoader)cls2.newInstance(); 18 | } catch (ClassNotFoundException e) { 19 | e.printStackTrace(); 20 | } 21 | } 22 | 23 | /** 24 | * 第四步,查看运行结果 25 | */ 26 | 27 | } 28 | -------------------------------------------------------------------------------- /java-algorithms/src/main/java/com/hks/eightsortingalgorithms/leetcode/lowestCommonAncestor.java: -------------------------------------------------------------------------------- 1 | package com.hks.eightsortingalgorithms.leetcode; 2 | 3 | public class lowestCommonAncestor { 4 | public class TreeNode { 5 | int val; 6 | TreeNode left; 7 | TreeNode right; 8 | 9 | TreeNode(int x) { 10 | val = x; 11 | } 12 | } 13 | 14 | public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) { 15 | if (root == null || root == p || root == q) { 16 | return root; 17 | } 18 | TreeNode left = lowestCommonAncestor(root.left, p, q); 19 | TreeNode right = lowestCommonAncestor(root.right, p, q); 20 | if (left == null && right == null) { 21 | return null; 22 | } 23 | if (left != null && right != null) { 24 | return root; 25 | } 26 | if (left == null) { 27 | return right; 28 | } else { 29 | return left; 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /java-object/delombok/src-bak/src/main/java/com/hks/valuePass/ValuePassTest.java: -------------------------------------------------------------------------------- 1 | package com.hks.valuePass; 2 | 3 | /** 4 | * @Author: hekuangsheng 5 | * @Date: 2018/10/29 6 | *

7 | * 值传递: 8 | * 在方法被调用时,实参通过形参把它的内容副本传入方法内部, 9 | * 此时形参接收到的内容是实参值的一个拷贝, 10 | * 因此在方法内对形参的任何操作,都仅仅是对这个副本的操作,不影响原始值的内容。 11 | */ 12 | public class ValuePassTest { 13 | 14 | public static void valueCrossTest(int age, float weight) { 15 | System.out.println("传入的age:" + age); 16 | System.out.println("传入的weight:" + weight); 17 | 18 | age = 33; 19 | weight = 89.3f; 20 | 21 | System.out.println("方法内重新赋值后的age:" + age); 22 | System.out.println("方法内重新赋值后的weight:" + weight); 23 | } 24 | 25 | // 值传递传递的是真实内容的一个副本,对副本的操作不影响原内容,也就是形参怎么变化,不会影响实参对应的内容。 26 | public static void main(String[] args) { 27 | int a = 25; 28 | float w = 77.5f; 29 | valueCrossTest(a, w); 30 | System.out.println("方法执行后的age:" + a); 31 | System.out.println("方法执行后的weight:" + w); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /java-object/src/main/java/com/hks/hashcode/Person.java: -------------------------------------------------------------------------------- 1 | package com.hks.hashcode; 2 | 3 | public class Person { 4 | 5 | private Integer age; 6 | 7 | private String name; 8 | 9 | @Override 10 | public int hashCode () { 11 | return this.age; 12 | } 13 | 14 | @Override 15 | public boolean equals (Object obj) { 16 | return obj instanceof Person && 17 | this.age == ((Person) obj).age; 18 | } 19 | 20 | public Person() { 21 | } 22 | 23 | public Person(Integer age) { 24 | this.age = age; 25 | } 26 | 27 | public Person(Integer age, String name) { 28 | this.age = age; 29 | this.name = name; 30 | } 31 | 32 | public Integer getAge() { 33 | return age; 34 | } 35 | 36 | public void setAge(Integer age) { 37 | this.age = age; 38 | } 39 | 40 | public String getName() { 41 | return name; 42 | } 43 | 44 | public void setName(String name) { 45 | this.name = name; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /java-8future/delombok/src-bak/src/test/java/FunctionTest.java: -------------------------------------------------------------------------------- 1 | import org.junit.Test; 2 | 3 | import java.util.function.Function; 4 | import java.util.stream.Stream; 5 | 6 | /** 7 | * @author heks 8 | * @description: TODO 9 | * @date 2020/11/11 10 | */ 11 | public class FunctionTest { 12 | /** 13 | * Function测试,function的作用是转换,将一个值转为另外一个值 14 | */ 15 | @Test 16 | public void test_Function() { 17 | //① 使用map方法,泛型的第一个参数是转换前的类型,第二个是转化后的类型 18 | Function function = new Function() { 19 | @Override 20 | public Integer apply(String s) { 21 | return s.length();//获取每个字符串的长度,并且返回 22 | } 23 | }; 24 | 25 | Stream stream = Stream.of("aaa", "bbbbb", "ccccccv"); 26 | Stream stream1 = stream.map(function); 27 | stream1.forEach(System.out::println); 28 | 29 | System.out.println("********************"); 30 | 31 | System.out.println(function.apply("heks")); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /java-algorithms/src/main/java/com/hks/eightsortingalgorithms/method/sort/impl/SelectAlgorithmsImpl.java: -------------------------------------------------------------------------------- 1 | package com.hks.eightsortingalgorithms.method.sort.impl; 2 | 3 | import com.hks.eightsortingalgorithms.method.sort.SelectAlgorithms; 4 | import org.springframework.stereotype.Component; 5 | 6 | @Component 7 | public class SelectAlgorithmsImpl implements SelectAlgorithms { 8 | 9 | private static void exchang(int[] s, int i, int j) { 10 | int temp = s[j]; 11 | s[j] = s[i]; 12 | s[i] = temp; 13 | } 14 | 15 | @Override 16 | public int[] sort(int[] intArr) { 17 | int temp; 18 | for (int i = 0; i < intArr.length - 1; i++) { 19 | temp = i; 20 | for (int j = i + 1; j < intArr.length; j++) { 21 | if (intArr[temp] > intArr[j]) { 22 | temp = j; 23 | } 24 | } 25 | if (temp != i) { 26 | exchang(intArr, i, temp); 27 | } 28 | } 29 | return intArr; 30 | } 31 | } 32 | --------------------------------------------------------------------------------