Java Program Structure ?
Let’s use example of HelloWorld Java program to understand structure and features of class. This program is written on few lines, and its only task is to print “Hello World from Java”
public class hellow{ //main method declaration public static void main(String[] args){ System.out.println("hello world"); } }Public class Hellow
This creates a class called Hellow. You should make sure that the class name starts with a capital letter, and the public word means it is accessible from any other classes.
CommentsJava Comments are used in programs to make the code more understandable. Comments in Java (remarks) make a program more intelligible as they set the details of the code. Appropriate utilization of remarks also makes support simpler and discovering bugs effectively.
BracesJava program is like an outline, why doesn’t a program look like an outline? What takes the place of the Roman numerals, capital letters, and other things? The answer is twofold:
- In a Java program, curly braces enclose meaningful units of code.
- You, the programmer, can (and should) indent lines so that other programmers can see the outline form of your code at a glance.
The public static void main() is the most important java method. The compiler starts executing the java program from the main method.The public static void main() is the most important java method. The compiler starts executing the java program from the main method.
String[] args"String[]" means we are going to use an array of String type."args" is the name of the String[]. "args" is not a keyword, so you can name it anything else and it would not affect your program
System.out.println();- System:It is name of Java utility class
- out:It is an object which belongs to System class
- println:It is utility method name which is used to send any String to console.
- “Hello World ”:It is String literal set as argument to println method.
Copyright © 2022 Shineskill Software Pvt. Ltd., All rights reserved.