Java programming structure lesson

In this lesson, you'll learn about the structure
 of a java program, how a program executes statements and how to
 fix syntax errors check out the most common program below which only has a single class-main

 public class Main{
  public static void main (String [] args){
  //this is a comment
  //Main method added
  System.out.println("java");// first statement
  System.out.println("is"); // second printline statement added
  System.out.println("Cool");
  }

 }

We've added the main method public static void main() as the execution starting point of the program. Finally, we have added a println statement inside of the main method field. Now if you run your compiler it should print "java", we have added another printline statement that will run after the first one look at it in the main method field. each printline statement is executed and print a text in a line. now notice what happens if you remove the semi-colon at the end of the statement, guess what! you should see an error now on your compiler indicating by a red squiggly line. java program will only run if they contain no errors. Now add a third printline statement that will prints "Cool" below "java" and "is" then execute afterward.
 The output should be 3 lines now. the words after the forward-slash (/) indicates a comment, it only contains explanation but is not executed.

Post a Comment

0 Comments