Posts

Showing posts from February 12, 2011

Simple Java Program of Command line arguments

class CommandLineArgument { public static void main(String[] args) {       System.out.println("Hi " +args[0]); } } save it with C.java (you can save it with any name) compile as usual java CommandLineArgument Kunal The output will be Hi Kunal

Create Inner class as a static

Image
Hi friends , in java there is no way to create a class static the only way to create this is by creating an inner class. class OuterClass {         static         {             InnerClass.main(null);             System.gc();             System.exit(0);         }         static class InnerClass         {         public static void main(String[] args)         {             System.out.println("This is inner class");         }     } }

Simple program in java to show your ipaddress

Image
import java.net.*; class Who {     public static void main(String[] args) throws UnknownHostException     {         InetAddress ip=InetAddress.getLocalHost();         System.out.println(ip);     } } Output