Running a java program and tracing IP address

Create a temporary folder. C:\mywork. Using Notepad or another text editor, create a small Java file

Save your file as in C:\mywork. To make sure your file name (not, first choose “Save as file type.” All files, then type in the file name

Run Command Prompt (as follows)

1. C:\cd\mywork 

This makes C:\mywork the current directory.

2. C:\mywork>;dir

This displays the directory contents. You should see among the files.

3. C:\mywork>javac

This runs javac.exe, the compiler. You should see nothing but the next system prompt…

4. C:\mywork>;dir

javac has created the HelloWorld.class file. You should see and HelloWorld.class among the files.

5. C:\mywork>java HelloWorld

This runs the Java interpreter. You should see the program output : Hello, World!

IP address java 



public class IPAddress


    public static void main(String args[])




            InetAddress ipAddr = InetAddress.getLocalHost();

            System.out.println("\nIP address of the machine: " +ipAddr.getHostAddress());


    catch (UnknownHostException ex)







Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s