Comments
Comments in programming languages are the values ignore by the compiler. Usually comments are used in the programming language for documentation. Suppose you write the code for the some specific piece of work and use in your current project, after 3 months you need that same function again you could remember that code is somewhere but you need to read all the logics and identified the desired code. If you have code in this code you can take that code from that place.
There are two type of comments
- one line comments
- multiline comments
Let see how to implements the comments in Java code
Single line comments
Multiline comments
Single line comments
// This is single line comments
public class Main {
// main method it is entry point for the java program
public static void main(String []args){
// Display the output on the console
System.out.println("Hello World");
}
}
Multiline comments
/* This is multiline comments
This class will use for the main method
*/
public class Main {
/*
main method it is entry point for the java program
what you want to write here!!!
*/
public static void main(String []args){
// Display the output on the console
System.out.println("Hello World");
}
}
Expressions
In this lesson we will learn about the expressions in Java. Expression is combination of the values, variables, constants and operators. Let say x is a variables and has a value 4. If we say
y = x + 3
is expression.
public class MyClass {
public static void main(String []args){
// expression
int x = 4;
// expression
int y = 7;
// expression
int answer = x + y;
// output
System.out.println(answer);
}
}
/*
This is expression example
*/
public class MyClass {
public static void main(String []args){
// This is string value
String x = "Hello";
// expression
String y = "World";
// expression
String answer = x + y;
// output
System.out.println(answer);
}
}






