Guest h4344 Posted August 5, 2011 Posted August 5, 2011 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) { } } }
Guest MAJ.Spartan-S63=US= Posted August 5, 2011 Posted August 5, 2011 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.
Guest h4344 Posted August 5, 2011 Posted August 5, 2011 Ya spartan that gives me a better idea about them. Thanks :D
Guest Dill Posted August 5, 2011 Posted August 5, 2011 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.
Recommended Posts
Archived
This topic is now archived and is closed to further replies.