Friday, December 23, 2011

VARIOUS WAYS TO ITERATE MAP OR HASHMAP IN JAVA

How to Iterate MAP or HASHMAP in JAVA

Map<Integer, Integer> map = new HashMap<Integer, Integer>();

for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
    System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
}


Map<Integer, Integer> map = new HashMap<Integer, Integer>();

//iterating over keys only
for (Integer key : map.keySet()) {
    System.out.println("Key = " + key);
}
//iterating over values only
for (Integer value : map.values()) {
    System.out.println("Value = " + value);
}Map<Integer, Integer> map = new HashMap<Integer, Integer>();

Iterator<Map.Entry<Integer, Integer>> entries = map.entrySet().iterator();
while (entries.hasNext()) {
    Map.Entry<Integer, Integer> entry = entries.next();
    System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
}


Map map = new HashMap();

Iterator entries = map.entrySet().iterator();

while (entries.hasNext()) {
    Map.Entry entry = (Map.Entry) entries.next();
    Integer key = (Integer)entry.getKey();
    Integer value = (Integer)entry.getValue();
    System.out.println("Key = " + key + ", Value = " + value);
}


Map<Integer, Integer> map = new HashMap<Integer, Integer>();

for (Integer key : map.keySet()) {
    Integer value = map.get(key);
    System.out.println("Key = " + key + ", Value = " + value);
}

Monday, December 19, 2011

(AVD) Android Emulator not loading on netbeans







































Step 1 ) Open your AVD manager


Step 2 ) Click on new button on the right hand side top corner


Step 3 ) Now follow the Images given here





Step 4) Now restart yous Netbeans and Run your android application.


Step 5 ) Thank You.











Wednesday, December 7, 2011

HOW TO DEBUG JAVA CODE IN ECLIPSE

 1. Introduction
Debugging allows you to run the program interactively and to watch the source code and the variables during this execution.
A Java program can be started in "Debug mode". You can set breakpoints in your Java code in which the execution of the Java code will stop if the Java program is executed in "Debug mode".

2 .Set Breakpoints

To set breakpoints right click in the small left column in your source code editor and select "Toggle Breakpoint". Or you can double click on this position.


































3. Star Debugger

You can debug your application, select a Java file which contains a main method, right click it and select Run →Debug.















If you have not defined any breakpoints, this will run your program as normal. To debug the program you need to define breakpoints.
If you start the debugger the first time, Eclipse ask you if you want to switch to the debug perspective. Answer "yes". You should then see a perspective similar to the following.
















You can use F5 / F6, F7 and F8 to step through your coding. The meaning of these keys are explained in the following table.

CommandDescription
F5Goes to the next step in your program. If the next step is a method / function this command will jump into the associated code.
F6F6 will step over the call, e.g. it will call a method / function without entering the associated code.
F7F7 will go to the caller of the method/ function. So this will leave the current code and go to the calling code.
F8Use F8 to go to the next breakpoint. If no further breakpoint is encountered then the program will normally run.

















Thank You.