Thursday, July 26, 2012

usage of Map.Entry interface in java collections


Hi,

    
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
// TODO code application logic here
// Create a hash map
        HashMap hm = new HashMap();
// Put elements to the map
        hm.put("John Doe", new Double(3434.34));
        hm.put("Tom Smith", new Double(123.22));
        hm.put("Jane Baker", new Double(1378.00));
        hm.put("Todd Hall", new Double(99.22));
        hm.put("Ralph Smith", new Double(-19.08));
// Get a set of the entries
        Set set = hm.entrySet();
// Get an iterator
        Iterator i = set.iterator();
// Display elements
        while (i.hasNext()) {
            Map.Entry me = (Map.Entry) i.next();
            System.out.print(me.getKey() + ": ");
            System.out.println(me.getValue());
        }
        System.out.println();
// Deposit 1000 into John Doe's account
        double balance = ((Double) hm.get("John Doe")).doubleValue();
        hm.put("John Doe", new Double(balance + 1000));
        System.out.println("John Doe's new balance: "
                + hm.get("John Doe"));
    }
}


Friday, July 13, 2012

what is SQLite ?

                                          SQLite  is a tiny, embedded RDBMS (~275kb) which is used by the most of the local/client storage in  application software such as web browsers.Simply its a embedded data base for web browsers.
Ex.  Mozilla stores the cookies information inside a cookie.sqlite  file in the location C:\Users\Mypc\AppData\Roaming\Mozilla\Firefox\Profiles\gwj7th6j.default.
 This file is encrypted internally.We can explore this data base using a firefox plug in called SQLite.

https://addons.mozilla.org/en-US/firefox/addon/sqlite-manager/

Thanks,

Rajesh Kumar Yuvaraj

Friday, June 29, 2012

Another way of System.out.println();

Hi Guys,

                         This is the another way of printing something to console.

import static java.lang.System.out;
 
public class ShortSOP {
public static void main(String[] args) {
out.println("Hello, world");
}
}

Thanks,

Rajesh Kumar yuvaraj

Performance Trade offs of System.out.println();

 Hi Guys,


                     Do you know that the more number of System.out.println(); leads to the slowness of the project, Why, The method println() is a synchronized  which leads to slowness in terms of execution.


Thanks

Rajesh Kumar Yuvaraj

The "Best Ever " example for Synchronization !!!!!!!

Hi Guys,
          
              As you know that  we can discuss half of the J2SE using the statement which is executed most number of times in this Universe, that is

                    i.e: System.out.println("");

Using this statement we can explain the concept of Synchronization in this way.

  • System is a final class which can not be extended.
  • out is a static variable in side the System class of type PrintStream.
  • println() is a method if PrintStream class.
  • We have totally 10 println() methods inside of this PrintStream class.
  • each and every println() method is synchronized.
 i.e    public void println(String x) {
        synchronized (this) {
        print(x);
        newLine();
     }
    } 

Q)      why sun micro systems designed println() method in this way?
 Ans)  Because at any point of time only one thread can be inside of this block,
                                     
Q)     Then what is the use?
Ans)   To prevent form the deadlock.If multiple thread access the same code it becomes a scrap.

In this way the println() method is a best example of Synchronization.

Thanks,

Rajesh Kumar Yuvaraj



Redirecting the output of System.out.println()

Hi Guys,

Using the below example we can redirect the out put of the System.out.println().

public class ChangeOut {
  public static void main(String args[]) {
    try {
      System.setOut(new PrintStream(new FileOutputStream("log.txt")));
      System.out.println("Now the output is redirected!");
    } catch(Exception e) {}
  }
}

Thanks

Rajesh Kumar yuvaraj

Wednesday, June 27, 2012

I Frame with javascript Example

Hi Guys,

           Here is a sample iFrame example.



<html>
    <head>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
        <title>Untitled 1</title>

        <script >
            function go(loc){
                alert(loc);
                document.getElementById('calendar').src = loc;
            }
        </script>
    </head>

    <body>
        <iframe id="calendar" src="about:blank" width="1000" height="450" frameborder="2" scrolling="no"></iframe>

        <form method="post">
            <input name="calendarSelection" type="radio" onclick="javascript:go('https://google.com')"/>Day
        </form>

    </body>

</html>


Thanks,


Rajesh Kumar Yuvaraj