PieceOfAPie
PieceOfAPie
  • Home
  • Tutorials
  • Projects
  • More
    • Home
    • Tutorials
    • Projects
  • Home
  • Tutorials
  • Projects

How Java Works

Previous Lesson


When you write a program, you might think that it's easy for the computer to understand what you are writing and that it understands all programming languages. Instead, your computer cannot understand any programming language except 1: binary. Binary, also called machine code, is a programming language so simple that it only uses 1s and 0s representing on and off. Converting a program written in Java into binary code involves several steps and processes, but understanding how it works can help you grasp important concepts later on.


Here's how it works:

  1. You write a program in a .java file
  2. The .java file is compiled into bytecode by the Java compiler (javac)
  3. The byte code is then taken to the Java Virtual Machine, which converts it into binary
  4. The binary code is run on your Operating System (OS)

 

Interpreter Vs. Compiler

You might have noticed that I have mentioned the word compiler many times throughout this course. What does it mean? A compiler translates your programming file into binary. The compiler has a counterpart called an interpreter. Although both the compiler and the interpreter accomplish the same task of turning a programming file into binary, they both do it in different ways, making both useful in different scenarios.


________________________________________________________________________________


Examples of languages that use a compiler:

  • Java
  • Rust
  • C
  • C++


Examples of languages that use an interpreter:

  • Python
  • Javascript
  • Bash
  • Perl


________________________________________________________________________________


How a compiler translates regular code into binary:

  • The compiler takes some time to read all the code
  • Then, the compiler quickly converts all of it into binary


How an Interpreter translates regular code into binary:

  • The interpreter reads each line of code line by line
  • As it's reading, it also turns each line into binary code simultaneously


________________________________________________________________________________


Attributes of Compilers:

  • Faster run time
  • Error detection before runtime
  • Slower development cycle
  • Protects source code
  • Compile code usually specific to the platform (can't run on every machine) (Java needs a JVM for it to run)


Attributes of Interpreters:

  • Slower run time
  • Error detection while runtime
  • Faster development cycle
  • Exposes source code
  • Source code can run on any platform (Interpreters handle binary translation)


________________________________________________________________________________


What to use when?

  • Use a compiler-based language when you need high-performance and security
  • Use an interpreter-based language when you need a program to run on any platform, or for scripting (writing short programs to automate tasks, interact with systems, or manipulate data)

Next Lesson

Coming Soon!

Copyright © 2025 PieceOfAPie - All Rights Reserved.

Powered by

This website uses cookies.

We use cookies to analyze website traffic and optimize your website experience. By accepting our use of cookies, your data will be aggregated with all other user data.

Accept