9
Nanu
5y

we(Friends) discovered this yesterday.

Steps:
1. created a file.js and added a console.
2. renamed the file.js to file.java
3. ran that file.java through node

result: displayed in that image.

Javascript running .java .....seriously?
js how many hidden surprises you have for me. it was even running in .txt, .php etc

Okay let's come to actual point .

I tried to research on this. however, i couldn't find any links related to it.

Well, I tried the same with casperjs and python.It behaved the same.
is this behaviour because it is a scripting language?
Please do share your thoughts on this

Comments
  • 0
    @irene ,yup. Did the same. Discovered this by mistake
  • 0
    @irene tried the same with basic js. My doubt: is this behavior is because js is a scripting language?
  • 3
    No, it's because most programs don't actually care about the extension a file has. It is just part of the file name. Windows still uses the extension to identify file types (and even hides it from the user by default - geez) but that is the only contrary example I can think of.
  • 14
    I sense a long time windows user who still believes that file extensions actualy mean something [even more - that they determine file type]... :)

    buddy you have soooo much to learn... :)
  • 1
    @irene @tokumei got it understood. Thanks for your help
  • 1
    @netikras, so much to learn . Can't deny that. Trying my best on it.
  • 3
    Call it test.docx and it will still work.. Its not suddenly a word document.
  • 1
    @Codex404, came to know about that. coming from a Java background needed .Java file to compile. Since js is a scripting language was expecting at least it to crash. However, it wasn't. That's why I added this question
  • 4
    @kiru15 the interpreter looks at the code inside the file, not the name of the file.

    Think of it as a wallet, the money is inside the wallet (file) and the currency can change (you have one wallet with javascript, the other one with java code)

    If you put the java currency inside the javascript wallet, you can still buy things on java island with the javascript wallet.

    It's what's inside the wallet that the stores care about, understood? 😉
  • 3
    At first I thought this was an easteregg, know I'm disappointed :(

    Also why do you have a k directory in the root of your filesystem?
  • 1
    @frickerg yes, thank you.
  • 0
    @Jifuna k is a drive. Running gitbash on windows
  • 2
    Code isn't magic, code is text. The parser doesn't do anything, really, except open the file and try to understand the inside. The file can be named whatever you want.
  • 0
    @kiru15 ah okay fair enough
  • 1
    The extension in the name it's just a suffix to identify fast the content. But the real information of the file is on the metadata. The metadata stores the encoding, date created, last date edited, etc. When you open a file, the porgram look this metadata.
    In simple words, calling you kirv51 intead of kiru15 will not change your person.
  • 1
    Am a Java to you?
Add Comment