Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Java Arrays
  • Java Strings
  • Java OOPs
  • Java Collection
  • Java 8 Tutorial
  • Java Multithreading
  • Java Exception Handling
  • Java Programs
  • Java Project
  • Java Collections Interview
  • Java Interview Questions
  • Java MCQs
  • Spring
  • Spring MVC
  • Spring Boot
  • Hibernate
Open In App
Next Article:
Compilation and Execution of a Java Program
Next article icon

What are the Roles of Java Compiler and Interpreter?

Last Updated : 18 Aug, 2022
Comments
Improve
Suggest changes
Like Article
Like
Report

Compiler and Interpreter are two different ways to translate a program from programming or scripting language to machine language. In this article let's discuss on what are the roles of the Compiler and Interpreter in Java.

Java Compiler

A compiler in Java translates the entire source code into a machine-code file or any intermediate code, and that file is then executed. It is platform-independent. A bytecode is basically an intermediate code generated by the compiler after the compilation of its source code. Java compiler can be operated by using the “Javac.exe” command from the command prompt. Some of the compiler options are given below:

  • -help: it prints a summary of standard options.
  • -version: returns the compiler information.
  • -verbose: verbose output i.e., it includes information about each source file compiled and each class loaded.
  • -nowarn: it is used to turn off warnings. 
Java-Compiler
 

Java Compiler Step By Step

Java-Compiler-Step-by-Step
 

Roles of Java Compiler

  • It scans the complete source code in one go and then highlights the error.
  • It requires more memory to produce the bytecode.
  • It checks the correctness of the program by checking the type errors, syntax, etc.
  • It also adds some additional code to our program if required.

Java Interpreter

Similarly, an Interpreter is a computer program that converts the high-level program statement into Assembly-level language. It converts the code into machine code when the program is run. Some of the interpreter options are given below:

  • -version: displays interpreter version.
  • -verbose: displays interpreter information.
  • -help: displays interpreter options.
Java-Interpreter
 

Java Interpreter Step By Step

Java-Interpreter-Step-by-Step
 

Roles of Java Interpreter

  • To convert the bytecode into the native code of the machine.
  • This process is done line by line.
  • If the error comes on any line, the process is stopped over there.

Interpreter vs Compiler: How is Interpreter Different Than a Compiler in Java?

Here are some key differences between an interpreter and a compiler. They are as follows:

  • The interpreter scans the program line by line and translates it into machine code whereas the compiler scans the entire program first and then translates it into machine code.
  • The interpreter shows one error at a time whereas the compiler shows all errors and warnings at the same time.
  • In the interpreter, the error occurs after scanning each line whereas, in the compiler, the error occurs after scanning the whole program.
  • In an interpreter, debugging is faster whereas, in the compiler, debugging is slow.
  • Execution time is more in the interpreter whereas execution time is less in the compiler.
  • An interpreter is used by languages such as Java, and Python, and the compiler is used by languages such as C, C++, etc.

Next Article
Compilation and Execution of a Java Program
author
akshaysobti15
Improve
Article Tags :
  • Java
  • java-basics
Practice Tags :
  • Java

Similar Reads

  • Why Java is Called a Compiler Interpreter Language?
    Java is both a compiled and interpreted programming language. Because it employs both compilation and interpretation to run code, it is known as a "compiler-interpreter language." In order for the Java Virtual Machine to understand the Java code, it must first be compiled into an intermediate format
    4 min read
  • Difference Between Java Threads and OS Threads
    In modern computing, multitasking and parallel processing are essential for improving system performance. Two important concepts that enable this are Java Threads and Operating System (OS) Threads. Both play a key role in managing concurrent tasks, but they operate at different levels and interact w
    8 min read
  • Compilation and Execution of a Java Program
    Java, being a platform-independent programming language, doesn't work on the one-step compilation. Instead, it involves a two-step execution, first through an OS-independent compiler; and second, in a virtual machine (JVM) which is custom-built for every operating system. The two principal stages ar
    5 min read
  • Java Program to Open the Command Prompt and Insert Commands
    In Java, the Runtime class allows Java applications to interact with the system's environment. Every Java application has an object of this class, this class provides exec() method and this method is used to run system commands. In this article, we will discuss how the exec() method can be used to o
    2 min read
  • Best Way To Start Learning Core Java – A Complete Roadmap
    In the corporate world, they say "Java is immortal!". It is one of the most robust programming languages that is currently used in more than 3 billion devices. It is a general-purpose, object-oriented programming language designed at Sun Microsystems in 1991. In the current era, Java is one of the m
    9 min read
  • Java Native Interface with Example
    In the Programming World, it is often seen in the comparison of Java vs C/C++. Although the comparison doesn't make any such sense, as both the languages have their Pros and Cons, but what if we can use multiple languages in a single Program? In this article, we will learn How to use JNI(Java Native
    4 min read
  • Java Interview Questions and Answers
    Java is one of the most popular programming languages in the world, known for its versatility, portability, and wide range of applications. Java is the most used language in top companies such as Uber, Airbnb, Google, Netflix, Instagram, Spotify, Amazon, and many more because of its features and per
    15+ min read
  • Java Developer Learning Path – A Complete Roadmap
    Java is one of the most widely used programming languages in the world. Talking about its popularity, more than nine million developers considered the Java Programming language as their mother tongue. So there is no doubt about Java’s popularity worldwide. Java is a general-purpose, object-oriented
    6 min read
  • Java - Divide the Classes into Packages with Examples
    Let us first know what is a class and package in Java. Class in java is a model for creating objects. It means that the properties and actions of the objects are written in class. Properties are represented by variables and actions of the objects are represented by methods. So, a class contains vari
    6 min read
  • Commonly Asked Java Programming Interview Questions | Set 1
    Why is Java called the ‘Platform Independent Programming Language’? Platform independence means that execution of your program does not dependent on type of operating system(it could be any : Linux, windows, Mac ..etc). So compile code only once and run it on any System (In C/C++, we need to compile
    5 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences