Jump to content

Java help please?


Guest h4344

Recommended Posts

Guest h4344

Ok i have been wondering about this for awile, i have seen these in most of the more complicated java programs i have seen but never quiet understood them? Can anyone who understands java tell me what these are and what they do? (also ignore rest of code its just for reference).

 

 

VVVVVVVVVVVVV

import java.net.*;

import java.io.*;

^^^^^^^^^^^^

 

public class GetHostName {

 

public static void main(String[] args) {

 

try {

InetAddress addr = InetAddress.getLocalHost();

 

byte[] ipAddr = addr.getAddress();

 

String hostname = addr.getHostName();

 

System.out.println("hostname="+hostname);

 

} catch (UnknownHostException e) {

 

}

 

}

 

}

Link to comment
Share on other sites

Guest MAJ.Spartan-S63=US=

Oh, those import statements are telling the Java compiler to pull in external libraries that are required to run the program. If you need to know what external libraries are available, just check them here at the official Java library documentation.

 

In the pane above you see the packages and down below on the left is a list of all possible classes. You can search the packages to see how to import that specific library into your project.

 

Also, doing the following statement:

 

import java.io.*;

 

Using the "*" character after "java.io" is an indication that you're including all classes within that package. It's a wildcard symbol used to indicate just that.

 

Hope that helps.

Link to comment
Share on other sites

import java.lang.* :D

 

I code a lot in java if you ever have any coding questions.

 

I'll throw up a cool java game up here that I did for my final project in computer science II.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...