Friday, December 30, 2011

Java Decompiler

 Hi Guys,
  
         Please click on corresponding links to get the Java Decompiler.

For Windows.
For Linux.
For Mac.



Thanks,
Rajesh Kumar Yuvaraj.

Saturday, November 12, 2011

Does java really allows Pointers ?? why can't it ? ?

Hi Guys,

I need response from all the Java experts. After reading this topic you will come to  a conclusion that java supports Pointers Arithmetic. Actually java 1.5 supports java Pointer Arithmetic. JDK 1.5 has the most disastrous java class called sun.misc.Unsafe which allow you to access the direct memory.
Please execute the following Code and your JVM will get crashed.

Please hang on a minute if java does not support  pointers it should throw Null Reference Exception. but JVM always throw Null Pointer Exception.

Think ..... Think ...... Think....... Think  ....Think..... Think........ and enjoy the below code...

import sun.misc.Unsafe;
import java.lang.reflect.Field;

public class TestPointers {
    public static void main(String[] args) throws Exception {
         Unsafe unsafe = getUnsafe();
         System.out.println("Unsafe = " + unsafe);
         System.out.println(" addressSize() = " + unsafe.addressSize());
         System.out.println(" pageSize() = " + unsafe.pageSize());
         System.out.println(" pageSize() = " + unsafe.pageSize());
         try {
             unsafe.putByte((long) 0xa000, (byte) 47);
         } catch(Throwable e) {
             System.out.println("IN THE CATCH BLOCK");
             e.printStackTrace();
         } finally {
             System.out.println("IN THE FINALLY BLOCK");
         }
         System.exit(0);
    }

     public static Unsafe getUnsafe() {
         Unsafe unsafe = null;
         try {
             Class uc = Unsafe.class;
             Field[] fields = uc.getDeclaredFields();
             for(int i = 0; i < fields.length; i++) {
                 if(fields[i].getName().equals("theUnsafe")) {
                     fields[i].setAccessible(true);
                     unsafe = (Unsafe) fields[i].get(uc);
                     break;
                 }
             }
         } catch(Exception ignore) {
     }
     return unsafe;
     }
   }



resource:
http://knol.google.com/k/pointers-in-java#

http://www.docjar.com/docs/api/sun/misc/Unsafe.html

Actually it s a bug in jdk 1.5  please read the following link


http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4420961

Thursday, November 3, 2011

Java Script Variable Number of arguments


Hi Guys,
As we know we can have the advantage of the  var args(variable number of arguments or variable length arguments ) in Java. Same as in java we have the advantages of var args in java script also.To achieve the variable number of arguments we have a key word called arguments which works only inside of the java script functions.

A pseudo code for that is as follows
----------------------------------------------- 

function test() {
alert(arguments.length);
for(var i=0;i< arguments.length; i++){
alert(arguments[i]);
}
}

and the method call would be

test('13',15,'15');
test('13',15);
test('13');



Please follow the link....

http://www.jtricks.com/javascript_tutorials/varargs.html

Friday, October 7, 2011

Can You define a constructor in the Interface



In java will you be able to define a constructor in an interface.

First of all we cannot define a constructor inside a Interface. Any Interface will not allow any one to define a interface. Interface is to declare only that means it declares only Contracts. the class which Implements that interface can have a constructor.


My bottom line if that, After all Constructor is a method, interface cannot define a  method it can declare a method which return some value.

Sunday, October 2, 2011

WebRTC a Revolutionary Evolution In Telecommunications

Hi Guys,



                 Do you know that the Web RTC is a Revolutionary Evolution In

Telecommunications and it is going to rock the world soon. click visit  

http://www.webrtc.org/ for more info.

for demo use http://www.youtube.com/watch?v=cx4rZH7fLpM&noredirect=1




Thursday, March 17, 2011

Name of the Server generated servlet class

Hi Guys,
Do you know the name of the Name of the web server generated servlet class???

for the test.jsp

the class file will created with the name test_jsp.class file which will be stored in  the directory



apache/work/Catalina/localhost/_/org/apache/jsp/

Thanks & Regards

Rajesh Kumar yuvaraj

Is it not possible to use System class inside JSP declarations ...

Hi Guys.....

have you ever tried to use the following code into your JSP


<%!
 System.out.println(" it is blunder");
 %>


because  jsp declarative tag is for jsp declarations only but not for the definitions


it is as simple as this


public class Demo{
System.out.println("hello world");// its is joke
public static void  main(String ar[]){
System.out.println("hello world from main");
 }

}
Thanks & Regards


Rajesh Kumar Yuvaraj

can we define the method inside of the jsp scriplet tag

Hi Guys,

Good Day....

Have you ever tried to define a method inside of the jsp scriplet tag.

what is my point is

<%
public void aMethod(){
-------------------------------
-------------------------------
-------------------------------
------------------------------


}

%>
this is not possible  try it guys....

Can we use the out (JSP implicit Object) Object in JSP declarative Tag

Hi Guys,

Have you ever tried to use the out object in the JSP Declarative Tag try it guys....

Actually you cannot use the out object directly in the JSP Declarative tag....

what i want to convey is try to understand the following code

<%!
        out.write("its a blunder");
        out.println("this is also blunder");
  %>

Thursday, March 10, 2011

Jar Signer in Java

Signing a jar is basically used to verify a trusted source. When you sign a jar with your digital signature (based on your private key), you place a mark into the jar file that could not have been done by anyone but you.

The signature is also a checksum of the Jar file, so if the jar get corrupted or modified in transit, the signature is invalid.

On the other side, your public key is placed into the keystore of the system that trust you. This will be used to verify your signature.

Currently, I believe this is mainly used for applets. Using signed jar files, and setting security properties on client browsers, applets can have access to disk, network, and other stuff that they don't normally have access to.



There are many ways by which you can sign a JAR file using jarsigner. One way would be:
jarsigner -keystore C:\working\mystore -signedjar sbundle.jar bundle.jar john 
On executing the command, you will be prompted for the store password and the private key password. Here, bundle.jar represents the jar file you'd like to sign using the private key of the user whose keystore alias is "john" in the keystore named "mystore" located in the directory c:\working. For details, see the jarsigner documentation


Wednesday, February 23, 2011

Can you Directly get the Browser Name and Version in the JSP?

Hai Guys,

There is no direct way to the get the Browser Name and version in the JSP.

check the following program.

copy the following code inside a JSP page.
<%!
String browserName = "";
String browserVersion = "";
String tmpResult = "";
String getBrowserVersion(String ua, int index) {
tmpResult=ua.substring(index,ua.length());
String temp[]=tmpResult.split(" ");
return temp[0].replaceAll(";","");
}
%>
<%
String _ua = (String) request.getHeader("User-Agent");
System.out.println(_ua);
if (_ua.contains("MSIE")) {
browserName = "Microsoft Internet Explorer";
browserVersion = getBrowserVersion(_ua, _ua.indexOf("MSIE ")+5);
}
if (_ua.contains("Firefox")) {
browserName = "FireFox";
browserVersion = getBrowserVersion(_ua, _ua.indexOf("Firefox/") +8);
}
if (_ua.contains("Chrome") && _ua.contains("Safari")) {
browserName = "Google Chrome";
browserVersion = getBrowserVersion(_ua, _ua.indexOf("Chrome/") +7);
}
if (_ua.contains("Safari") && _ua.indexOf("Chrome")==-1) {
browserName = "Safari";
browserVersion = getBrowserVersion(_ua, _ua.indexOf("Version/") +8);
}
out.print("BrowserName  : " + browserName + "<br>");
out.print("BrowserVersion  : " + browserVersion);
 %>
out put

BrowserName : FireFox
BrowserVersion : 3.6.13

 OR

 <%!     
String browserName = "";
String browserVersion = "";
String tmpResult = "";
String getBrowser(String ua, String splitcon, String name) {
String temp1[] = ua.split(splitcon);
for (String s : temp1) {
if(s.contains(name))
tmpResult = s.trim();
}
tmpResult = tmpResult.replaceAll(" ", "/");
String temp2[] = tmpResult.split("/");
return temp2[1];
}
%>
<%
String _ua = (String) request.getHeader("User-Agent");
if (_ua.contains("MSIE")) {
browserName = "Microsoft Internet Explorer";
browserVersion = getBrowser(_ua, ";", "MSIE");
}
if (_ua.contains("Firefox")) {
browserName = "FireFox";
browserVersion = getBrowser(_ua, " ", "Firefox");
}
if (_ua.contains("Chrome") && _ua.contains("Safari")) {
browserName = "Google Chrome";
browserVersion = getBrowser(_ua, " ", "Chrome");
}
if (_ua.contains("Safari") && _ua.indexOf("Chrome")==-1) {
browserName = "Safari";
browserVersion = getBrowser(_ua, " ", "Version");
}
out.print("BrowserName  : " + browserName + "<br>");
out.print("BrowserVersion  : " + browserVersion);
%>

OUT PUT

BrowserName : FireFox
BrowserVersion : 3.6.13

Thanks,

Keep Rocking.

Sunday, February 13, 2011

JAVA videos...

check this for java videos...

http://www.java-videos-promotions.blogspot.com/

Thursday, February 10, 2011

Use of jps Command?

Good Day Friends..
if u want to know about the currently running JAVA processes here is a command


NAME
          jps - Java Virtual Machine Process Status Tool

SYNOPSIS
       jps [options] [hostid]

DESCRIPTION
       The  jps  tool lists the instrumented HotSpot Java Virtual Machines (JVMs) on the target system. The tool is limited to reporting information on JVMs for which it has the access permissions.

       If jps is run without specifying a hostid, it will look for instrumented  JVMs  on  the  local  host.  If started  with  a  hostid,  it  will look for JVMs on the indicated host, using the specified protocol and port.  A jstatd process is assumed to be running on the target host.

       The jps command will report the local VM identifier, or lvmid, for each instrumented  JVM  found  on  the target system. The lvmid is typically, but not necessarily, the operating system’s process identifier for the JVM process. With no options, jps will list each Java application’s lvmid followed by the short  form
of the application’s class name or jar file name. The short form of the class name or JAR file name omits
       the class’s package information or the JAR files path information.

       The jps command uses the java launcher to find the class name and arguments passed to the main method. If the  target JVM is started with a custom launcher, the class name (or JAR file name) and the arguments to  the main method will not be available. In this case, the jps command will output the string  Unknown  for the class name or JAR file name and for the arguments to the main method.

       The  list  of JVMs produced by the jps command may be limited by the permissions granted to the principal running the command. The command will only list the JVMs for which the principle  has  access  rights  as determined by operating system specific access control mechanisms.

       NOTE  - This utility is unsupported and may or may not be available in  future versions of the JDK.  It is not currently available on Widows 98 and Windows ME platforms.

Use of jmap command?

hey Guys if you want to know the secrets of the JVM and its behavior here is a useful command.

which will give you the important information about the JVM memory Mappings.

       jmap prints shared object memory maps or heap memory details of a given
       process or core file or remote debug server.

       NOTE - This utility is unsupported and may or may not be  available  in
       future  versions  of  the J2SE SDK.  jmap is not currently available on
       Windows platforms or on the Linux Itanium platform.

 Usage

     jmap [option] pid
     jmap [option] executable core
     jmap [option] [server-id@]remote-hostname-or-IP


OPTIONS

<no option>  When  no  option is used jmap prints shared object mappings. For each shared object  loaded in the target VM, start     address, the size of the mapping, and the full path of the  shared
                      object file are printed. This is similar to the Solaris pmap utility.
-heap             Prints  a  heap  summary.  GC  algorithm used, heap configuration and generation wise heap
                      usage are printed.

 -histo            Prints a histogram of the heap. For each Java class, number of  objects,  memory  size  in
                      bytes,  and  fully  qualified class names are printed. VM internal class names are printed
                      with ’*’ prefix.
-permstat      Prints class loader wise statistics of permanent generation of Java heap. For  each  class
                      loader,  its  name,  liveness,  address,  parent  class loader, and the number and size of
                      classes it has loaded are printed.
 

 -h                  Prints a help message.
Example  


jmap -heap 2709


using thread-local object allocation.
Mark Sweep Compact GC

Heap Configuration:

   MinHeapFreeRatio = 40
   MaxHeapFreeRatio = 70
   MaxHeapSize      = 67108864 (64.0MB)
   NewSize          = 655360 (0.625MB)
   MaxNewSize       = 4294901760 (4095.9375MB)
   OldSize          = 1441792 (1.375MB)
   NewRatio         = 12
   SurvivorRatio    = 8
   PermSize         = 8388608 (8.0MB)
   MaxPermSize      = 67108864 (64.0MB)

Heap Usage:
New Generation (Eden + 1 Survivor Space):
   capacity = 589824 (0.5625MB)
   used     = 384136 (0.36634063720703125MB)
   free     = 205688 (0.19615936279296875MB)
   65.12722439236111% used
Eden Space:
   capacity = 524288 (0.5MB)
   used     = 382816 (0.365081787109375MB)
   free     = 141472 (0.134918212890625MB)
   73.016357421875% used
From Space:
   capacity = 65536 (0.0625MB)
   used     = 1320 (0.00125885009765625MB)
   free     = 64216 (0.06124114990234375MB)
   2.01416015625% used
To Space:
   capacity = 65536 (0.0625MB)
   used     = 0 (0.0MB)
   free     = 65536 (0.0625MB)
   0.0% used
tenured generation:
   capacity = 7544832 (7.1953125MB)
   used     = 6702600 (6.392097473144531MB)
   free     = 842232 (0.8032150268554688MB)
   88.83696813925081% used
Perm Generation:
   capacity = 8388608 (8.0MB)
   used     = 4809184 (4.586395263671875MB)
   free     = 3579424 (3.413604736328125MB)
   57.32994079589844% used

Keep Rocking Guys.....

Monday, February 7, 2011

Why hashCode() can return the same value for different objects in java?

Hai guys i have some interesting thing related to the HashCode of java Objects....

                     The point is that hashcodes can be the same without necessarily guaranteeing that the objects are equal, because the "hashing algorithm" used in the hashCode() method might happen to return the same value for multiple objects"

Q. Do all the Objects of the same class will have the Same HashCode?
A. No

Q. Can different objects can have the same HashCode?
A. May or may not

                  Just consider a  scenario where i am using the HashSet which uses the Hash code to store the  Objects of any class, if i am adding the two different objects which have the same hashCode  and don't forget that  HashSet will not allow the duplicate elements and specifically it uses the hashcode to store and access???????


Typically, this does not produce any problems, because hashCode() is mostly used together with equals(). For instance, a HashMap will call hashCode() upon its keys, to know whether the keys may already be contained in the HashMap. If the HashMap does not find the hash code, it's obvious the key is not contained in the HashMap yet. But if it does, it will have to double-check all keys having that same hash code using equals().
I.e.
A.hashCode() == B.hashCode() // does not necessarily mean
A.equals(B)
but
A.equals(B) // means
A.hashCode() == B.hashCode()
if equals() and hashCode() are implemented correctly