Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 10 of 10

Thread: println class

  1. #1
    Member
    Join Date
    Jan 2010
    Posts
    42
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default println class

    Hi, sorry to bother you guys again, but as above. Any ways to print out everything(every lines of code) that is on another class?
    Last edited by javanub:(; May 13th, 2010 at 12:57 AM.


  2. #2
    Junior Member
    Join Date
    May 2010
    Posts
    7
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: println class

    Not possible directly.
    But any way if that class is providing all its code as string through toString method then you can print.

  3. #3
    Member
    Join Date
    Jan 2010
    Posts
    42
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: println class

    Quote Originally Posted by jnthakar View Post
    Not possible directly.
    But any way if that class is providing all its code as string through toString method then you can print.
    by importing the class and printing the methods directly?

  4. #4
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default Re: println class

    You could print the method signatures, but not the actual method content. If you want to print the whole file you need to make sure its available as a .java file and that you can read it, load the file in and just read it line by line and print it, but I take it that's not what you want.

    Any chance you can narrow down to what exactly it is you want?

    // Json

  5. #5
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: println class

    Either have the .java source file available, or a handy Java Bytecode decompiler. Note that I think due to what is actually available in compiled form (variable names, code logic, any other code obfuscation that might be implemented by the compiler), you won't get back the exact code that was originally written, and you definately won't get back any comment information (Javadocs are questionable)

  6. #6
    Member
    Join Date
    Jan 2010
    Posts
    42
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: println class

    okay.. what i wanna do is to pass in what is inside another class(the actual content) or or a method of the another class(the method's content) into a string. then use the string to upload to the server using my client api.
    Last edited by javanub:(; May 13th, 2010 at 09:17 PM.

  7. #7
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default Re: println class

    You would really need to have the .java file for the source available for this or as helloworld says, use a decompiler. Getting method content can not be done through reflection. You can however invoke a method and get the return value.

    // Json

  8. #8
    Member
    Join Date
    Jan 2010
    Posts
    42
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: println class

    thanks guys, anyway this problem is solved

  9. #9
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default Re: println class

    How did you solve it if I may ask?

    // Json

  10. #10
    Member
    Join Date
    Jan 2010
    Posts
    42
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: println class

    reflection

Similar Threads

  1. Replies: 0
    Last Post: April 11th, 2010, 08:56 AM
  2. problem with data access when a class call another class
    By ea09530 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 4th, 2010, 05:20 PM
  3. Accessing a method of one class in another class
    By Sai in forum What's Wrong With My Code?
    Replies: 6
    Last Post: March 23rd, 2010, 04:06 PM
  4. System.out.println ("Hello world!")
    By ShaunB in forum Member Introductions
    Replies: 0
    Last Post: December 29th, 2009, 05:17 PM
  5. how to load a class and type cast to that class?
    By chinni in forum Object Oriented Programming
    Replies: 2
    Last Post: November 9th, 2009, 10:18 AM