經常會有人問,如果重寫了equals方法,是不是一定要重寫hashcode方法呢? 答案是yes,因為如果不重寫,那麼基於hash結構的那些東東比如hashMap,HashSet等等會出現非你想象的結果。why?看一下HashMap的源碼,get也是一樣的判斷邏輯:public V put(K key, V value) { if (key == null) return putForNullKey(value); int hash =
Why Isn’t the Swing Toolkit Multithread-Safe? After Swing components have been displayed on the screen, they should only be operated on by the event-handling thread. The event-handling thread (or just event thread) is started automatically by the
一個單獨的XML檔案不能做任何的工作,它需要與應用程式結合起來實現各種功能,應用程式通過XML解析器和XML應用程式介面處理XML檔案。我們現在就討論一下如何使用Java載入XML檔案並訪問其中的元素。 為了簡化編寫處理XML的應用程式,W3C已制訂出多種編程介面,其中包含的DOM和SAX(Simple API for XML)較為典型。在Java應用程式中要需要使用JAXP(Java API for XML)建立DOM或是SAX解析器來訪問XML檔案。
對於這個系列裡的問題,每個學Java的人都應該搞懂。當然,如果只是學Java玩玩就無所謂了。如果你認為自己已經超越初學者了,卻不很懂這些問題,請將你自己重歸初學者行列。內容均來自於CSDN的經典老貼。問題一:我聲明了什麼!String s = "Hello world!";許多人都做過這樣的事情,但是,我們到底聲明了什嗎?回答通常是:一個String,內容是“Hello
《深入理解Java虛擬機器》中講文法糖時,提到了下面這個例子(不是原文中的例子,我自己改過):public class AutoBoxingTest {/** * @param args */public static void main(String[] args) {Integer a = 1;Integer b = 2;Integer c = 127;Integer d = 127;Integer e = 3;Integer f = 3;Long g =
摘自:《Java Performance》第三章Initial Heap Space Size ConfigurationThis section describes how to use live data size calculations to determine an initial Java heap size. Figure 7-3 shows the fields that identify an application’s live data size. It is wise
在java中,一個線程用一個Thread對象表示一般每一個java程式都有一個main方法(applet沒有),它是主線程的進入點而用Thread表示的線程,進入點自然不是main了,而是run方法定義一個線程,主要就是寫它的run方法寫run有兩種方法,一種是繼承Thread類,然後重寫它的run另一種是實現Runnable介面,然後重寫它的run,如下所示:============================//用外部類實現多線程class ThreadTest2 { public
public class TestBigChar { public static char[] characters = {'零','一','二','三','四','五','六','七','八','九'}; public static char[] units = {'點','十','百','千'}; public static void main(String[] args) { System.out.println(convert(123.04
When multiple threads are interacting with an object, controls need to be in place to ensure that the threads don’t adversely affect one another. This chapter deals with issues that can introduce subtle errors in your application. An application
There are two ways to create a new class that can have a thread running within it. One way is to extend the Thread class. The other is to extend any class and implement the Runnable interface. For the sake of illustration, extending Thread is the