In: Computer Science
Problem 1) For each of the following sentences, indicate whether it is a language rule that is enforced by the Java compiler or a convention (that is, not enforced by the Java compiler but most programmers follow it). (a) Variable names must begin with a lower-case letter. (b) The name of a class must match the name of the file containing it. (c) All variables must be declared. (d) There must be a space before and after each operator. (e) All lines after a left curly brace must be indented. (f) Class names must begin with an upper-case letter. (g) Every program must begin with comments describing the author of the program and what the program does.
(a) Variable names must begin with a lower-case
letter.
In java, variable names must start with lowercase letter,
and first letter of next(second,...) words must be in capital
case.
This is the java naming convention rule..
***************************************************************
(b) The name of a class must match the name of the file
containing it.
In java, name of the class should be match with file name,
because of .class file generation.
************************************************************
c) All variables must be declared
In java, we can not use variables before
declaration,
it means variable should decalred first and then it should be used
in program,
otherwise java compiler throws error.
******************************************************************
(d) There must be a space before and after each
operator.
This is not a java rule.
If we are not giving space before and after operator then also java
code compiles successful.
*******************************************************************
(e) All lines after a left curly brace must be
indented.
This is not a java rule.
Indentation in code is the recomendation for better understanding
of code,
but this is not compulsory in java.
*****************************************************************
(f) Class names must begin with an upper-case
letter
This is again java naming convention rule that
class name should be start with upper case letter.
********************************************************************
(g) Every program must begin with comments
describing the author of the program and what the program
does
It is recomended..Not compulsory