Write your first program in Java

Photo by Andrew Neel on Unsplash

Write your first program in Java

·

2 min read

In this blog at first we talk about what is the structure of java

What is the structure of the java file ?

As we know that every file in java is created with the extension .java file. This java. file must be in a class.

  • The name of the class file can be started with the upper case. It’s basically the naming convention in java programs however. it is not compulsory to do.

  • Class which having the same name of the such file must be in the public class.

  • The main function/method must be present in the main class. The program is always start in main function.

we already study about how the source code file is converted into bytes (if you don’t know about this then go to my blog why java programming language is the best language).

package jay.com
Public class Main{ 
 public static void main(String [] args){ 
 System.out.println("Hello World"); 
 } 
}

Public = In this program we often have excuses that what Public keyword actually do. Basically it’s used to access from anywhere in the program.

class = It is same type of properties or function .Java is a general-purpose programming language that is concurrent, class-based, object-oriented, and specifically designed to have as few implementation dependencies as possible.

Main = Here Main is the file name that is same as the main file.

public = Here, you probably have question is that what is the second public and how it’s works. so basically it’s used or allow the main function/method that can be used anywhere in the program.

static = Here, static the keyword that is not dependent on objects.

void = In this program void keyword mainly used for return nothing.

main = here, the second main is the function or method of this program.

String[]args = Here, String [] args mainly for command line string type array .

System = Basically it’s the final class that is defined in the java.lang.package.

out = It is the variable of Printstream where it is public and static for member of the System class.