Core Java (Horstmann) – Java Intro Notes (CNIT255)

Lecture Objectives

  • Identify key components of the Java Development Kit (JDK)
  • Describe the purpose and benefits of using an Integrated Development Environment (IDE) for Java Development
  • Use JShell for interactive Java programming
  • Explain and write the structure of a basic Java program
  • Compile and run Java programs using the command-line tools
  • Demonstrate how to pass command-line arguments to a Java program

Java Jargon

  • JDK (Java Development Kit): The software for programmers who want to write Java programs
  • JRE (Java Runtime Environment): The software for consumers who want to run Java programs
  • SE (Standard Edition): The Java platform for desktops and simple server applications
  • JavaFX: An alternative toolkit for graphical user interfaces included in Oracle’s Java SE distribution
  • OpenJDK: A free and open-source implementation of Java SE
  • J2: An outdated term describing Java versions from 1998 until 2006
  • SDK: An outdated term describing the JDK from 1998 until 2006

JDK Components

  • Java Compiler (javac): translates Java source code into bytecode
  • Java Virtual Machine (JVM): executes Java bytecode by providing a runtime environment tailored to the operating system
  • Java Runtime Environment (JRE): includes the JVM, core libraries, and other components needed to run Java applications
  • Java Archive Tool (jar): used for creating and managing .jar files that bundle multiple Java classes and resources

Integrated Development Environment (IDE)

  • IDEs: IntelliJ, Visual Studio Code, Eclipse, NetBeans
  • Definition: a comprehensive environment for coding, compiling, running, and debugging Java programs
  • Lab0 provides instructions for setting up your Java programming environment with Oracle JDK 8 and NetBeans 12

JShell

  • A Read-Evaluate-Print Loop (REPL) designed for interactive learning and testing code snippets, exploring APIs, and understanding Java concepts
  • Benefits: no need to write boilerplate code; immediate feedback

The First Program

  • The simplest Java program that can be compiled: public class Hello { }
  • Significance: demonstrates the minimal class structure required by Java

The First Executable Class

  • public class Hello { public static void main(String[] args) { } }
  • Meaning to recall: public, static, void, main, String[] args as the entry point

The Hello World Program

  • public class Hello { public static void main(String[] args) { System.out.println("Hello world!"); } }
  • Significance: the simplest class that produces output

Command-Line Tools

  • Although an IDE is convenient, Exercise 1 practices writing source code in a text editor and compiling/running via command-line tools
  • Purpose: to delineate the path from source code to a running program

From Source Codes to Running Programs

  • Pipeline: Editor -> Source File -> Compiler -> Class files -> Library files -> Running Program
  • Concept: Building and executing Java applications from source to runtime

Compile with Command-Line Tools

  • To compile: javac Hello.java
  • Result: Hello.class
  • Note: simple example demonstrating the compile step from source to bytecode

Run with Command-Line Tools

  • To run: java Hello
  • Result: prints the program’s output (e.g., Hello, World!)
  • Note: demonstrates how to execute the compiled class file on the JVM

Command-Line Arguments

  • Example program idea: public class Hello { public static void main(String[] args) { System.out.println("Hello, World! " + args[0]); } }
  • Compile: javac Hello.java
  • Run: java Hello BoilerMakers
  • Output: Hello, World! BoilerMakers
  • Concept: main method receives command-line arguments via the args array