Programming Fundamentals

Chapter 2
Java and Python Development Environments

Certificate in Java-Python-Programming Languages
Programming Fundamentals   •   Certificate

Java and Python Development Environments

Introduction

A programming language becomes useful only when a developer can write, translate, execute, test, and revise programs. These activities take place within a development environment: the combination of software tools, files, operating-system services, and procedures used to create programs.

Java and Python are both widely used, but their execution models differ. Java source code is normally compiled into platform-independent bytecode, which is executed by the Java Virtual Machine (JVM). Python programs are commonly executed by an interpreter or runtime implementation that translates and runs instructions during program execution. In practice, both languages may involve several translation stages, caching mechanisms, and development tools; therefore, the simple statement that “Java is compiled and Python is interpreted” is useful as an introduction but is not a complete technical description.

This chapter develops the practical foundation required to install and use a Java Development Kit (JDK), a Python interpreter, an integrated development environment (IDE), a terminal, and source files. It also explains how to run simple programs and diagnose common errors.

Learning Objectives

By the end of this chapter, you should be able to:

  • distinguish source code, bytecode, machine code, an interpreter, a compiler, and a runtime;
  • install and verify a Java JDK and a Python interpreter;
  • explain the roles of the JVM, Java compiler, Python runtime, IDE, terminal, and operating system;
  • create, save, compile, and execute simple Java programs;
  • create, save, and execute simple Python programs;
  • interpret common syntax, compilation, runtime, and configuration errors;
  • select suitable tools and practices for small programming projects.

1. The Main Components of a Development Environment

A working programming environment generally contains the following components.

1.1 Source files

A source file contains instructions written in a human-readable programming language. Java source files conventionally use the .java extension, while Python source files conventionally use .py. A source file is text, so it can be created using a basic text editor, an IDE, or a code editor.

The file extension helps tools identify the language, but it does not guarantee that the content is correct. A file named program.py may still contain invalid Python syntax.

1.2 Compiler

A compiler translates source code into another form before execution. The Java compiler, normally called javac, translates Java source into JVM bytecode. A compiler can detect many errors before a program runs, including misspelled keywords, missing punctuation, and incompatible types.

Compilation does not prove that a program is logically correct. A program may compile successfully and still calculate the wrong result or fail during execution.

1.3 Interpreter and runtime

An interpreter is a program that executes instructions represented in a source or intermediate form. A runtime supplies the services required while a program runs, such as memory management, libraries, input/output, and error reporting.

Python is distributed with a runtime implementation. The commonly installed implementation is CPython, which first converts source into an internal bytecode representation and then executes that representation in a virtual machine. This means that the practical distinction between “compiled” and “interpreted” is not absolute. At introductory level, Python is described as interpreted because the developer usually runs the source through the Python runtime without a separate compilation command.

1.4 Libraries and package tools

A library is reusable code supplied by the language platform or by other developers. Java includes the Java standard library, and Python includes its standard library. Package tools install additional libraries. For example, Python commonly uses pip, while Java projects often use build and dependency tools such as Maven or Gradle. These tools are useful in larger projects but are not required for the first programs in this chapter.

1.5 IDE and code editor

An integrated development environment, or IDE, combines source editing, syntax highlighting, project management, execution, debugging, and often version-control support. Examples include IntelliJ IDEA and Eclipse for Java, and PyCharm or Visual Studio Code for Python. An IDE improves productivity, but it does not replace understanding of the language runtime or command line.

1.6 Terminal and shell

A terminal provides a text-based interface to the operating system. A shell—such as Bash, PowerShell, or a Unix-like command shell—reads commands and starts programs. Terminal skills are important because they expose the actual commands used by IDEs and automation systems.

The prompt and path syntax differ by operating system. The commands in this chapter are broadly applicable, but exact installation directories and shell behavior may vary.

2. Java: From Source Code to JVM Execution

Java follows a staged execution model.

  1. A programmer writes a source file, such as Hello.java.
  2. The Java compiler javac checks and translates the source into bytecode.
  3. The bytecode is stored in a .class file.
  4. The java launcher starts a JVM and requests execution of the class.
  5. The JVM loads, verifies, and executes the bytecode. Frequently executed sections may be optimized at runtime by a just-in-time compiler.

The bytecode is designed to be portable across systems that provide a compatible JVM. This is the practical meaning of the phrase “write once, run anywhere,” although operating-system dependencies, library versions, and hardware-specific behavior can still affect portability.

2.1 JDK, JRE, and JVM

The terms below describe related but different components.

ComponentMain role
JVMExecutes Java bytecode and manages runtime services
JREJVM plus libraries needed to run Java applications; modern distributions commonly package runtime capabilities with the JDK
JDKDevelopment kit containing tools such as javac, the Java launcher, libraries, and documentation utilities

For programming, install a JDK, not merely a runtime. A common long-term-support release is appropriate for learning, although the exact version should follow the course or institution’s instructions.

2.2 Installing and verifying Java

After installing a JDK, open a terminal and enter:

java --version
javac --version

Both commands should produce version information. If java works but javac does not, the runtime may be installed without the complete JDK, or the JDK’s bin directory may not be included in the system PATH.

PATH is an operating-system environment variable containing directories searched for executable commands. It is preferable to configure it carefully rather than copying executable files into arbitrary directories. After changing PATH, open a new terminal so that the new environment is loaded.

2.3 A first Java program

Create a file named Hello.java:

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

The public class is named Hello, so the source file must be named Hello.java. Java is case-sensitive: Hello, hello, and HELLO are different identifiers.

Compile the file in the directory where it is saved:

javac Hello.java

If compilation succeeds, a file such as Hello.class is created. Run it with:

java Hello

The command uses the class name, not Hello.class. The expected output is:

Hello, Java!

2.4 Understanding the Java program

public class Hello declares a class. The main method is the conventional entry point used by the Java launcher. String[] args represents command-line arguments. System.out.println writes text followed by a line terminator.

Java requires more structural syntax than the equivalent first Python program. Braces delimit a block, parentheses surround method parameters, and semicolons terminate statements. These conventions allow the compiler to identify program structure before execution.

3. Python: Source Code and Runtime Execution

Python emphasizes concise syntax and rapid experimentation. A Python implementation usually performs the following conceptual steps:

  1. read Python source code;
  2. parse the source and check its syntax;
  3. convert it into an internal bytecode form;
  4. execute the bytecode using the Python virtual machine.

The details depend on the Python implementation. CPython, PyPy, and other implementations may use different optimization strategies. Consequently, “Python is interpreted” describes the usual user experience, not every internal operation.

3.1 Installing and verifying Python

Install a current version approved by the course. On many systems the interpreter is invoked as python; on some systems, especially Unix-like systems, the command is python3.

Try the following commands:

python --version
python3 --version

Use the command that reports the intended Python 3 version. On Windows, the Python launcher may also be available as:

py --version

If no command works, Python may not be installed or its executable may not be in PATH. If a command starts Python 2 or an unrelated program, use the explicitly configured Python 3 command and correct the installation or path configuration.

3.2 A first Python program

Create a file named hello.py:

print("Hello, Python!")

Run it from the terminal:

python hello.py

or, where required:

python3 hello.py

The result is:

Hello, Python!

Python uses indentation to represent program blocks. Indentation is therefore part of the syntax rather than merely a formatting preference. A typical four-space indentation is recommended.

3.3 The Python interactive shell

Running the interpreter without a filename usually opens an interactive prompt:

python

A prompt such as >>> indicates that Python is ready to receive an expression or statement. For example:

>>> 2 + 3
5
>>> print("Testing")
Testing

The interactive shell is useful for testing small expressions and library calls. A script file is more appropriate for a program that must be saved, rerun, shared, or assessed.

Exit the interpreter using exit() or the operating system’s end-of-file shortcut.

4. Java and Python Compared

FeatureJavaPython
Typical source extension.java.py
Common first commandjavac File.javapython File.py
Intermediate representationJVM bytecode in .class filesImplementation-dependent bytecode or internal form
Usual entry mechanismmain method in a classTop-level statements in a module
Block structureBraces, with semicolons commonly usedIndentation
Type checkingPrimarily static, with declared typesPrimarily dynamic, with types associated with runtime values
RuntimeJVMPython implementation/runtime
Typical strengthsLarge systems, explicit structure, performance-oriented deploymentRapid development, readability, automation, data and scientific applications

These are tendencies rather than strict limitations. Java supports dynamic features, and Python can be compiled, optimized, embedded, or used for large systems. The choice should depend on project requirements, team skills, available libraries, performance needs, deployment constraints, and maintainability.

4.1 Compilation errors and runtime errors

A compile-time error occurs while a compiler translates source code. For example, omitting a semicolon in Java may produce an error before a .class file is generated.

A syntax error occurs when the runtime cannot parse source code. Python normally reports such an error when the script is started.

A runtime error occurs after execution has begun. Dividing by zero, opening a missing file, or referring to an undefined variable can cause a runtime exception.

A logic error produces an incorrect result without necessarily causing a diagnostic message. Logic errors require testing, tracing, assertions, code review, or debugging.

5. Working with IDEs and Projects

An IDE normally organizes work as a project. A project may contain source files, test files, configuration files, external dependencies, generated output, and documentation.

When creating a project:

  1. select the correct language and project type;
  2. select the intended JDK or Python interpreter;
  3. create a clear source directory;
  4. save files with appropriate names and extensions;
  5. run a minimal program before adding complexity;
  6. inspect the IDE’s terminal or run configuration when behavior is unexpected.

A Java IDE may ask for a project SDK. This is the installed JDK. A Python IDE may ask for a project interpreter. For small projects, a virtual environment is recommended because it isolates project packages from the system installation. A typical command is:

python -m venv .venv

Activation commands differ by operating system and shell. The IDE can often activate the environment automatically. Isolation reduces version conflicts and makes a project easier to reproduce.

5.1 IDE versus terminal execution

An IDE’s Run button may set a working directory, environment variables, classpath, interpreter, or command-line arguments. Terminal execution makes these choices visible. If a program works in the IDE but not in the terminal, compare:

  • the selected Java or Python version;
  • the current working directory;
  • the source and output paths;
  • environment variables;
  • command-line arguments;
  • installed packages;
  • file permissions.

Learning both methods prevents dependence on hidden IDE configuration.

6. A Systematic Troubleshooting Method

Troubleshooting is an evidence-based process rather than random editing.

Step 1: Read the first diagnostic

Start with the first error message, the filename, and the line number. Later messages may be consequences of the first problem.

Step 2: Confirm the environment

Run:

java --version
javac --version
python --version

Use the commands relevant to the program. Verify that the selected version is the one expected by the course or project.

Step 3: Confirm the location

Display the current directory and list its files. The exact commands depend on the shell, but the purpose is to verify that the source file exists in the directory being used.

A frequent error is running a command from the wrong directory. A file may be correctly saved but invisible to the current command because the terminal is elsewhere.

Step 4: Reduce the program

Temporarily replace a complex program with the smallest program that demonstrates the issue. If a one-line program works, add features one at a time.

Step 5: Check names and case

Java class names, Python module names, commands, and paths may be case-sensitive. Check spelling carefully. In Java, the public class and filename must correspond exactly.

Step 6: Check the actual interpreter or compiler

Multiple JDKs or Python installations may coexist. The command being invoked may not be the one configured in the IDE. Inspect the executable location using the operating system’s command-discovery tool, then compare it with the IDE configuration.

Step 7: Reproduce and document

Record the command, input, error message, version, and steps already attempted. Clear documentation makes assistance faster and prevents repeated work.

Common problems

SymptomLikely causeAppropriate action
javac is not recognizedJDK missing or PATH incorrectInstall a JDK and configure the command path
Java class not foundWrong directory, classpath, or class nameRun from the output directory and use the exact class name
Public class/file mismatchJava names differRename the file or class so they match
Python command not foundPython missing or unavailable in PATHInstall Python or use the configured launcher
Python indentation errorInconsistent block indentationUse consistent spaces and inspect the indicated line
Module not foundPackage absent or wrong interpreter selectedInstall in the active environment and verify the interpreter
Program runs but output is wrongLogic or input errorTrace values and test expected cases

7. Worked Application: A Cross-Language Temperature Converter

The following illustrative example converts Celsius to Fahrenheit. The relationship is:

F = (9/5)C + 32

Here, C is temperature in degrees Celsius and F is temperature in degrees Fahrenheit. The formula applies to ordinary temperature conversion between these two scales; it is not a physical model of every temperature-dependent phenomenon.

Java implementation

import java.util.Scanner;

public class Temperature {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.print("Celsius: ");
        double celsius = input.nextDouble();
        double fahrenheit = (9.0 / 5.0) * celsius + 32.0;
        System.out.println("Fahrenheit: " + fahrenheit);
    }
}

Compile and run:

javac Temperature.java
java Temperature

The decimal values 9.0 and 5.0 make the intended floating-point calculation explicit. The program accepts a numeric input, computes a result, and prints it.

Python implementation

celsius = float(input("Celsius: "))
fahrenheit = (9 / 5) * celsius + 32
print("Fahrenheit:", fahrenheit)

Run it with:

python temperature.py

In both programs, the algorithm is the same, but the surrounding syntax and input mechanisms differ. This illustrates an important professional principle: language syntax changes, whereas problem-solving structures—input, processing, and output—often remain similar.

8. Case Study: A Student Laboratory Setup

This is an illustrative case.

Background

A student team must submit small Java and Python programs. One student reports that Python runs in the IDE but not in the terminal. Another reports that Java compiles but cannot be launched.

Problem analysis

The team first records versions and locations. The IDE is configured to use Python 3.12 from a project virtual environment, while the terminal command python points to no installation. The Java source compiles successfully, but the student runs java Hello.class from the parent directory. The launcher expects a class name and cannot find the class in its current classpath.

Approach and solution

The team selects the project interpreter explicitly in the IDE and documents the command used to activate the virtual environment. They run Python with the environment’s interpreter. For Java, they change to the directory containing the compiled class and execute:

java Hello

They also create a short setup document containing version commands, directory expectations, and run instructions.

Outcome

Both programs execute consistently in the IDE and terminal. The team can now distinguish a source-code defect from an environment or path defect.

Learning points

  • A working IDE configuration does not guarantee a working terminal configuration.
  • Java execution uses the class name and a correct classpath, not the .class suffix in the usual command.
  • Reproducible setup instructions are part of professional software practice.
  • Version control and isolated environments reduce avoidable configuration differences.

9. Best Practices, Limitations, and Professional Responsibility

Use a supported language version, record the version used by a project, and avoid changing several configuration variables at once. Keep source code separate from generated files where practical. Use meaningful filenames, small test programs, and regular backups or version control.

Do not treat an IDE’s suggestions as automatically correct. Auto-completion can insert an unintended method or import. Developers remain responsible for reviewing generated code, including code produced by AI assistants. AI tools can help explain an error or propose a test, but their output may be insecure, outdated, incompatible with the selected version, or simply wrong. Never paste confidential credentials, personal data, proprietary source code, or regulated information into an unapproved service.

Java and Python also have limitations. Java’s explicit structure can increase initial verbosity, while Python’s flexibility can allow errors to remain undetected until execution. Both require testing, readable code, dependency management, and attention to security. A language runtime should be obtained from a trusted source, kept updated, and configured according to institutional policy.

Chapter Summary

A development environment combines source files, language tools, runtimes, libraries, an operating system, and user procedures. Java source is normally compiled by javac into JVM bytecode and launched through the JVM. Python is commonly run through a Python runtime; implementations such as CPython may internally compile source to bytecode before execution. Thus, compilation and interpretation are useful introductory categories but not mutually exclusive technical descriptions.

A JDK is required for Java development, while Python requires an installed interpreter. IDEs provide integrated editing and debugging, whereas terminals expose commands, paths, versions, and environment configuration. Java programs conventionally begin in a main method and require close correspondence between public class and filename. Python programs can contain top-level statements and use indentation to express blocks. Effective troubleshooting begins with diagnostic messages, verifies versions and locations, checks names and paths, reduces the program, and documents the evidence. Finally, reliable programming practice includes isolated environments, reproducible instructions, careful testing, responsible use of AI, and protection of confidential information.

Key Terms

Source file: Text file containing program instructions.

Compiler: Tool that translates source code into another representation.

Interpreter: Runtime component that executes source or intermediate instructions.

Runtime: Services and software required while a program executes.

Bytecode: Intermediate instructions designed for execution by a virtual machine.

JVM: Java Virtual Machine that loads and executes Java bytecode.

JDK: Java Development Kit containing Java development tools and libraries.

JRE: Java runtime components used to execute Java applications.

IDE: Integrated development environment combining editing, execution, and development tools.

Terminal: Text-based interface for entering operating-system commands.

Shell: Program that interprets terminal commands.

PATH: Environment variable listing directories searched for executable commands.

Classpath: Locations from which Java classes and libraries can be found.

Syntax error: Error in the grammatical structure of source code.

Compile-time error: Error detected while source is being compiled.

Runtime error: Error occurring during program execution.

Logic error: Defect that produces an incorrect result without necessarily stopping execution.

Virtual environment: Isolated Python environment for project-specific packages and settings.

Bytecode cache: Stored intermediate representation used by some language implementations to improve loading or execution.

Review Questions

Short Answer Questions

  1. What is the purpose of a Java Development Kit?
  2. Why must a Java public class and its source filename normally have corresponding names?
  3. What is the difference between an IDE and a terminal?
  4. Why is the statement “Python is interpreted” an incomplete technical description?
  5. What information should be checked when a program works in an IDE but not in a terminal?

Long Answer Questions

  1. Describe the complete path from a Java source file to execution by the JVM.
  2. Compare Java and Python with respect to source files, translation, block structure, and program entry.
  3. Explain a systematic method for diagnosing a program that will not run.
  4. Discuss the benefits and limitations of using an IDE for introductory programming.
  5. Explain why virtual environments and reproducible setup instructions are valuable in software projects.

Analytical / Application Questions

  1. A student receives “command not found” for javac, although java --version works. Identify two likely causes and propose diagnostic steps.
  2. A Python program runs in an IDE but reports ModuleNotFoundError in the terminal. Analyze how interpreter selection and virtual environments could explain the difference.
  3. Design a short setup procedure for a class laboratory containing one Java program and one Python program. Include version checks, file creation, execution commands, and at least two troubleshooting checks.

Multiple Choice Questions with Answers

Question 1

Which tool normally translates Java source code into JVM bytecode?

A. The Java compiler, javac

B. The Python shell

C. The operating-system shell only

D. The Java debugger only

Correct Answer: A. The Java compiler, javac

Question 2

Which installation is normally required to compile Java programs?

A. A text editor only

B. A Java Development Kit

C. A Python virtual environment

D. A web browser

Correct Answer: B. A Java Development Kit

Question 3

Which command is normally used to run a compiled Java class named Hello?

A. java Hello.class

B. javac Hello

C. java Hello

D. run Hello.java

Correct Answer: C. java Hello

Question 4

What does the Python interactive prompt commonly look like?

A. ###

B. <<<

C. ???

D. >>>

Correct Answer: D. >>>

Question 5

Why is 9.0 / 5.0 used in the Java temperature example?

A. To force an explicitly floating-point division

B. To rename the Java class

C. To activate the JVM

D. To read keyboard input

Correct Answer: A. To force an explicitly floating-point division

Question 6

Which problem is most directly associated with inconsistent indentation in Python?

A. A classpath error

B. An indentation or syntax error

C. A missing JDK

D. A Java bytecode verification error

Correct Answer: B. An indentation or syntax error

Question 7

What is the primary role of the JVM?

A. To edit Python source files

B. To create operating-system accounts

C. To execute Java bytecode

D. To install every third-party library

Correct Answer: C. To execute Java bytecode

Question 8

If java works but javac is not recognized, which explanation is most likely?

A. The Python file has invalid indentation

B. The Java source contains a logic error

C. The monitor resolution is too low

D. The JDK is missing or its executable path is not configured

Correct Answer: D. The JDK is missing or its executable path is not configured

Question 9

Which statement best describes a logic error?

A. The program runs but produces an incorrect result

B. The compiler cannot find the JDK command

C. The source file has no filename

D. The terminal cannot display text

Correct Answer: A. The program runs but produces an incorrect result

Question 10

What is a major purpose of a Python virtual environment?

A. To replace the operating system

B. To isolate project-specific packages and settings

C. To compile Java into machine code

D. To guarantee that every algorithm is correct

Correct Answer: B. To isolate project-specific packages and settings

Programming Fundamentals
Chapter 2 of 14