Skip to content

Commit 7856e30

Browse files
committed
Merge pull request giantray#36 from AutumnLight/patch-1
添加翻译与格式修改
2 parents f33f6d6 + 8c9a864 commit 7856e30

21 files changed

+63
-19
lines changed

README.md

+19-18
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ stackoverflow-Java-top-qa
2828
2929
* [Java += 操作符实质](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/java-operator.md)
3030
* [将InputStream转换为String](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/read-convert-an-inputstream-to-a-string.md)
31-
* [将数组转换为List](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/create-arraylist-arraylistt-from-array-t.md)
31+
* [将数组转换为List](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/create-arraylist-from-array.md)
3232
* [如何遍历map对象](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/iterate-through-a-hashmap.md)
3333
* [public,protected,private,不加修饰符。有什么区别呢?](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/in-java-whats-the-difference-between-public-default-protected-and-private.md)
34-
* [如何测试一个数组是否包含指定的值?](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/How-can-I-test-if-an-array-contains-a-certain-value.md)
34+
* [如何测试一个数组是否包含指定的值?](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/how-can-i-test-if-an-array-contains-a-certain-value.md)
3535
* [重写(Override)equlas和hashCode方法时应考虑的问题](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/what-issues-should-be-considered-when-overriding-equals-and-hashcode-in-java.md)
3636
* [从一个多层嵌套循环中直接跳出](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/breaking-out-of-nested-loops-in-java.md)
3737
* [如何将String转换为Int](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/converting-string-to-int-in-java.md)
@@ -40,33 +40,34 @@ stackoverflow-Java-top-qa
4040
* [`Map<Key,Value>`基于Value值排序](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/how-to-sort-a-mapkey-value-on-the-values-in-java.md)
4141
* [`HashMap和Hashtable的区别](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/differences-between-hashmap-and-hashtable.md)
4242
* [如何便捷地将两个数组合到一起](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/how-to-concatenate-two-arrays-in-java.md)
43-
* [Java 是否支持默认的参数值](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/Does-Java-support-default-parameter-values.md)
43+
* [Java 是否支持默认的参数值](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/does-java-support-default-parameter-values.md)
4444
* [Java 产生指定范围的随机数](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/generating-random-integers-in-a-range-with-Java.md)
4545
* [JavaBean 到底是什么](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/what-is-a-javabean-exactly.md)
4646
* [wait()和sleep()的区别](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/difference-between-wait-and-sleep.md)
47-
* [能否在一个构造器( `constructor` )中调用另一个构造器](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/How-do-i-call-one-constructor-from-another-in-java.md)
48-
* [ `finally` 代码块总会被执行么](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/Does-finally-always-execute-in-Java.md)
47+
* [能否在一个构造器( `constructor` )中调用另一个构造器](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/how-do-i-call-one-constructor-from-another-in-java.md)
48+
* [ `finally` 代码块总会被执行么](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/does-finally-always-execute-in-java.md)
4949
* [如何将String转换为enum](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/convert-a-string-to-an-enum-in-java.md)
50-
* [在Java中声明数组](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/Declare-array-in-Java.md)
51-
* [反射是什么及其用途](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/What-is-reflection-and-why-is-it-useful.md)
52-
* [为什么不能用string类型进行switch判断](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/Why-can't-I-switch-on-a-String.md)
50+
* [在Java中声明数组](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/declare-array-in-java.md)
51+
* [反射是什么及其用途](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/what-is-reflection-and-why-is-it-useful.md)
52+
* [为什么不能用string类型进行switch判断](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/why-cant-i-switch-on-a-string.md)
5353
* [比较java枚举成员使用equal还是==](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/comparing-java-enum-members-or-equals.md)
5454
* [用java怎么创建一个文件并向该文件写文本内容](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/how-to-create-a-file-and-write-to-a-file-in-java.md)
55+
* [serialVersionUID 有什么作用?该如何使用?](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/what-is-a-serialversionuid-and-why-should-i-use-it.md)
5556

5657
> 编程技巧
5758
5859
* [去掉烦人的“!=null"(判空语句](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/avoiding-null-statements-in-java.md)
5960
* [获取完整的堆栈信息](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/get-current-stack-trace-in-java.md)
6061
* [如何用一行代码初始化一个ArrayList](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/initialization-of-an-arraylist-in-one-line.md)
61-
* [初始化静态map](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/How-can-I-Initialize-a-static-Map.md)
62-
* [给3个布尔变量,当其中有2个或者2个以上为true才返回true](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/Check-if-at-least-two-out-of-three-booleans-are-true.md)
63-
* [输出 Java 数组最简单的方式](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/What's-the-simplest-way-to-print-a-Java-array.md)
62+
* [初始化静态map](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/how-can-i-initialize-a-static-map.md)
63+
* [给3个布尔变量,当其中有2个或者2个以上为true才返回true](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/check-if-at-least-two-out-of-three-booleans-are-true.md)
64+
* [输出 Java 数组最简单的方式](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/whats-the-simplest-way-to-print-a-java-array.md)
6465
* [为什么以下用随机生成的文字会得出 “hello world”?](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/why-does-this-code-using-random-strings-print-hello-world.md)
65-
* [什么在java中存放密码更倾向于char[]而不是String](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/why-is-cha[]-preferred-over-String-for-passwords-in-java.md)
66+
* [什么在java中存放密码更倾向于char[]而不是String](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/why-is-char-preferred-over-string-for-passwords-in-java.md)
6667
* [如何避免在JSP文件中使用Java代码](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/how-to-avoid-java-code-in-jsp-files.md)
67-
* [Java 源码里的设计模式](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/Examples_of_GoF_Design_Patterns_in_Java's_core_libraries.md)
68-
* [如何产生一个随机的字母数字串作为 session 的唯一标识符](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/How_to_generate_a_random_alpha-numeric_string.md)
69-
* [如何创建单例](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/What_is_an_efficient_way_to_implement_a_singleton_in_Java.md)
68+
* [Java 源码里的设计模式](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/examples-of-gof-design-patterns-in-javas-core-libraries.md)
69+
* [如何产生一个随机的字母数字串作为 session 的唯一标识符](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/how-to-generate-a-random-alpha-numeric-string.md)
70+
* [如何创建单例](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/what-is-an-efficient-way-to-implement-a-singleton-in-java.md)
7071
* [实现Runnable接口 VS. 继承Thread类](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/implements-runnable-vs-extends-thread.md)
7172
* [我应该用哪一个@NotNull注解](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/which-notnull-java-annotation-should-i-use.md)
7273
* [怎样将堆栈追踪信息转换为字符串](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/how-can-i-convert-a-stack-trace-to-a-string.md)
@@ -81,15 +82,15 @@ stackoverflow-Java-top-qa
8182
8283
* [LinkedList、ArrayList各自的使用场景,如何确认应该用哪一个呢?](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/when-to-use-linkedlist-over-arraylist.md)
8384
* [StringBuilder和StringBuffer有哪些区别呢](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/stringbuilder-and-stringbuffer.md)
84-
* [为什么处理排序的数组要比非排序的快](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/Why-is-processing-a-sorted-array-faster-than-an-unsorted-array.md)
85+
* [为什么处理排序的数组要比非排序的快](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/why-is-processing-a-sorted-array-faster-than-an-unsorted-array.md)
8586

8687
> 测试
8788
88-
* [如何测试 private 方法,变量或者内部类](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/How_to_test_a_class_that_has_private_methods,_fields_or_inner_classes.md)
89+
* [如何测试 private 方法,变量或者内部类](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/how-to-test-a-class-that-has-private-methods-fields-or-inner-classes.md)
8990

9091
> Android
9192
92-
* [在Android里面下载文件,并在ProgressDialog显示进度](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/Download_a_file_with_Android_and_showing_the_progress_in_a_ProgressDialog.md)
93+
* [在Android里面下载文件,并在ProgressDialog显示进度](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/download-a-file-with-android-and-showing-the-progress-in-a-progressdialog.md)
9394
* [如何获取Android设备唯一ID](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/is-there-a-unique-android-device-id.md)
9495

9596
### 待翻译问题链接(还剩x问题)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# 如何使用Java创建一个内存泄漏的程序
2+
3+
## 问题:
4+
我在一个面试的过程中被问到如何使用Java创建一个内存泄漏的程序。毫无疑问地说,我当时哑口无言,根本不知道如何开始编码。
5+
6+
## 解答
7+
在Java下有一个很好的方法来创建内存泄漏程序--通过使得对象不可访问但任然存储在内存中。
8+
9+
1. 应用程序创建一个长期运行的线程A 或者 使用一个线程池来加快泄漏的速度。
10+
11+
2. 线程A使用ClassLoader(用户可以自定义)加载一个类 B。
12+
13+
3. 在类B申请一块很大的连续内存(例如:new byte[1000000]),
14+
并使用一个静态成员变量保存该空间的一个强引用,之后在一个ThreadLocal对象中存储类B对象的引用。
15+
虽然泄漏这个类的一个实例就足够了,但是也可以通过申请多个实例的方法来加快内存泄漏的速度。
16+
17+
4. 线程A清理所有指向自定义类或者通过ClassLoadeer加载的引用。
18+
19+
5. 重复上述步骤
20+
21+
上述方式可以达到内存泄漏的目的,因为 ThreadLocal 存储了一个指向类B对象的引用,
22+
而该对象又保存了一个指向其类的引用,这个类又保存了一个指向其ClassLoader的引用,
23+
而ClassLoader又保存了一个通过它加载的所有类的引用。
24+
这种方法在许多的JVM的实现中表现更糟糕,因为Classes和ClassLoader被直接存储在老年代(permgen)并且永远都不会被GC处理。
25+
26+
******************************下方为个人理解************************************
27+
28+
通过一个简单的图来描述上述关系:<br>
29+
ThreadLocal.obj ---> B.obj ---> B.class <--> ClassLoader.obj<br>
30+
注:上图的\*.obj表示\*类的一个实例对象,B.class表示类B的Class对象
31+
32+
******************************上方为个人理解************************************
33+
34+
这个模式的一个变形:如果频繁的重新部署那些可能使用ThreadLocals的应用,应用容器(例如Tomcat)就会像筛子一样泄漏内存。
35+
因为应用容器使用上述所说的线程,每次重新部署应用时,应用容器都会使用一个新的ClassLoader。
36+
37+
具体代码可以参考:https://gist.github.com/dpryden/b2bb29ee2d146901b4ae
38+
39+
参考:http://frankkieviet.blogspot.com/2006/10/classloader-leaks-dreaded-permgen-space.html
40+
41+
stackoverflow原址:http://stackoverflow.com/questions/6470651/creating-a-memory-leak-with-java
File renamed without changes.

contents/What_is_a_serialVersionUID_and_why_should_I_use_it.md contents/what-is-a-serialversionuid-and-why-should-i-use-it.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
# serialVersionUID 有什么作用?该如何使用?
1+
# serialVersionUID 有什么作用?该如何使用?
2+
##问题
23

34
当一个对象实现 Serializable 接口时,多数 ide 会提示声明一个静态常量 serialVersionUID(版本标识),那 serialVersionUID 到底有什么作用呢?应该如何使用 serialVersionUID ?
45

6+
##回答
57
serialVersionUID 是实现 Serializable 接口而来的,而 Serializable 则是应用于Java 对象序列化/反序列化。对象的序列化主要有两种用途:
68

79
- 把对象序列化成字节码,保存到指定介质上(如磁盘等)

0 commit comments

Comments
 (0)