First program in java - HelloWorld
A "Hello, World!" program is a simple program that outputs the message "Hello, World!" on the screen. It's often used as the first program that new programmers learn to write in a new language. Here's an example of a "Hello, World!" program in Java:
This program consists of a single class called "HelloWorld" and a single method called "main".
The "public" keyword before the class declaration indicates that the class is available to other classes in the program. The "class" keyword is used to declare a new class. The class name "HelloWorld" should be the same as the file name (HelloWorld.java)
The "main" method is the starting point of a Java program. It's where the program begins executing. The "public" keyword indicates that the main method can be called by any other code. The "static" keyword indicates that the method can be called without creating an instance of the class. The "void" keyword indicates that the method does not return any value.
The System.out.println("Hello, World!"); is used to print the string "Hello, World!" to the console. The System.out is an object that represents the standard output, and the println() method is used to print a line of text to the console.
When you run the program, the computer will execute the code in the main method, which will print "Hello, World!" to the console.
Comments
Post a Comment