Skip to main content
Engineering LibreTexts

1.13: Java Examples

  • Page ID
    10592
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    234px-Java_programming_language_logo.svg_.pngOverview

    Java is a general-purpose computer-programming language that is concurrent, class-based, object-oriented, and specifically designed to have as few implementation dependencies as possible. It is intended to let application developers “write once, run anywhere” (WORA), meaning that compiled Java code can run on all platforms that support Java without the need for recompilation. Java was originally developed by James Gosling at Sun Microsystems and released in 1995.

    Java is one of the most popular current programming languages[1] and is often used in computer science courses.

    Example

    Hello World

    // This program displays "Hello world!"
    //
    // References:
    // https://introcs.cs.princeton.edu/java/11hello/HelloWorld.java.html
    
    class Main {
        public static void main(String[] args) {
            System.out.println("Hello world!");
        }
    }

    Output

    Hello world!
    

    Discussion

    Each code element represents:[2]

    • // begins a comment
    • class hello begins the Hello World program
    • { begins a block of code
    • public static void main(String[] args) begins the main function
    • System.out.println() calls the standard output print line function
    • "Hello world!" is the literal string to be displayed
    • ; ends each line of Java code
    • } ends a block of code

    Java IDEs

    There are many free cloud-based and local IDEs available to begin coding in Java. Check with your instructor or do your own research for recommendations.

    Local IDEs

    • BlueJ
    • jEdit
    • jGRASP

    References

    • Wikiversity: Computer Programming

    1. TIOBE: Index
    2. Wikibooks: Programming Fundamentals/Hello World

    1.13: Java Examples is shared under a CC BY-SA 4.0 license and was authored, remixed, and/or curated by LibreTexts.

    • Was this article helpful?