Results 1 to 7 of 7

Thread: Thinking in Java (3rd Ed)

  1. #1

    Thread Starter
    Frenzied Member StrangerInBeijing's Avatar
    Join Date
    Mar 2005
    Location
    Not in Beijing
    Posts
    1,666

    Thinking in Java (3rd Ed)

    Hi,
    I bought myself Thinking in Java, 3rd Edition, but did not get the cd with (Tried but failed to explain to the chinese shop assistant ), so I got myself the excersizes from the internet.

    I am coding in EditPlus, as I believe when one try learn a new language, you should do as much of the dirty work yourself.

    However, I got no idea how to work with the supplied excersizes. It got folders named c02 to c15, and the com, frogbean and jcsc folders.

    In for instance an excersize in c03 named called EqualsMethod.java, there will be an import line like "import com.bruceeckel.simpletest.*;" This class is in the com folder (com\bruceeckel\simpletest)

    How do I compile this sample excersizes in the chapter folders, that import stuff in the com directory?

    I'm a newbie, especially with this kind of stuff. Just know some basic Java
    Install and Configure Eclipse For both Java and PHP development
    Accessible Ajax/jQuery Forms Degrade gracefully with JavaScript Disabled

  2. #2

    Thread Starter
    Frenzied Member StrangerInBeijing's Avatar
    Join Date
    Mar 2005
    Location
    Not in Beijing
    Posts
    1,666

    Re: Thinking in Java (3rd Ed)

    OK, Let me try again...

    To import namespaces in the JVM, one would for instance say
    Code:
    import java.awt.*;
    import javax.swing.*;
    etc,

    But say I am working on ClassA in FolderA. In the same directory as FolderA is FolderB, and inside FolderB is ClassB.

    How do I "reference" ClassB in ClassA, so I can use ClassB's stuff in ClassA?

    I need to know how one do this if you code in a normal text editor, and compile from the command prompt, using the javac command.

    Please?
    Install and Configure Eclipse For both Java and PHP development
    Accessible Ajax/jQuery Forms Degrade gracefully with JavaScript Disabled

  3. #3
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: Thinking in Java (3rd Ed)

    You can extend functionality, implement functionality, or in your case you can import them.

    You need to store the class in a specific folder...If I remember right it's recommended that you store it in the com.java folder, and when you import it will look something like this:


    import com.java.ClassA;

  4. #4

    Thread Starter
    Frenzied Member StrangerInBeijing's Avatar
    Join Date
    Mar 2005
    Location
    Not in Beijing
    Posts
    1,666

    Re: Thinking in Java (3rd Ed)

    Thanks SE;

    This classes and folders are stored exactly as I downloaded it (Source code for the book).

    I want to know that if I create a class which need to use a class's functionality in another folder, how do I compile it?

    I just assume that I'm using the wrong command line compile options.
    Install and Configure Eclipse For both Java and PHP development
    Accessible Ajax/jQuery Forms Degrade gracefully with JavaScript Disabled

  5. #5
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: Thinking in Java (3rd Ed)

    Ok, what folder are you hiding the class file in?

    For instance, containg the class A in the directory com, but in a folder ch01:

    import com.ch01.classA;

    Let me know kind of the directory/heirarchy structure you are using.


    PS: Glad you are starting out with the command line....Most people won't take the pains to do so, but since you are you'll never regret it

  6. #6

    Thread Starter
    Frenzied Member StrangerInBeijing's Avatar
    Join Date
    Mar 2005
    Location
    Not in Beijing
    Posts
    1,666

    Re: Thinking in Java (3rd Ed)

    Hope you don't mind, but I attached the full source code that comes with the book (allthough I had to download it from the net like I said before)

    I went throught the first 2 chapters of the book pretty fast, and then the guy start with the excersizes. These sample files use lines like "import com.bruceeckel.simpletest.*;" in a class in say folder "c03".

    As you can see, there's all kind of "build" xml files, and some others, and using this is not explained in the book so far. I suppose this guy were using some IDE, not a text editor and cmd line like me.

    Saying all this I want to seperate my code too. Nest classes with functionality in folders (Say //SSDev/IO/..., //SSDev/Graphic/...) and then let classes in folders outside use that functionality.

    The more I talk (which is too much) I genuinely think I must go back and look at compiler options for JAVAC....that should be where you specify what path's to include?

    My english kind of suck (ain't got not mother tongue no more!), so sorry for any misunderstandings
    Attached Files Attached Files
    Install and Configure Eclipse For both Java and PHP development
    Accessible Ajax/jQuery Forms Degrade gracefully with JavaScript Disabled

  7. #7
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: Thinking in Java (3rd Ed)

    No need to worry about english. It's my native language and still foreigners speak it better than me!


    Anyways, this is working for me:

    import com.bruceeckel.simpletest.*;

    That imports all files in the simpletext directory. If you did something like this:
    import com.bruceeckel.simpletest.Test;
    It would import only the test file.

    Also, your problem could be not adding the package statement in the classes you want to import:

    For instance, in the Test class you MUST have this statement:

    package com.bruceeckel.simpletest;
    I think this is what you're missing, but I could be wrong.



    Let me know if there's something I'm not understanding, or you need more help.

    PS: There's no need to set the classpath over. It should point to the parent directory, and nothing more.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width