How to comment code in java | hindi coding community

0


 In the last article we learnt how to print hello world in java. In this article we will look at how to comment some code in Java.

Again, before we start this article you should know few things .

1. Java is a complete Object oriented Programming language.

2. Your code must be written inside a class.

3. Java is a case sensitive language.

First of all let's see what is comment .

Comment :- It is nothing but some lines of code we don't want to run at the run time.

So lets write hello world program in Java


class HindiCodingCommunity{
public static void main(String args[]){
System.out.println("Helllllllooooo Wooooooorld");
}
}

So now you know how to print hello world in Java but suppose you want to write hello java and you do not want to remove the earlier println line . Let's see how can we do this.


class HindiCodingCommunity{
public static void main(String args[]){
//System.out.println("Helllllllooooo Wooooooorld");
System.out.println("Helllllllooooo Java");
}
}

You can see the line in green right ? that line is commented . It will not execute during run time.

Imagine if your code is very big and you want to comment around 100 lines in that case what would you do ? will use // in every line. Thats very lengthy work so we will do something else for multiline comment.


class HindiCodingCommunity{
public static void main(String args[]){
/*
System.out.println("Helllllllooooo Wooooooorld");
System.out.println("Helllllllooooo Java");
System.out.println("Helllllllooooo Programmers");
System.out.println("Helllllllooooo Developers");
*/
System.out.println("Helllllllooooo Coders");
}
}

In this case we use /* then we have some code then end it with */ 

In this way we can comment some lines in Java language.


Hindi coding community provides you the best articles for you to learn Java .

If you want to write for us please contact us at hindicodingcommunity@gmail.com


Post a Comment

0Comments
Post a Comment (0)

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !