On line 1 Object j = l.get(x); // Line 1 the "get" should return an object of type String, you can nicely assign this to a variable of type Object. At runtime, the object returned is not a String but the Integer-object 123. This can also be assigned to an Object without problems.
In line 2 however System.out.println(l.get(x).getClass().getName()); at runtime you will also get the same 123 Integer object back, and again a String is expected. But this time the Integer-object is not assigned to an Object variable but to a String variable. This must happen somewhere in the getClass-method. And then the cast fails and you have the exception. I don't know what happens exactly in the getClass() - method. It is native.
By the way, the getName() should not be the problem, the exception comes also when you delete that part.