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.


Tuesday, November 29, 2011

NETBEANS SHORTCUTS (Debugging)


Debugging
Ctrl-F5                        Start debugging main project

Ctrl-Shift-F5              Start debugging current file

Ctrl-Shift-F6              Start debugging test for file
(JUnit)
Shift-F5/F5                Stop/Continue debugging session

F4                               Run to cursor location in file

F7/F8                          Step into/over

Ctrl-F7                        Step out

Ctrl-Alt-Up                 Go to called method

Ctrl-Alt-Down            Go to calling method

Ctrl-F9                        Evaluate expression

Ctrl-F8                        Toggle breakpoint

Ctrl-Shift-F8              New breakpoint

Ctrl-Shift-F7              New watch

Enhanced by Zemanta

NETBEANS SHORTCUTS (JSP Editor Code Templates)


JSP Editor Code Templates
ag                    application.getAttribute("|")

ap                    application.putAttribute("|",)

ar                     application.removeAttribute("|")

cfgi                  config.getInitParameter("|")

jspf                 

jspg                 

jspi                  

jspp                 

jsps                 

jspu                 

oup                  out.print("|")

oupl                 out.println("|")


pcg                  pageContext.getAttribute("|")

pcgn                pageContext.getAttributeNamesInScope("|")

pcgs                pageContext.getAttributesScope("|")

pcr                   pageContext.removeAttribute("|")

pcs                  pageContext.setAttribute("|",)

pg                    <%@page |%>

pga                  <%@page autoFlush="false"%>

pgb                  <%@page buffer="|kb"%>

pgc                  <%@page contentType="|"%>

pgerr                <%@page errorPage="|"%>

pgex                <%@page extends="|"%>

pgie                 <%@page isErrorPage="true"%>

pgim                <%@page import="|"%>

pgin                 <%@page info="|"%>

pgit                  <%@page isThreadSafe="false"%>

pgl                   <%@page language="java"%>

pgs                  <%@page session="false"%>

rg                     request.getParameter("|")

sg                    session.getAttribute("|")

sp                    session.setAttribute("|", )

sr                     session.removeAttribute("|")

tglb                  <%@taglib uri="|"%>

Enhanced by Zemanta

NETBEANS SHORTCUTS (Coding in Java)


Coding in Java

Alt-Insert                    Generate code

Ctrl-Shift-I                  Fix all class imports

Alt-Shift-I                   Fix selected class's import

Alt-Shift-F                  Format selection

Alt-Shift Left/             Shift lines left/right/up/down
Right/Up/Down

Ctrl-Shift-Up/D          Copy lines up/down

Ctrl/Alt-F12                Inspect members/hierarchy

Ctrl-/                            Add/remove comment lines

Ctrl-E                          Delete current line


Ctrl-K/Ctrl-Shift K     Next/previous word match

Alt-Left/Alt-                Go backward/forward/to last

Right/Ctrl-Q               edit

Alt Up/Down              Next/previous marked occurrence

NETBEANS SHORTCUTS (Navigating through Source Code)


Navigating through Source Code

Ctrl-O/Alt-Shift-O       Go to type/file

Ctrl-Shift-T                  Go to JUnit test

Alt-O                           Go to source

Ctrl-B                          Go to declaration

Ctrl-G                          Go to line

Ctrl-Shift-M                 Toggle add/remove bookmark

Ctrl-Shift-Period/Comma    Next/previous bookmark

Ctrl-Period/Comma    Next/previous usage/compileerror

Ctrl-Shift-1/2/3           Select in Projects/Files/Favorites

Ctrl-[                          Move caret to matching bracket

Ctrl-K/Ctrl-Shift K     Next/previous word match

Alt-Left/Alt-                Go backward/forward/to last

Right/Ctrl-Q               edit

Alt Up/Down             Next/previous marked occurrence

NETBEANS SHORTCUTS (Finding, Searching, and Replacing)



Finding, Searching, and Replacing

Ctrl-F3                      Search word at insert point

F3/Shift-F3                Find next/previous in file

Ctrl-F/H                    Find/Replace in file

Alt-F7                       Find usages

Ctrl-Shift-F/H            Find/replace in projects

Alt-Shift-U                 Find usages results

Alt-Shift-H                 Turn off search result highlights

Ctrl-R                        Rename

Ctrl-U,                       then U Convert selection to uppercase

Ctrl-U,                       then L Convert selection to lowercase

Ctrl-U,                      then S Toggle case of selection

Ctrl-Shift-V               Paste formatted

Ctrl-I J                       ump to quick search field


Wednesday, November 16, 2011

WHAT IS UTF-8 ?



UTF-8 :   UCS Transformation Format — 8-bit
Unicode is a character set supported across many commonly used software applications and operating systems.
Operating systems that support Unicode include Solaris Operating Environment, Linux, Microsoft Windows 2000, and Apple’s Mac OS X.
Applications that support Unicode are often capable of displaying multiple languages and scripts within the same document.
In a multilingual office or business setting, Unicode’s importance as a universal character set cannot be overlooked.
Unicode is the only practical character set option for applications that support multilingual documents.
An encoding is the mapping of Unicode code points to a stream of storable code units or octets.

Enhanced by Zemanta

JAVA CODE FOR VARIOUS DIALOG BOXES



import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.UIManager;

public class TestDialogue extends JFrame implements ActionListener {
    JButton button1 =null;
    JButton button2 =null;
    JButton button3 =null;

  public TestDialogue() throws HeadlessException {
    setSize(200, 200);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    button1 = new JButton("Simple Message dialog");
    button2 = new JButton("Dialog with InputBox");
    button3 = new JButton("Yes/No dialog");

    setLayout(new FlowLayout(FlowLayout.CENTER));
    getContentPane().add(button1);
    getContentPane().add(button2);
    getContentPane().add(button3);

    button1.addActionListener(this);
    button2.addActionListener(this);
    button3.addActionListener(this);
  }

  public static void main(String[] rk) {
        try
 {
  UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
 }catch(Exception e)
        {}
        new TestDialogue().setVisible(true);
  }

    @Override
    public void actionPerformed(ActionEvent e) {
    String Action;
    Action = e.getActionCommand ();

        if(Action.equals("Simple Message dialog")){
            JOptionPane.showMessageDialog((Component) e.getSource(), "Hello ! Thank you!");

        }else if(Action.equals("Dialog with InputBox")){
            String name = JOptionPane.showInputDialog((Component) e.getSource(), "Hello, please Input your name.");
            if (name != null && !name.equals("")) {
                JOptionPane.showMessageDialog((Component) e.getSource(), "Hi, " + name);
            }

        }else if(Action.equals("Yes/No dialog")){

            int result = JOptionPane.showConfirmDialog((Component) e.getSource(), "Close this application?");
            if (result == JOptionPane.YES_OPTION) {
            System.exit(0);
            } else if (result == JOptionPane.NO_OPTION) {
            System.out.println("No Action performed.");

        }
       }

    }
}

Enhanced by Zemanta

Thursday, November 10, 2011

What is URLEncoding in Java ?


Utility class for HTML form encoding. This class contains static methods for converting a String to the application/x-www-form-urlencoded MIME format. For more information about HTML form encoding, consult the HTML specification.
When encoding a String, the following rules apply:
  • The alphanumeric characters "a" through "z", "A" through "Z" and "0" through "9" remain the same.
  • The special characters ".", "-", "*", and "_" remain the same.
  • The space character " " is converted into a plus sign "+".
  • All other characters are unsafe and are first converted into one or more bytes using some encoding scheme. Then each byte is represented by the 3-character string "%xy", where xy is the two-digit hexadecimal representation of the byte. The recommended encoding scheme to use is UTF-8. However, for compatibility reasons, if an encoding is not specified, then the default encoding of the platform is used.

Tuesday, November 8, 2011

CSS CODE FOR MOUSE POINTERS

style="cursor: default;"
style="cursor: hand;"
style="cursor: pointer;"
style="cursor: pointer; cursor: hand;"
style="cursor: crosshair;"
style="cursor: text;"
style="cursor: wait;"
style="cursor: help;"
style="cursor: move;"
e-resize
style="cursor: e-resize;"
ne-resize
style="cursor: ne-resize;"
nw-resize
style="cursor: nw-resize;"
n-resize
style="cursor: n-resize;"
se-resize
style="cursor: se-resize;"
sw-resize
style="cursor: sw-resize;"
s-resize
style="cursor: s-resize;"
w-resize
style="cursor: w-resize;"
progress
style="cursor: progress;"
all-scroll
style="cursor: all-scroll;"
col-resize
style="cursor: col-resize;"
no-drop
style="cursor: no-drop;"
not-allowed
style="cursor: not-allowed;"
row-resize
style="cursor: row-resize;"
url(uri)
style="cursor: url(mycursor.cur);"
IE6vertical-text
style="cursor: vertical-text;"

Monday, November 7, 2011

jQuery function , Selectors, Fade effect.

jQuery function

  • You use this to select elements from an HTML page to manipulate.
  • The $ shortcut means you don't have to type “jQuery" over and over.
  • The jQuery function can handle selectors, straight HTML, and even JavaScript objects.

Selectors

  • jQuery selects elements the same way CSS does: with selectors.
  • Just about any kind of HTML element is fair game for a jQuery selector.

Fade effect
  • Once you've selected an element, you can fade it in a variety of ways, using FadeIn, FadeOut, FadeTo, and FadeToggle.
  • You can fade in all kinds of elements, from text to images and more.
  • Control the speed of your fade effect by putting a time (in milliseconds) value inside the parentheses at the end of the statement.

Tuesday, November 1, 2011

Convert JAVA DATE to MS SQL datetime format


SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");

Date javaDate=new Date();

System.out.println("Java Date : "+javaDate);

String msSqlDate=sdf.format(javaDate).trim();

System.out.println("Ms Sql Date : "+msSqlDate.replace(" ","T"));

insert into DATA (CREATED) values (convert(datetime,'"+msSqlDate+"'));

Monday, October 17, 2011

Dennis Ritchie, father of C programming language, is in Paradise now




The New York Times reported that Ritchie died on October 12 after a prolonged illness at age 70.


Ritchie died at his home over the weekend,
His Wikipedia entry was updated to say he had died in Murray Hill, N.J.


In addition to being the creator of C, Ritchie co-authored "The C Programming Language", commonly referred to as K&R (after the authors, Brian Kernighan and Ritchie) and widely considered the definitive work on C. He also made significant contributions to the development of the Unix operating system, for which he received the Turing Award in 1983 along with Kenneth Thompson.





President Bill Clinton awarded Ritchie and Thompson the National Medal of Technology in 1999 for their contributions to Unix and C. He won many other national and international awards for his work and was elected to the National Academy of Engineering in 1988 for "development of the C programming language and for co-development of the Unix operating system".



Dennis was well loved by his colleagues at Bell Labs, and will be greatly missed. He was truly an inspiration to all of us, not just for his many accomplishments, but because of who he was as a friend, an inventor, and a humble and gracious man.


 Ritchie had the lifestyle and habits to match his position as an early guru of IT. Long-haired and bearded, and famously more owl than lark, he started work at midday in his industry-standard chaotic office, emerging late in the evening to go home and carry on working through to the small hours at the end of a leased line connected to the Bell Labs computers....

His ideas live on, in the rudest of health, at the centre of modern operating system design, in new programming languages, and in every electron and bit of open systems.


I wish god may give them peace and paradise.

Friday, October 14, 2011

All About Java Collection : Useful Point wise information



What Do You Do with a Collection?
  • Add objects to the collection.
  • Remove objects from the collection.
  • Find out if an object (or group of objects) is in the collection.
  • Retrieve an object from the collection (without removing it).
  • Iterate through the collection, looking at each element (object) one after another.
Key Interfaces and Classes of the Collections Framework

  • Collection
  • Set
  • SortedSet
  • List
  • Map
  • SortedMap
  • Queue 

Maps
·         HashMap
·         Hashtable
·         TreeMap
·         LinkedHashMap

Sets
·         HashSet
·         LinkedHashSet
·         TreeSet

Lists
·         ArrayList
·         Vector
·         LinkedList

Queues
·         PriorityQueue

Utilities
·         Collections
·         Arrays


Note : Basically You will find three kinds of collection words in this framework but each has its own importance given as below

i)        collection (lowercase c), which represents any of the data structures in
which objects are stored and iterated over.

ii)       Collection (capital C), which is actually the java.util.Collection interface
 from which Set, List, and Queue extend. (That's right, extend, not implement. 
There are no direct implementations of Collection.)

iii)     Collections (capital and ends with s) is the java.util.Collections class
that holds a pile of static utility methods for use with collections.


List Interface
  • A List cares about the index.
ArrayList
  • This as a growable array
  • It gives you fast iteration and fast random access
  • It is an ordered collection (by index), but not sorted

Vector
  • Vector is a holdover from the earliest days of Java
  • Vector and Hashtable were the two original collections
  • Vector is basically the same as an ArrayList
  • Vector methods are synchronized for thread safety
  • You'll normally want to use ArrayList instead of Vector because
  • the synchronized methods add a performance hit you might not need
  • Vector is the only class other than ArrayList to implement RandomAccess

LinkedList
  • A LinkedList is ordered by index position, like ArrayList, except that the elements are doubly-linked to one another
  • LinkedList  is best for adding and removing from the beginning or end, which makes it an easy choice for implementing a stack
  • or queue.
  • LinkedList may iterate more slowly than an ArrayList

Set Interface
  • A Set cares about uniqueness—it doesn't allow duplicates

HashSet

  • A HashSet is an unsorted, unordered Set
  • It uses the hashcode of the object being inserted
  • Use this class when you want a collection with no duplicates and you don't care about order when you iterate through it

LinkedHashSet

  • A LinkedHashSet is an ordered version of HashSet that maintains a doubly-linked List across all elements.
  • Use this class instead of HashSet when you care about the iteration order.

  • When you iterate through a HashSet the order is unpredictable, while a LinkedHashSet lets you iterate through the elements in the order in which they were inserted.

TreeSet

  • The TreeSet is sorted collections

  • It uses a Red-Black tree structure, and guarantees that the elements will be in ascending order, according to natural order

  • TreeSet, lets you define a custom sort (your own rule to sort) order via a Comparable or Comparator)

Map Interface
  • A Map cares about unique identifiers

HashMap

  • The HashMap gives you an unsorted, unordered Map
  • A Map cares about unique identifiers.
  • You map a unique key (the ID) to a specific value
  • Map implementations let you do things like search for a value based on the key

Hashtable

  • Like Vector, Hashtable has existed from prehistoric Java times

  • Looks HashMap vs. Hashtable. Where's the capitalization of t?
  • Hashtable is the synchronized counterpart to HashMap
  • Hashtable are synchronized,  means that the key methods of the class are synchronized
  • HashMap lets you have null values as well as one null key, a Hashtable doesn't let you have anything that's null.

LinkedHashMap

  • LinkedHash-Map collection maintains insertion order

  • It will be somewhat slower than HashMap for adding and removing elements,

  • Iteration with a LinkedHashMap will be faster

TreeMap

  • TreeMap is a sorted Map by natural order

  • Like TreeSet, TreeMap lets you define a custom sort order via a Comparable or Comparator

Queue Interface
  • A Queue is designed to hold a list of "to-dos," or things to be processed in some way.

PriorityQueue

  • We PriorityQueue is to create a "priority-in, priority out" queue as opposed to a typical FIFO queue

  • A PriorityQueue's elements are ordered either by natural ordering (in which case the elements that are sorted first will be accessed first) or according to a Comparator

  • In either case, the elements' ordering represents their relative priority