Results 1 to 10 of 10
  1. #1
    allaudin's Avatar
    allaudin is offline Senior Member
    Join Date
    Apr 2013
    Posts
    271
    Rep Power
    0

    Default Displaying Source Code

    I have to make a programme that displays its own source code , without using file handling. How can I do this ?

  2. #2
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,083
    Rep Power
    4

    Default Re: Displaying Source Code

    Include the java file in the jar, then load it using
    Java Code:
    BufferedReader r = new BufferedReader( new InputStreamReader( getClass().getResourceAsStream("MySourceFile.java")));
    If your teacher gives you full credit for this, I would like to know.

  3. #3
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,038
    Rep Power
    10

    Default Re: Displaying Source Code

    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  4. #4
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,083
    Rep Power
    4

    Default Re: Displaying Source Code

    Oh and PS: *please* change your avatar. It's really confusing with PhHein's...

  5. #5
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,021
    Rep Power
    6

    Default Re: Displaying Source Code

    That's file handling -- OP said it is not allowed. (Nor is it required!)

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  6. #6
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,083
    Rep Power
    4

    Default Re: Displaying Source Code

    Quote Originally Posted by jim829 View Post
    That's file handling -- OP said it is not allowed. (Nor is it required!)

    Regards,
    Jim
    LOL after your slap in the face, I woke up and realized that it indeed is file handling, despite the lack of Files, FileReaders, etc. Ah well, no real world project would require this anyway. I have never had a need for it in the past 12 years :)

  7. #7
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,038
    Rep Power
    10

    Default Re: Displaying Source Code

    Quote Originally Posted by SurfMan View Post
    LOL after your slap in the face, I woke up and realized that it indeed is file handling, despite the lack of Files, FileReaders, etc. Ah well, no real world project would require this anyway. I have never had a need for it in the past 12 years :)
    It's an interesting academic question that leads to a bunch of other topics. Check out the wikipedia rabbit hole I posted above.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  8. #8
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,021
    Rep Power
    6

    Default Re: Displaying Source Code

    FYI -->http://www.java-forums.org/new-java/...tml#post344885

    Just in case you didn't know.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  9. #9
    allaudin's Avatar
    allaudin is offline Senior Member
    Join Date
    Apr 2013
    Posts
    271
    Rep Power
    0

    Default Re: Displaying Source Code

    it was a task in java programming contest ..

  10. #10
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,038
    Rep Power
    10

    Default Re: Displaying Source Code

    Quote Originally Posted by allaudin View Post
    it was a task in java programming contest ..
    That makes sense. It's a pretty interesting problem. If you want to have your head exploded, read Gödel, Escher, Bach: An Eternal Golden Braid: Gödel, Escher, Bach: An Eternal Golden Braid: Douglas R. Hofstadter: 9780465026562: Amazon.com: Books
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Replies: 16
    Last Post: 01-31-2012, 09:36 PM
  2. Replies: 0
    Last Post: 08-07-2011, 09:32 PM
  3. OCR source code
    By sudee in forum Advanced Java
    Replies: 6
    Last Post: 04-28-2011, 12:40 PM
  4. Replies: 1
    Last Post: 11-28-2008, 07:27 PM
  5. Need a source code
    By vissu007 in forum New To Java
    Replies: 1
    Last Post: 07-05-2007, 08:08 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
  •