Tt
Click this widget to change the font size.
CC
Click this widget to change contrast.

Home Page 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | Links | Search | Bio |

Guide to Object-oriented Programming With Java (Buffalo State University Version)


Chapter 2: Your First Java Program

Java is a popular programming language that is especially suited to develop applications for business and the Internet of Things (IoT).

This guide will use the Eclipse IDE (Neon version) to develop the java code.

Hello World!

Most beginning programmers start with the standard "Hello World" code:

package edu.buffalostate.cis425.fa10.exercises..put-your-username-here;

/**
 *
 * File: helloworld.java
 *
 * This is a Hello World Application
 * It prints a short statement to the standard out
 */

public class HelloWorld {
/**
 * The main methid is the entry point for a Java program when executed
 *
 * @param args String[] - command line arguments passed to program
 * @return none
 */

  public static void main(String[] args) {
  // print to the console
    System.out.println("Hello World!");
  }
}

Figure 2-1: Code for helloworld.java

The Eclipse Console would look like this:

Console
<terminated>
Hello World!

Figure 2-2: HelloWorld.java Console Output

Java Comments

Java provides inline, single line, multi-line, and JavaDoc comments. You can even use HTML tags in JavaDoc comments.

JavaDoc comments:
    
  /**
  * The <b>main</b> method is the entry point for a Java program when executed
  *
  * @param args String[] - command line arguments passed to program
  * @return none
  */
  
Multi-line comments:

/*
 This
 is
 a
 multi-line
 comment
*/

Single line comments:

// print to the console

Inline comments:

  System.out.println("Hello World!");// print this out
   
Figure 2-3: Java Comment Examples

Help contribute to my OER Resources. Donate with PayPal button via my PayPal account.
Creative Commons License This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. Copyright © 2016-2024 Jim Gerland