Q:

typeOf without using getClass() or instanceof

I am currently trying to use System.out.print to give out the type out of an integer x. However from what I've found the only functions simular to typeOf are getClass, which does not work on int, or instanceof, which seems to only work with an if. Is there any other command I could try or am I stuck with System.out.print("Integer")? 

A:

Note that Java is statically typed language. There's no need to check the variable primitive type at runtime, because it's known at compile time and cannot change. For example, if you declare
int x = 5;

Then x cannot be anything else other than int, so trying to do something like typeof(x) (like in some other languages) is meaningless.
You can generalize the variable type assigning it to the Object reference type:
int x = 5;
Object obj = x;

But even in this case obj will not be int. In this case Java compiler will automatically box your x to Integer type, so obj.getClass().getName() will return java.lang.Integer and obj instanceof Integer will return true.

