This code should be put into a text file named MessageApp.java
/** Program to display a message and the number of characters in the message on the console. */ public class MessageApp { public static void main(String[] args) { String message = "Java application"; // Give the message System.out.print("The message is: "); System.out.println(message); // Give the number of characters System.out.print("It has "); int numChars = message.length(); System.out.print(numChars); System.out.println(" characters"); /* Alternatively (as we will see soon), we could have done: System.out.println("The message is: " + message); System.out.println("It has " + message.length() + " characters"); */ } }