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 HelloWorld.java.

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

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 HelloWorld.java among the files.

3. C:\mywork>javac HelloWorld.java

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 HelloWorld.java 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 

import java.net.*;

 

public class IPAddress

{

    public static void main(String args[])

  {

        try

    {

            InetAddress ipAddr = InetAddress.getLocalHost();

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

        }

    catch (UnknownHostException ex)

    {

            ex.printStackTrace();

        }

    }

}

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s