Thứ Năm, 27 tháng 1, 2011

4 Ways to Traverse a Map

Usually I don't need to traverse a java.util.Map, which is meant to be looked up, not iterated through. I traverse a java.util.Map primarily for debugging purposem, to dump its content. In case you do need to, here are 4 ways I've tried, just as examples:
import static java.net.HttpURLConnection.*;

private static void traverseMap() {
final String lineSeparator = System.getProperty("line.separator");
Map data = new HashMap();
data.put(HTTP_OK, "HTTP_OK");
data.put(HTTP_FORBIDDEN, "HTTP_FORBIDDEN");
data.put(HTTP_NOT_FOUND, "HTTP_NOT_FOUND");

System.out.println(lineSeparator + "Using JDK 5 foreach and entry set");
Set entries = data.entrySet();
for(Map.Entry entry : entries) {
    Object key = entry.getKey();
    Object value = entry.getValue();
    System.out.println(key + " = " + value);
}

System.out.println(lineSeparator + "Using Iterator and entry set");
for(Iterator it = entries.iterator(); it.hasNext();) {
    Map.Entry entry = it.next();
    Object key = entry.getKey();
    Object value = entry.getValue();
    System.out.println(key + " = " + value);
}

System.out.println(lineSeparator + "Using JDK 5 foreach and key set");
for(Object key : data.keySet()) {
    Object value = data.get(key);
    System.out.println(key + " = " + value);
}

System.out.println(lineSeparator + "Using traditional Iterator and key set");
for(Iterator it = data.keySet().iterator(); it.hasNext();) {
    Object key = it.next();
    Object value = data.get(key);
    System.out.println(key + " = " + value);
}
}
You may have noticed I'm using primitive int numbers (200, 403, 404) as the map key. Thanks to auto-boxing in JDK 5, I can use primitive s and their wrapper types interchangeably. Another useful feature in JDK 5 used here is using static import to import all HTTP status constants from java.net.HttpURLConnection.

Source: http://javahowto.blogspot.com/2006/06/4-ways-to-traverse-map.html

Thứ Ba, 25 tháng 1, 2011

How to Disable the Hidden Administrative Shares (c$,d$…) in Vista/XP/2003/2000

The system automatically creates hidden “administrative shares” for its logical drives C:, D:, and so forth which it names C$, D$ and so forth. It also creates the admin$ hidden share for to the \winnt or windows folder. These shares are designed for remote access support by domain administrators. By default, if you delete these admin shares, they will be recreated when you reboot. To disable permanently so they will not be recreated on the next reboot, use the following procedure.

Note:- Before doing this procedure please take a complete registry backup
For Workstations (Vista/XP/2000)
Click Start—>Run type regedit click ok
For vista users Enter your UAC credentials to continue.
Open the HKEY_LOCAL_MACHINE branch.
Open the SYSTEM branch.
Open the CurrentControlSet branch.
Open the Services branch.
Open the LanmanServer branch.
Select the Parameters branch.
Select Edit, New, DWORD (32-bit) Value. Vista adds a new value to the Parameters key (If you have the key just check for correct value).
Type AutoShareWks and press Enter. (You can leave this setting with its default value of 0.)
Restart Windows  to put the new setting into effect.
Solution 2
In Windows 2000 and Windows XP, you disable the shares via
Start —>Settings —>Control Panel
Systems Tools panel
Shared Folders
Double-click the Shared Folders branch to expand it
Click Shares
In the Shared Folder column, right-click the share you want to disable
Click Stop sharing
Cick OK.
For Servers (2003/2000)
Click Start—>Run type regedit click ok
Open the HKEY_LOCAL_MACHINE branch.
Open the SYSTEM branch.
Open the CurrentControlSet branch.
Open the Services branch.
Open the LanmanServer branch.
Select the Parameters branch.
Select Edit, New, DWORD (32-bit) Value. Vista adds a new value to the Parameters key (If you have the key just check for correct value).
Type AutoShareServer and press Enter. (You can leave this setting with its default value of 0.)
Restart Windows  to put the new setting into effect.