2024-04-20 09:00:01

Java的隐藏特性

在阅读了c#的隐藏特性之后,我想知道Java的隐藏特性有哪些?


当前回答

在Swing中工作时,我喜欢隐藏的Ctrl - Shift - F1特性。

它转储当前窗口的组件树。 (假设您没有将该击键绑定到其他内容。)

其他回答

JDK 1.6_07+包含一个名为VisualVM (bin/jvisualvm.exe)的应用程序,它是许多工具之上的一个漂亮的GUI。它似乎比JConsole更全面。

一种可以为基于Java控制台的应用程序显示启动画面的功能。

使用带有-splash选项的命令行工具java或javaw

eg:

java -splash:C:\myfolder\myimage.png -classpath myjarfile.jar com.my.package.MyClass

C:\myfolder\myimage.png的内容将显示在你的屏幕中央,每当你执行类"com.my.package.MyClass"

java.util.Arrays中的asList方法允许变量参数、泛型方法和自动装箱的良好组合:

List<Integer> ints = Arrays.asList(1,2,3);

我知道这是在1.5版中添加的,但是新的enum类型是一个很棒的特性。不必使用旧的“int enum模式”极大地帮助了我的一堆代码。看看JLS 8.9的甜肉汁你的土豆!

The power you can have over the garbage collector and how it manages object collection is very powerful, especially for long-running and time-sensitive applications. It starts with weak, soft, and phantom references in the java.lang.ref package. Take a look at those, especially for building caches (there is a java.util.WeakHashMap already). Now dig a little deeper into the ReferenceQueue and you'll start having even more control. Finally grab the docs on the garbage collector itself and you'll be able to control how often it runs, sizes of different collection areas, and the types of algorithms used (for Java 5 see http://java.sun.com/docs/hotspot/gc5.0/gc_tuning_5.html).