How to Display Output using Java

In this tutorial, you will learn the basic elements and concepts of Java Programming language to create a Java Program. You will know the effect of an output statement in this program. I will be using the JCreator IDE in developing the program. To start in this tutorial, first open the JCreator IDE, click new and paste the following code.
  1. public class MyFirstJavaProgram
  2. {
  3.  
  4.         public static void main(String[] args)
  5.         {
  6.        
  7.         System.out.println("My First Java Program");  
  8.         System.out.println("the sum of 2 and 3 = " + 5);
  9.         System.out.println("7 + 8 = " + (7 + 8));  
  10.        
  11. }
  12. }
The basic unit of a Java program is a class. Typically, every Java class consists of one or more methods. A method is a set of statements or instructions whose objective is to accomplish something. In the first line of the program, that is: public class MyFirstJavaProgram MyFirstJavaProgram is the name of the Java class. The second line of the program consists of the left brace, which is matched with the second right brace(the very last brace). These braces together mark the beginning and the end of the class MyFirstJavaProgram. The Third line consists of the following line: public static void main(String[] args) This is the heading of the method main. A java class can have at most one method main. If java class contains an application program, such as the preceding program, it must contain the method main. When you execute the program, execution always begin with the method main. The fourth line consists of a left brace(the second left brace of the program. This marks the beginning of the method main. The first right brace (on the eighth line of the program)matches the left brace and marks the end of the method main System.out.println("My First Java Program");   This statement causes the program to evaluate whatever is in the parentheses and display the result on the screen. Typically, anything in double quotation marks, called a string, evaluates itself. Therefore causes the system to display the following line on the screen: My first Java Program Let us now consider the following statement: System.out.println("The sum of 2 and 3 = " + 5); In this output statement, the parenthesis consist of the string “The sum of 2 and 3 = “, + (the plus sign), and the number 5. Here the symbol + is used to join the strings. In this case, the system automatically converts the number 5 into a string, joins that string with the first string, and displays the following line on the screen: The sum of 2 and 3 = 5 Let us now consider the following statement: System.out.println("7 + 8 = " + (7 + 8)); In this output statement, the parenthesis consists of the string “7 + 8 = “, + (the plus sign), and the expression (7+8). In this expression (7+8), notice the parenthesis around 7+8. This causes the system to add the numbers 7 and 8, resulting in 15. The number is then converted to the string 15 and then joined with the string “7 + 8 = “. Therefore, the output of this statement is : 7 + 8 =15

Comments

This did not tell me how to get Java Project to my pc screen.... that was my question.

Add new comment