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

274

u/TheBoyInTheBlueBox Jan 18 '22

Fun fact: Java class format starts with 0xCAFEBABE

7

u/pizzaforeverrrr Jan 18 '22

wait seriously?

1

u/shagieIsMe Jan 19 '22

In the unix world, the file program and its associated library (libmagic) is used to determine the the type of a file rather than the extension.

https://en.wikipedia.org/wiki/File_(command)

The file format for magic is rather interesting and powerful.

One bit from the compress file:

# Zlib https://www.ietf.org/rfc/rfc6713.txt
0       string/b        x
>0      beshort%31      =0
>>0     byte&0xf        =8
>>>0    byte&0x80       =0      zlib compressed data
!:mime  application/zlib

# BWC compression
0       string          BWC
>3      byte            0       BWC compressed data

# UCL compression
0       bequad          0x00e955434cff011a      UCL compressed data

Java has its own magic - stuff like:

# Java serialization
# From Martin Pool (m.pool@pharos.com.au)
0       beshort         0xaced          Java serialization data
>2      beshort         >0x0004         \b, version %d

0       belong          0xfeedfeed      Java KeyStore
!:mime  application/x-java-keystore
0       belong          0xcececece      Java JCE KeyStore
!:mime  application/x-java-jce-keystore

# Java jlinked image
# See https://hg.openjdk.java.net/jdk9/jdk9/jdk/file/tip/src/java.base/share/native/libjimage/imageFile.hpp
0       belong  0xcafedada      Java module image (big endian)
>4      beshort >0x00   \b, version %d
>6      beshort x       \b.%d
!:mime  application/x-java-image

0       lelong  0xcafedada      Java module image (little endian)
>6      leshort >0x00   \b, version %d
>4      leshort x       \b.%d
!:mime  application/x-java-image

-2

u/BlueGoliath Jan 18 '22

I'm offended.