I started this class 5 days ago

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dreamer1963
    New Member
    • Mar 2008
    • 6

    I started this class 5 days ago

    I started a java class 5 days ago. I have read the chapters several times and can not find the answer to the following question. It probably seems simple to most but I am just beginning and really want to learn. Thanks.

    The _______________ command is placed at the beginning of Java source code
    to load the appropriate class package
  • herenbdy
    New Member
    • Mar 2008
    • 5

    #2
    The import command allows you to load other classes into your code so that you can use their methods, for example:

    Code:
    import java.applet.Applet;
    This code finds the Applet class int the JRE library, and imports it. This allows you to make an Applet object, extend the Applet class, use Applet methods, etc.

    Comment

    • Laharl
      Recognized Expert Contributor
      • Sep 2007
      • 849

      #3
      Look at this sample code (don't worry, nothing fancy) and see if you can figure it out (it should be fairly obvious if you try to compile without it).

      [CODE=java]
      //Prints out a random number between 1 and 6
      import java.util.Rando m;

      public class Randomage{
      public static void main(String[] args){
      Random r = new Random();
      System.out.prin tln(r.nextInt(6 )+1);
      }
      }
      [/CODE]

      Comment

      • dreamer1963
        New Member
        • Mar 2008
        • 6

        #4
        Thanks to you both. I feel a little silly now. It was so obvious.

        Comment

        • Ganon11
          Recognized Expert Specialist
          • Oct 2006
          • 3651

          #5
          Don't ever feel silly for asking questions. What is simple to us may be hard for you - and vice versa (on other issues, most likely). The best way to learn is to ask questions.

          That being said, always be willing to work to find the answers to your own questions (which you have been, if you have been reading your textbook as much as you say ;).

          Comment

          • JosAH
            Recognized Expert MVP
            • Mar 2007
            • 11453

            #6
            Originally posted by dreamer1963
            Thanks to you both. I feel a little silly now. It was so obvious.
            No need to feel silly and it isn't obvious either: if your class resides in a package
            itself the above question cannot be answered because then the import statement
            isn't at the top of the source file, i.e. first comes the 'package' specification. At
            best I find that question obfuscating and assuming incorrect things.

            kind regards,

            Jos

            Comment

            Working...