Jump to content

Programming Fundamentals/Introduction Examples Java

From Wikibooks, open books for an open world

Overview

[edit | edit source]

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.[1]

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

Example

[edit | edit source]

Hello World

[edit | edit source]
 // 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

[edit | edit source]
Hello world!

Discussion

[edit | edit source]

Each code element represents:Programming Fundamentals/Hello World

  • // begins a comment
  • class Main 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

[edit | edit source]

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.

Cloud-Based IDEs

[edit | edit source]

Local IDEs

[edit | edit source]

References

[edit | edit source]