This is my second programming class and I am new to Java. I have been working on my first assignment and it involves classes and methods. I know very little about these topics and find myself lost. My assignment asks me to create a RPN calculator that asks the user for two numbers and an operator. The calculator performs the
Tag: class
What does .class mean in Java?
What does .class mean in Java? For example, if I created a class called Print. What does Print.class return? Answer When you write .class after a class name, it references the class literal – java.lang.Class object that represents information about a given class. For example, if your class is Print, then Print.class is an object that represents the class Print
Accessing non-visible classes with reflection
I am trying to get an instance of a non-visible class, AKA package private class, using reflection. I was wondering if there was a way to switch the modifiers to make it public and then access it using Class.forName. When I try that now it stops me saying I can’t do it. Unfortunately there is no setAccesible method of the
An interface with different method parameters
I want to declare an interface be use with several classes this classes have method with different parameters interface: class A: class B: how to impelement of this interface? Answer you could make an operand-object or
What happens if import statements can not be resolved?
I am not clear on the following: A class is loaded by JVM when needed, like lazy initialization, right? Now if class A does an import of class B which class B actually is not in the file system (e.g. B.class was deleted or not delivered or any reason) then does class A get loaded and runs if no method
Android Call a method from another class
I know that this Question is repeated but I can’t find the answer in the Internet. I want to call a method from another class. I have Class1 and Class2. In Class 2 I have this method: I want to call the above method from Class1. Thanks for any answer. —-EDIT—- —-LogCat— Answer You should use the following code :
Java ClassLoader: load same class twice
I have a ClassLoader which loads a class compiled by JavaCompiler from a source file. But when I change the source file, save it and recompile it, the ClassLoader still loads the first version of the class. What am I missing? like a newInstance or something? Answer A classloader can’t replace a class that already has been loaded. loadClass will
Eclipse – Show generated class files
How can I show the folder (bin) where my class files are placed after I build a project in eclipse? I want this directory to show up in the package explorer. Searched the forums, but can’t seem to find an answer Answer You can view the the bin folders in the Navigator (Window –> Show View —> Navigator), which is
Java: can you cast Class into a specific interface?
I’ve got a project I am working on and in this project I would like to include the ability for developers to include their own plugins without having to change the whole code. This is what I have …
What is this: [Ljava.lang.Object;?
I get this when I call toString on an object I received from a function call. I know the type of the object is encoded in this string, but I don’t know how to read it. What is this type of encoding called? Answer [Ljava.lang.Object; is the name for Object[].class, the java.lang.Class representing the class of array of Object. The