Introduction to Java
Select from among the following, the programming language(s) that Java was directly related to during its development.
- C
- C#
- C++
- F#
- C--
Solution
The correct answers are: (a) and (c)
Java is a strongly typed language, it checks data types mainly at:
- Code editing time
- Compile time
- Debugging time
- Code writing time
- File saving time
Solution
Java is a strongly typed language, it checks data types mainly at:
- Code editing time
- Compile time
- Debugging time
- Code writing time
- File saving time
Java performs strict type checking during the compile time. This means that the Java compiler verifies whether the data types in the program (The Java compiler checks all expressions and parameters to ensure that the types) are used correctly before the program runs. Errors such as type mismatches or invalid type conversions are caught at this stage, preventing the code from compiling successfully until these errors are fixed.
Other options such as code editing time, debugging time, code writing time, and file saving time are not when the language enforces type rules, though some IDEs might highlight issues during editing or debugging.
Which in the below is an identifier?
- public
- main
- args
- String
- FirstProgram
Solution
In Java, identifiers are the names given to various program elements — like classes, methods, variables, interfaces, and packages — so that they can be referred to in the code.
They are created by the programmer and must follow certain rules.
- public
- main — the method name (an identifier).
- args — the parameter variable name (an identifier).
- String — a predefined class name from the Java API (an identifier but not user-defined here).
- FirstProgram — the class name defined in the program (a user-defined identifier).
— a Java keyword, not an identifier.
Note: If multiple answers were allowed, main, args, and FirstProgram are all identifiers in this snippet.
Select from among the following the valid option(s) that can be considered as keywords of the Java programming language.
- public
- static
- void
- main
- String
Solution
In Java:
public
→ keyword ✅static
→ keyword ✅void
→ keyword ✅main
→ ❌ not a keyword (it’s just a commonly used method name in the entry point).String
→ ❌ not a keyword (it’s a predefined class in java.lang).
Correct options: (a) public, (b) static, (c) void
Java: Keyword vs Identifier — Explanation
🔑 Keyword in Java
Definition: A keyword is a reserved word in Java that has a predefined meaning and purpose in the language syntax.
Examples:
class
if
else
public
static
int
new
return
Rules:
- Cannot be used as variable names, method names, class names, or other identifiers.
- All keywords are lowercase.
- The meaning of keywords cannot be changed by the programmer.
🆔 Identifier in Java
Definition: An identifier is the name given to a variable, method, class, object, or interface by the programmer.
Examples: Student
, totalMarks
, calculateSum
, myVar123
.
Rules:
- Must start with a letter, underscore
_
, or dollar sign$
. - Cannot start with a digit.
- Cannot be a keyword.
- Case-sensitive (
Student
andstudent
are different). - Should be descriptive and follow Java naming conventions.
📊 Comparison: Keyword vs Identifier
Aspect | Keyword | Identifier |
---|---|---|
Definition | Predefined reserved word in Java. | Programmer-defined name (variables, methods, classes, etc.). |
Purpose | Defines structure and syntax of code. | Names elements in your program. |
Examples | class , int , while , return |
age , Employee , sumOfNumbers |
Case | Always lowercase. | Case-sensitive; may mix cases. |
Who decides? | Java language designers. | The programmer. |
Can be reused? | No — fixed meaning (reserved). | Yes — create any valid identifier (following rules). |
✅ In short
Keywords = Reserved by Java (you can’t change their meaning).
Identifiers = Chosen by you (to name things in your program).
Example Java snippet (shows both)
Is String
a Keyword in Java?
No — String
is not a keyword in Java.
Explanation
String
(with a capital S) is a class in thejava.lang
package.- You use it to create string objects.
- Since it’s a class, technically you could define your own class named
String
(but that would be confusing and discouraged).
Important Difference
string
(all lowercase) is not recognized in Java (unlike C#).- Only
String
(capital S) refers to the built-in class.
✅ Conclusion
String
= Identifier (predefined class name, not a keyword).
It is not reserved by the Java compiler as a keyword.