4 Replies Latest reply: Jun 16, 2012 11:07 AM by jschellSomeoneStoleMyAlias RSS

    What do you thing about this new Feature?

    943961
      Hi,

      I'm thinking to write a feature request for the jvm and wanted to hear what the comunity thinks about that.

      So what I needed already some times was the possibility to run java code without a class file. Not very often but realy more than once;-)

      I'm looking for something like this:

      $ java -interpret "System.out.println(\"hello world\")"

      or

      $javac -execute "System.out.println(\"hello world\")"

      I know, writing a Java Programm that's doing this is very easy. But i quite often wanted to test someshing on a server. F.ex. checking the default locale or things linke this. And this way it would getting possible very fast.

      So what do you thinkt?

      Edited by: 940958 on 15.06.2012 04:34
        • 1. Re: What do you thing about this new Feature?
          EJP
          It's been done, several times. JShell for one.
          • 2. Re: What do you thing about this new Feature?
            943961
            yeah, you're right, but why not as a feature in java/javac?

            Writing/using a programm that's doing this is not difficult, but the fastest way would be directly in the jdk.
            • 3. Re: What do you thing about this new Feature?
              EJP
              Why as a feature in java/javac, when it can already be done outside? What's the benefit of bloating the JDK to satisfy the one person that has asked for it to be built in, in 16 years?
              the fastest way would be directly in the jdk
              No it isn't. Asking for it to be included in the JDK implies a wait of at least 18 months if you're lucky, and a very probable refusal if you're not, i.e. an infinite way. Nothing fast about either of those. The fastest way is undoubtedly to download and install JShell or one of its many cognates. Or use the built-in script engine.
              • 4. Re: What do you thing about this new Feature?
                jschellSomeoneStoleMyAlias
                boskop wrote:
                I know, writing a Java Programm that's doing this is very easy.
                Although you didn't mean it that way that statement exactly sums it up.

                It is rather easy to write a java program that will dynamically execute a source files. The steps are.
                - Get file
                - Compile it
                - Run it.

                You can do all of that in the current VM/API.

                Matter of fact that is exactly how javac works.

                You second requirement is a bit harder but also possible if you make some minimal assumptions. The steps are.
                - Create class wrapper for code.
                - Compile it
                - Run it.
                So what do you thinkt?
                Write it yourself.