-4

I have studied about java which have listed 50 Java keywords. There is a homework of Lex, the goal is to recognize the word is keywords, IDs, symbols, operators. But there is one more little problem is the code below, is print in System.out.print() an ID or keyword?

 public class HelloWorld {
    public static int add(int a, int b) {
    return a + b;
    }
    public static void main(String[] args) {
        int c;
        int a = 5;
        c = add(a, 10);
        if (c > 10)
            System.out.print("c = " + -c);
        else
            System.out.print(c);
        System.out.print("Hello World");
        }
}
Dhanuka
  • 2,826
  • 5
  • 27
  • 38
user2871337
  • 115
  • 11

2 Answers2

3

print is the name of a method in the java.io.PrintStream class, hence an ID. Keywords are those which generally turn blue or another colour when you type them in most IDEs.

For more information: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/index.html

kaykay
  • 556
  • 2
  • 7
1

System is a final class from java.lang package.
out is the reference of PrintStream class and a static member of System class.
print is a method of PrintStream class.

//the System class belongs to java.lang package
class System {
  public static final PrintStream out;
  //...
}

//the Prinstream class belongs to java.io package
class PrintStream{
public void print();
//...
}

Have a look at this too.. https://docs.oracle.com/javase/7/docs/api/java/lang/System.html

Dhanuka
  • 2,826
  • 5
  • 27
  • 38