Results 1 to 13 of 13
  1. #1
    eel
    eel is offline Member
    Join Date
    Sep 2010
    Posts
    36
    Rep Power
    0

    Unhappy Separate file for main and class

    I've write codes for the main with message class and PrintWriter class. May I know how do I put the PrintWriter class in another file? As I need to put the main, message class and PrintWriter class in separated file.

    What should I put in the main so that it can detect the PrintWriter class file. What should be included in PrinterWriter class file? Do I need to include public void or something like that? I'm not very sure about it.

  2. #2
    eel
    eel is offline Member
    Join Date
    Sep 2010
    Posts
    36
    Rep Power
    0

    Default

    Is there anyone who can give me an example of a main file which contain PrintWriter and another file which contain just the PrintWriter class? So that I can have it as a reference. Thanks a lot.

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,528
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by eel View Post
    Is there anyone who can give me an example of a main file which contain PrintWriter and another file which contain just the PrintWriter class? So that I can have it as a reference. Thanks a lot.
    Note that there exists a PrintWriter class in the core library of your Java SE distribution; all you have to do is import it.

    kind regards,

    Jos

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,426
    Rep Power
    25

    Default

    example of a main file which contain PrintWriter and another file which contain just the PrintWriter class
    Can you explain the difference between these two classes? I assume by main file you are referring to a class file.
    Any class can use the PrintWriter class.

  5. #5
    eel
    eel is offline Member
    Join Date
    Sep 2010
    Posts
    36
    Rep Power
    0

    Default

    The main class is with Scanner which uses system.out.println and public static void main (String[] args). Is that the information that you need?

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,426
    Rep Power
    25

    Default

    Is that the information that you need?
    Sorry, I thought you were asking a question.

    Are you asking about classes you are writing?
    Or are you asking about classes in the JDK?

  7. #7
    eel
    eel is offline Member
    Join Date
    Sep 2010
    Posts
    36
    Rep Power
    0

    Exclamation

    Quote Originally Posted by Norm View Post
    Can you explain the difference between these two classes? I assume by main file you are referring to a class file.
    Any class can use the PrintWriter class.
    I'm asking question about the class I'm writing which is a the main which contained PrinterWriter class and message class. I need to separate the document into three separated documents in which each document contained: main class, PrinterWriter class & message class respectively.

    The problem is I don't know how to put the PrinterWriter from my main file to another file. Because if you put the code wrongly, the program won't run smoothly. It will generate error.

    I hope there were some examples which I can refer to.

    Thanks a lot :)

  8. #8
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,426
    Rep Power
    25

    Default

    It will generate error
    Can you copy the full text and paste here the error(s) you get

    Is the problem that you have a reference to a PrintWriter class object in one class and you want to pass that reference to another class so it can use it?

  9. #9
    eel
    eel is offline Member
    Join Date
    Sep 2010
    Posts
    36
    Rep Power
    0

    Default

    I don't have error. I havent' done it because I've got no idea about it.
    I have just created a main class file in which inside the main class file contained printwriter class and message class. However, what I want to do is to make all of the class separated which means I need to use the printwriter code in the main class file to create another file which belongs to only printWriter class and the same for message class.

  10. #10
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,426
    Rep Power
    25

    Default

    what I want to do is to make all of the class separated which means I need to use the printwriter code in the main class file to create another file which belongs to only printWriter class
    Your use of the word "file" here is confusing. The PrintWriter class can be used to create disk files. I suspect you mean you want to create several different classes. A main one, one that uses the PrintWriter class and another for messages.

    I am having a hard time understanding what you are asking.

    use the printwriter code in the main class file to create another file
    As I said above, that is what the PrintWriter class can do, create files. Do you have code you are having problems with using the PrintWriter class to create a file?

  11. #11
    eel
    eel is offline Member
    Join Date
    Sep 2010
    Posts
    36
    Rep Power
    0

    Cool

    [QUOTE=Norm;144075]Your use of the word "file" here is confusing. The PrintWriter class can be used to create disk files. I suspect you mean you want to create several different classes. A main one, one that uses the PrintWriter class and another for messages.

    Yes, you are correct. That's my question here :) I have a document that have main, PrintWriter classes and messages classes. Now I want to create another document for each of the different classes. But I don't know how.

  12. #12
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,528
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by surya86mca View Post
    Respected sir...
    i have an assignment to develop the Fleet Management System
    Don't hijack this topic; start your own thread instead.

    kind regards,

    Jos

  13. #13
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,528
    Blog Entries
    7
    Rep Power
    20

    Default

    [QUOTE=eel;144149]
    Quote Originally Posted by Norm View Post
    Your use of the word "file" here is confusing. The PrintWriter class can be used to create disk files. I suspect you mean you want to create several different classes. A main one, one that uses the PrintWriter class and another for messages.

    Yes, you are correct. That's my question here :) I have a document that have main, PrintWriter classes and messages classes. Now I want to create another document for each of the different classes. But I don't know how.
    You should read the Java tutorials; they explain how you should create classes, the source of each in its own file, and how to run them together in one program.

    kind regards,

    Jos

Similar Threads

  1. Jar file could not find the main class
    By Collinryans in forum New To Java
    Replies: 3
    Last Post: 06-23-2010, 04:18 AM
  2. How to make swing.Timer as a separate class
    By nethz13 in forum New To Java
    Replies: 9
    Last Post: 04-18-2010, 09:14 AM
  3. Replies: 1
    Last Post: 07-03-2009, 08:41 PM
  4. Should I separate my code into separate files?
    By Inks in forum New To Java
    Replies: 0
    Last Post: 03-26-2009, 12:12 AM
  5. different multiple public class and main class
    By mr idiot in forum New To Java
    Replies: 2
    Last Post: 01-01-2009, 12:10 PM

Posting Permissions

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