Comments in Java are identical to those in C++. Everything between
/* and */ is ignored by the compiler, and everything on a single
line after // is also thrown away. Therefore the following program
is, as far as the compiler is concerned, identical to the first
HelloWorld program.
// This is the Hello World program in Java
class HelloWorld {
public static void main (String args[]) {
/* Now let's print the line Hello World */
System.out.println("Hello World!);
} // main ends here
} // HelloWorld ends here
The /* */ style comments can comment out multiple
lines so they're useful when you want to remove large blocks of
code, perhaps for debugging purposes. // style
comments are better for short notes of no more than a line.
/* */ can also be used in the middle of a line whereas
// can only be used at the end. However putting a
comment in the middle of a line makes code harder to read and is
generally considered to be bad form.
Comments evaluate to white space, not nothing at all. Thus the following line causes a compiler error:
int i = 78/* Split the number in two*/76;
Java turns this into the illegal line
int i = 78 76;
not the legal line
int i = 7876;
This is also a difference between C and ANSI C.
Bhopal news
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100