Java Basic Syntex




	package MyFolder
	/**
	*
	Comments	
	*/
	public class WelcomeDemo
	{
	public static void main(String...args)
	{
	System.out.println("Welcome To Java Programming");
	
	}
	}

package MyFolder:

It is package declaration statement. package is keyword and MyFolder is directory in which we have created source file.

It must be first line of your program.Package statement cannot appear anywhere in program.

The package statement defines a name space in which classes are stored. Package is used to organize the classes based on functionality.

If you omit the package statement, the class names are put into the default package, which has no name.

public class WelcomeDemo

public This is access modifier keyword which tells compiler access to class. Various values of access modifiers can be public or default (no value).

class This keyword used to declare class. WelcomeDemo is the name of this class.

Comments section Comments never executes. It is for documentation purpose. We can write comments in java in two ways.

Line comments It start with two forward slashes (//) and continue to the end of the current line. Line comments do not require an ending symbol.

Block comments start with a forward slash and an asterisk (/*) and end with an asterisk and a forward slash (*/). Block comments can also extend across as many lines as needed.

public static void main (String... args)

Its method (Function) named main with string array as argument.

public Access Modifier.

static static is reserved keyword which means that a method is accessible and usable even though no objects of the class exist.

void It is return type. This keyword declares nothing would be returned from method. Method can return any primitive or object.

main It is starting point of our program.

String... args It is a parameter. It is a String array.This array can accept commend line argument.

{ } Start and Stop for methods

System.out.println("Welcome To Java Programming")

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.

WelcomeTo Java Programming It is String literal set as argument to println method.

Points To Remember
  • Java program has first statement as package statement (if package declared).
  • One Java file can have multiple classes declared in it but only one public class which should be same as file name.
  • Java class can have instance variable such as methods, instance variable.