DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • Auditing Spring Boot Using JPA, Hibernate, and Spring Data JPA
  • How To Validate Archives and Identify Invalid Documents in Java
  • Unraveling Lombok's Code Design Pitfalls: Exploring Encapsulation Issues
  • Difference Between High-Level and Low-Level Programming Languages

Trending

  • How to Submit a Post to DZone
  • Spring Authentication With MetaMask
  • Automated Testing Lifecycle
  • TDD With FastAPI Is Easy
  1. DZone
  2. Coding
  3. Java
  4. CAFEBABE: Java's Magic Word

CAFEBABE: Java's Magic Word

Java compilers make Java source code into bytecode. Did you know all Java classes start with the word CAFEBABE? Check out this awesome look at the Java magic word.

A N M Bazlur Rahman user avatar by
A N M Bazlur Rahman
CORE ·
Feb. 06, 16 · Analysis
Like (23)
Save
Tweet
Share
61.97K Views

Join the DZone community and get the full member experience.

Join For Free

A Java compiler compiles a Java Source code into bytecode and stores it in a .class file which is then get executed by the JVM.

Well, we all know this, but do you know that all Java classes start with a magic word called – CAFE BABE?

In case you’re curious and interested to know why bear with my attempt to inform you something interesting.

Go to the vim (whatever editor you like to) and with the simple following Java code.

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

cafebabe1

Now compile it and open the HelloWorld.class in a hex editor –

$ javac HelloWorld.java

$ xxd HelloWorld.class

cafebabe2

Did you notice the CAFE BABE part? If you open any java .class file with a hex editor, you will find this magic word at the beginning.
Well it's just a hexadecimal number which is 3405691582 in decimal.

(CAFEBABE)16 = (3405691582)10

But why it is so magical that it has to add in each class file is probably the most important question to be asked.

Well, James Gosling explained why: –

We used to go to lunch at a place called St Michael’s Alley.  According to local legend, in the deep dark past, the Grateful Dead used to perform there before they made it big.  It was a pretty funky place that was definitely a Grateful Dead Kinda Place.  When Jerry died, they even put up a little Buddhist-esque shrine.  When we used to go there, we referred to the place as Cafe Dead.  Somewhere along the line, it was noticed that this was a HEX number.  I was re-vamping some file format code and needed a couple of magic numbers: one for the persistent object file, and one for classes.  I used CAFEDEAD for the object file format, and in grepping for 4 character hex words that fit after “CAFE” (it seemed to be a good theme) I hit on BABE and decided to use it.  At that time, it didn’t seem terribly important or destined to go anywhere but the trash can of history.  So CAFEBABE  became the class file format, and CAFEDEAD was the persistent object format.  But the persistent object facility went away, and along with it went the use of CAFEDEAD – it was eventually replaced by RMI.
Java (programming language)

Published at DZone with permission of A N M Bazlur Rahman, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Auditing Spring Boot Using JPA, Hibernate, and Spring Data JPA
  • How To Validate Archives and Identify Invalid Documents in Java
  • Unraveling Lombok's Code Design Pitfalls: Exploring Encapsulation Issues
  • Difference Between High-Level and Low-Level Programming Languages

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: