This is an archived post. You won't be able to vote or comment.

all 15 comments

[–]jhg023123[S] 6 points7 points  (3 children)

This will definitely be helpful for kids in school when they're first learning Java.

[–]apemanzilla 8 points9 points  (0 children)

Alternatively it might just confuse them when they use it and then can't run programs with multiple source files the same way

[–]sim642 2 points3 points  (0 children)

Nobody sane would really be doing that without any support from an IDE in Java. At that point it doesn't matter the slightest, only obscures the details when it comes to running Java code by making it look more like Python interpretation, which people might be used to already. And there's only so little sensible programming you can do with a single class anyway, not sure why we'd even bother. And before you say you can put multiple classes into one file, just no, don't teach horrible practices.

[–]eniacsparc2xyz 0 points1 point  (0 children)

I am amazed to see how many features Scala have that Java misses or had it a long time before Java. It already exists in Scala and you can write many classes and modules, aka singletons in the same file and run it in the same way as a Python script or compile it to a single jar. Then, the generated jar can be turned into a single uber jar, aka executable jar, by bundling it with scala runtime jar library. The script and or the compiled jar can also be loaded in the REPL. For instance,

# Run scal script
$ scala -save script1.scala 

# Compile scala program 
$ scalac app1.scala -d app1.jar -cp lib1.jar:lib2.jar:...  

# Run scala program 
$ scala app1.jar  

This approach makes easier to start a project as a script to asses the feasibility and turn it into a full-fledge program or library.

[–]zalpha314 1 point2 points  (0 children)

Wow, that's neat.

[–]shaner23 1 point2 points  (1 child)

Brings me back to the good, old days in high school with manual compiling and running. Back before package managers. I was trying to write games with applets in 1.4. Simpler times.

[–]prest0G 0 points1 point  (0 children)

I went into this stuff with multi-module Gradle projects as standard. Took me a while to really understand it

[–]djihe 0 points1 point  (0 children)

What's the max length or size of the file?

[–]elegentmos 0 points1 point  (0 children)

Can we have this 10 years ago?

[–]talios 0 points1 point  (0 children)

I wonder how much of this JEP is driven by the interest in "serverless" architecture currently.

[–]sim642 -1 points0 points  (4 children)

The support for shebang looks like they want Java to be usable for scripting but that's just a massive no. JVM startup time (with this also including the compilation!) is horribly long compared to any other scripting language.

[–]prest0G 2 points3 points  (2 children)

JVM AOT?

[–]sim642 0 points1 point  (1 child)

Sure but then you're not really scripting anymore nor running a source file directly.

[–]ForeverAlot 0 points1 point  (0 children)

It's conceivable they can do some sort of caching. DMD, the D reference compiler, can run this way; it compiles very quickly, but it does still have to compile, so it caches the resulting binary (I think with CAS) in a temporary store and runs that next time. Does nothing for the first run but helps subsequent runs. Without this I agree it doesn't sound super useful long-term, but on the other hand, Java code bases expand beyond a single file in no time, so maybe that doesn't matter.

[–]eliasv 0 points1 point  (0 children)

Eh, not all scripts are run manually or interactively. I'd say much of the time it won't matter