`

Java Advance

    博客分类:
  • Java
阅读更多

1. A class with a given name can only be loaded once by a given classloader.

 

2. When the JVM is started, three class loaders are used:

    1.Bootstrap class loader - loads the core Java libraries(<JAVA_HOME>/lib directory). This class loader, which is part of the core JVM, is writtern in native code.

    2.Extensions class loader - loads the code in the extensions directories(<JAVA_HOME>/lib/ext or any other directory specified by the java.ext.dirs system property). It's implemented by the sun.misc.Launcher$ExtClassLoader class.

    3.System class loader - loads code found on java.class.path, which maps to the system CLASSPATH variable. This is implemented by the sun.misc.Launcher$AppClassLoader class.

 

2. Thread

Thread.yield(); -- you are suggesting that otehr threads with the same priority might be run.

Thread.sleep(); -- throws InterruptedException

TimeUnit.MILLISECONDS.sleep(100); /j2se5 or 6

Thread.currentThread();

thread1.join(); -- the main thread waits thread1 task finish. The call to join() may be aborted by calling interrupt() on the calling thread.

thread1.interrupt(); -- the main thread will go on process since the thread1 has been interruptted.

wait(),notify(),notifyAll() - should define in 'synchronized' method or block, otherwise, IllegalMonitorStateException will throw in runtime.

 

synchronized(x) { 

  x.notifyAll(); 

}

 

3.ArrayList vs. Vector

Collection

©ÀList     ----- sortable

©¦©ÀLinkedList

©¦©ÀArrayList  --- expand 50%, non-thread-safe

©¦©¸Vector  --- expand 100%, thread-safe

©¦¡¡©¸Stack

©¸Set     ------ no-sortable, no-duplicate

Map

©ÀHashtable

©ÀHashMap

©¸WeakHashMap  --- if the key object is not referenced by outside, then the entry will be GCed.

 

4.Reflection:

Class<String> clz = (Class<String>) Class.forName("java.lang.String");

System.out.println("getTypeParameters():");

for(TypeVariable tv :clz.getTypeParameters()) {

    System.out.println(tv);

}

System.out.println("getSuperClass():");

System.out.println(clz.getSuperclass().getCanonicalName());

 

System.out.println("clz.getModifiers():");

System.out.println(Modifier.toString(clz.getModifiers()));

 

 

System.out.println("getInterfaces():");

for(Class c : clz.getInterfaces()) {

    System.out.println(c.getCanonicalName());

}

 

5.Regex:

jpql.replaceFirst("^(?i)SELECT ((?!FROM).)* FROM", "SELECT COUNT(r.id) FROM");

 

6.Keystore:

    1. gen a keystore file:

        keytool -genkey -alias jetty -keyalg RSA -keystore my.keystore

 

7.Java Locale:

append -J-Duser.country=US to any java command.

or -J-Duser.language=en

 

to find all java system properties:

for(Map.Entry<Object, Object> s : System.getProperties().entrySet()) {

    System.out.println(s.getKey() + "=" + s.getValue());

}

 

e.g.: keytool -genkey -alias jetty -keyalg RSA -keystore .keystore -J-Duser.language=en

 

8. compile/run java in shell:

$javac com/asran/HelloWorld.java

$java com.asran.HelloWorld

 

9. join list as string with comma separated:

org.apache.commons.lang.StringUtils.join(list, ",");

 

10. -javaagent:***-agent.jar

MySimpleTransformer.java

------------------------------------------------------------------------------------------

package com.asran.javagent;

import java.lang.instrument.ClassFileTransformer;

import java.lang.instrument.IllegalClassFormatException;

import java.security.ProtectionDomain;

 

public class MySimpleTransformer implements ClassFileTransformer {

    public byte[] transform(ClassLoader classloader,

                                String classname,

                                Class redefinedclass,

                                ProtectionDomain protectiondomain,

                               byte b[]) throws IllegalClassFormatException {

        if (!classname.endsWith("HelloWorld"))

            return (null);

 

        String line = "";

        for (int i = 0; i < b.length; i++) {

            line += Byte.toString(b[i]) + " ";

            if (line.length() > 60) {

                System.out.println(line);

                line = "";

            }

            if (b[i] == (byte) '6')

                b[i] = (byte) '7';

        }

        System.out.println(line);

        System.out.println("The number of bytes in HelloWorld: " + b.length);

        return (b);

    }

}

 

MySimpleAgent.java

------------------------------------------------------------------------------------------

package com.asran.javagent;

import java.lang.instrument.Instrumentation;

 

public class MySimpleAgent {

    public static void premain(String agentArgs, Instrumentation inst) {

        inst.addTransformer(new MySimpleTransformer());

    }

}

 

HelloWorld.java

------------------------------------------------------------------------------------------

package com.asran.javagent;

 

public class HelloWorld {

    public static void main(String arg[]) {

        System.out.println("The number six is 6");

    }

}

 

MyManifest.mf

------------------------------------------------------------------------------------------

Premain-Class: com.asran.javagent.MySimpleAgent

(carriage return[CR] is mandantory)

 

Test:

------------------------------------------------------------------------------------------

>jar cvfm MyAgent.jar MyManifest.mf com/asran/javagent/MySimpleAgent.class com/asran/javagent/MySimpleTransformer.class

>java -javaagent:MyAgent.jar com.asran.javagent.HelloWorld

分享到:
评论

相关推荐

    Java Basic, Java Advance, Sprint Cloud.zip

    这个压缩包"Java Basic, Java Advance, Spring Cloud.zip"包含了从基础到高级,再到Spring Cloud的相关学习资源,旨在帮助开发者深入理解Java及其在云计算环境中的应用。 Java Basic部分是Java初学者的起点,它涵盖...

    Java Advanced Imaging API和Java Image IO Technology包 for Linux.rar

    jai_imageio-1_1-lib-linux-amd64-jdk.bin jai_imageio-1_1-lib-linux-amd64-jre.bin jai_imageio-1_1-lib-linux-i586-jdk.bin jai_imageio-1_1-lib-linux-i586-jre.bin jai-1_1_3-lib-linux-amd64-jdk.bin ...

    java72-java-advance.zip

    "java72-java-advance.zip"文件很可能包含了关于Java高级特性和技术的资源,特别是针对Java 7版本的深入学习材料。Java 7是Java发展历程中的一个重要里程碑,引入了许多新特性,旨在提高开发者的生产力和代码的可...

    java72-java-advance源代码.zip

    "java72-java-advance源代码.zip" 这个标题表明这是一个关于Java编程语言的高级主题的源代码集合。数字"72"可能是版本号或者是某种编码方式,而"java-advance"则暗示这包含了Java的进阶内容,可能包括一些复杂的数据...

    java72-java-advance.rar

    a)java.sql b) java.util c) java.math d) java.io 2.不属于java.io包中的接口的一项是(C) a)DataInput b) DataOutput c) DataInputStream d) ObjectInput 3. ByteArrayOutputStream将下列哪一项作为输出流 C a)...

    java-advance:java进阶,包含 常用设计模式、线程和并发、spring核心代码、mybatis核心代码、springboot2.0、springcloud G版本、docker的使用、各类面试题

    java进阶源码分析专题常用设计模式线程与并发锁的使用深度理解synchronized、volatile、cas手写ASQSpring5IOC容器设计原理及高级特性AOP设计原理FactoryBean与BeanFactorySpring事务处理机制Spring JDK动态代理...

    ADVANCE_JAVA-源码.rar

    《深入解析ADVANCE_JAVA源码》 ADVANCE_JAVA-源码.rar 是一个压缩包文件,其中包含的源码是针对高级Java编程的学习资源。Java作为一种广泛应用的编程语言,其高级特性对于开发者来说至关重要,这包括但不限于多线程...

    Java并发包源码解析-Java-InterviewNotes-Advance:Java-InterviewNotes-Advance包含面试

    Java-InterviewNotes-Advance系码上代码公众号和csdn博客同步分享,包含面试常见高并发,分布式,海量数据常见面试题和技术解决方案,以及springcloud源码解析,Elasticsearch等中间件专栏,JVM原理,mysqly,Redis...

    AdvanceJava:Advance Java 示例程序

    #JDBC:学习序列 ConnectToMySQLDB.java GetRecord.java InsertRecord.java InsertRecordWithTx.java CreateTable.java AlterTable.java DropTable.java 获取元数据 CallStoredFunction.java CallStoredProcedure....

    DefendPeace:用Java制作的Advance Wars的克隆

    《DefendPeace:Java语言实现的Advance Wars克隆游戏解析》 Advance Wars是一款深受玩家喜爱的策略战棋游戏,而DefendPeace则是开发者利用Java编程语言制作的一款与其类似的游戏克隆作品。通过深入剖析DefendPeace...

    Advance-Java

    "Advance-Java"通常指的是Java的高级特性、框架和技术,这些内容是Java开发者进阶必备的知识。以下将详细探讨一些Java高级领域的知识点。 1. **多线程编程**:Java提供了内置的多线程支持,通过实现Runnable接口或...

    官方,主要这是 Core,Advance Java 示例系列项目 它有助于使用此处提供的 PDF 教程和相应的 Eclipse 演示项目逐步学习 Java 标签Java 学生、Java 课程、.zip

    JavaStud这是 Java 教程示例系列。请访问http://yro-tech.blogspot.com/博客获取更多资源。1. 简介2.OOP3. 异常处理、内部类、日期时间、Joda 时间、反射4. 多线程、IO、序列化5. 集合、Java 泛型6. JDBC7. Swing ...

    Java.to.Python 高清完整epub版

    I had already known Java and worked with it professionally for some time, but I found myself having to learn Python fast to advance in my career. It motivated me to find a way to harness my existing ...

    Advance_prg.zip_it

    【标题】"Advance_prg.zip_it" 涉及的主题是高级Java编程,这通常指的是在基础Java语法之上更深入的技术和概念。这个压缩包很可能包含了一系列的示例代码,用于展示和解释Java编程中的高级特性。 【描述】"It ...

    Advance_Java_Assignments

    "Advance_Java_Assignments" 是一个针对高级Java编程的学习资源集合,可能包含了多个实践项目或练习题,旨在帮助开发者深化对Java语言的理解并提升其编程技能。在深入探讨这些高级Java主题之前,我们首先需要了解...

    testing java microservices

    You'll advance from writing simple unit tests for individual services to more-advanced practices like chaos or integration tests. As you move towards a continuous-delivery pipeline, you'll also ...

    Advance-Java-Programs

    在“Advanced-Java-Programs”这个主题中,我们探讨的是...在“Advance-Java-Programs-master”这个压缩包中,可能包含了相关的代码示例、项目练习或者教程文档,这些都是进一步学习和掌握这些高级Java概念的宝贵资源。

    Apache Spark 2.x for Java Developers

    Apache Spark 2.x for ...Spark Programming Model - Advance concepts Working with Spark SQL Near real time processing with Spark Streaming Machine learning analytics with Spark MLlib Learning Spark GraphX

    workshop-advance-java-02

    《深入探索Java高级技术——workshop-advance-java-02详解》 在Java的世界里,不断探索和学习是提升技术水平的关键。"workshop-advance-java-02"这个项目,显然是一个专注于Java高级技术的工作坊,旨在帮助开发者...

    程序员考试刷题-Advance-Java:高级Java

    Java 培训 Banuprakash C 联合创始人 Lucida Technologies Pvt Ltd., 全栈架构师 GitHub: 所需软件: JDK 8:[Java SE 8u261] 面向 Java 企业开发人员的 Eclipse MySQL 5:[不是 MySQL 8:8 的一些问题] 下载在 ...

Global site tag (gtag.js) - Google Analytics