yt

Header Ads

Chapter 5 What is Syntax of Java/ Keywords/ Comments Explain in Details.

 Syntax Of Java Program :- 

What is Syntax:- It is a code of word excited rule of Program then say at last it is a format of Program

.


class Easy {
            public static void main(String[] args) {
                System.out.println("Hello World");
            }
        }


 

 class

1.It is a keyword which is used to declare a class.

2.Keyword:The word which is predefined in the library is called keyword.

for example class, void, main etc.

Easy

1.It is an user defined class name.

 

public

1.It is a keyword which is called access specifier/modifier.

2.It is used to provide accessibility of data member(variable) and member function.

 

static

1.It is a keyword.

2.It can be used with a variable or function or block, we will discuss it in next chapter.

 

 

Void

1.It is a keyword.

2.It indicates that there is no value is returning by the function.

3.If we use any other keyword like int, float, char etc,  in place of void then we will use return keyword.

 

 

main()

1.It is the function which is called the entry point of any program.

2.The execution of any program starts from the main function.

3.If in a program there is only one function then it should be main function.

 

String[]args

1.It is an array of type String.

2.It is also called command line argument.

3.you can write anything in place of args

 

System.out.println()

or print, printf()

1.It is used to print data or information on to the output screen.

2.System.out means Standard output object.

3.println is a method/function.

 I think follow this table explain hope your doubts your clear.

Keywords in Java 

  • The keyword which is pre-defined in the library is called keyword. It's functionality is also pre-defined.
  • Keyword can not be used as a varible,  function_name, class_name or as any identifier. 
  • Example of Keywords are int, float, char, void, main etc.

List of Keywords  in Java 

Char

Continue

Catch

Finally

Int

Default

Interface

Class

Float

Assert

Abstract

Const

Double

Abstract

Public

Protected

Long

Implements

Bytes

Case

Short

Private

Native

Goto

If

Break

Volatile

New

Else

Enum

Synchronized

Static

Do

Import

Switch

This

While

Strictfp

Transient

Try

For

super

Throws

Final

Instanceof

Extends

Boolean

Pakage

Return

Void

 

 


Comments in Java 
  • It is used to explain the code to make it more readable.
  • It is not considered as a part of program. 
  • In other word we can say that compiler ignores the comments.
  • Java comments are statements that are not executed by the compiler.
Types of comments in Java
  • Single line comment
  • Multiline comments

Single line comment :- 
  • It is used to comment only one line.
  • Two forward slashes(//) is used for single line comment.
  • Single line comment starts with double forward slashes.
//this is a single line comment
System.out.println("you are excellent");



Multi line comments:- 
  • Multiline comment is used to comment a block of code.
  • Multiline comment statrts with /* and ends with */.
  • The text between /* and */ is not executed by the compiler.
  • An Example of Program 
        class Easy {
            public static void main(String[] args) {
/*
This is multiline comment
Write a program to add
two number and store it
in third number
*/
        int x, y = 10, z = 30;
                x = y + z;
                System.out.println("Add=" + x);
            }
        }
        /*
        Output is:
        Add=40
        */


No comments

Theme images by Dizzo. Powered by Blogger.