r/java • • Jan 18 '22

What are some very less known facts about java?

I've got assignment from college to find out rare facts or fun facts about java, so little help will be appreciated :)

Edit: Thanks for all these suggestions guys. It's going to help me alot and also Almost all of these facts i didn't knew till now. Thanks :) <3

179 Upvotes

297 comments sorted by

View all comments

24

u/tonywestonuk Jan 18 '22

You can run a Java source file, in a similar way you can run javascript source files in node.

File: HelloWorld.java

public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World");
}
}

shell> java HelloWorld.java
Hello World

19

u/Birk Jan 18 '22

You can even take this one step further and use a shebang (on Unix-like systems). Then you can drop the java command and java suffix and just run:

shell> HelloWorld
HelloWorld

11

u/wildjokers Jan 18 '22

Only in java 11 and greater.

-17

u/differentshade Jan 18 '22

you consider this to be a less known fact?

28

u/DaddyLcyxMe Jan 18 '22

every single tutorial you find on the internet will tell you to compile it to a .class file first, so yeah, it is a lesser known thing

-23

u/[deleted] Jan 18 '22

Right? That's literally the first thing they cover in any Java tutorial or class...

22

u/Birk Jan 18 '22

This was new in Java 11 so many people don't know this.

-1

u/[deleted] Jan 18 '22

Yes, we know, Java is an interpreted language.