Introduction to Java

Select from among the following, the programming language(s) that Java was directly related to during its development.

  1. C
  2. C#
  3. C++
  4. F#
  5. C--

Solution

Java Object-oriented features of Syntax of C++ C Descendant of

The correct answers are: (a) and (c)

Java is a strongly typed language, it checks data types mainly at:

  1. Code editing time
  2. Compile time
  3. Debugging time
  4. Code writing time
  5. File saving time

Solution

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 class FirstProgram{
	public static void main(String args[]){
	System.out.println("Bachelor of Information Technology Degree");
		}
	}
  1. public
  2. main
  3. args
  4. String
  5. 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
  • — a Java keyword, not an identifier.

  • 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).

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.

  1. public
  2. static
  3. void
  4. main
  5. 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 and student 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)

  // Keywords: public, class, static, void, int, return
// Identifiers: MyClass, main, args, x, addNumbers
public class MyClass {
    public static void main(String[] args) {
        int x = 5;                 // 'int' is a keyword; 'x' is an identifier
        int result = addNumbers(x, 3);
        System.out.println(result);
    }

    public static int addNumbers(int a, int b) { // 'addNumbers', 'a', 'b' are identifiers
        return a + b; // 'return' is a keyword
    }
}

Is String a Keyword in Java?

NoString is not a keyword in Java.

Explanation

  • String (with a capital S) is a class in the java.lang package.
  • You use it to create string objects.
  String name = "Hello";
  • 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.

Popular posts from this blog

Evolution of computers and Computers today

Convert into binary

Processor Types and Specifications