Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java application that prints its own source code [duplicate]

Tags:

java

quine

I have a little quiz that I cannot solve by myself. I want to build a program that will print its own source code with java. Anyone knows how to do this? Like this example:

public class SourcePrint {

    private static final long serialVersionUID = 1L;

    public void test(){
        System.out.println("Hi I'm test");

    }
    public static void main(String[] args) {
        new SourcePrint().test();
    }

}

when we run this, the output would be same like this:

public class SourcePrint {

    private static final long serialVersionUID = 1L;

    public void test(){
        System.out.println("Hi I'm test");

    }
    public static void main(String[] args) {
        new SourcePrint().test();
    }

}

I don't know how to do this. Anybody know the solution or at least the hint? This is not the decompiler, the quiz maker told me the hint is "STATIC".

like image 498
user1481602 Avatar asked Jun 26 '12 04:06

user1481602


People also ask

How do quines work?

A quine is a program which prints its own listing. This means that when the program is run, it must print out precisely those instructions which the programmer wrote as part of the program (including, of course, the instructions that do the printing, and the data used in the printing).

What code is used for printing on the screen in Java?

out. println(): This method prints the text on the console and the cursor remains at the start of the next line at the console.


1 Answers

http://en.wikipedia.org/wiki/Quine_%28computing%29

like image 74
Rick Mangi Avatar answered Oct 12 '22 11:10

Rick Mangi