I am taking a Java class and so far, my instructor has been spectacularly less than helpful when it comes to the assignments we need to complete and turn in. I have a couple of questions about the program I am writing and was hoping for a few minutes of tutor time.
I am taking my first JAVA class as well at UH. The instructor cant teach worth crap! Why is it so hard to teach java?
can you have more than one class in one program? And how would that work? What do you save the file as?
If what you meant by program is a single file, then yes. You declare your initial class, the one with the main function in it, as a public class. then whatever utility classes you have you don't put the public key word in front of them. And the file need to have the same name as the your public class.
awesome, makes sense so it would be liek ------------ public class Rockets { public static void main(String args []) { System.out.println("I love the rockets"); Tmac.shots(); } } class Tmac { shots() {System.out.println("i took 30 shots"); } }
well, kinda, but since your shots method is not static, you have to initiate the Tmac class first. public class Rockets { public static void main(String args []) { System.out.println("I love the rockets"); Tmac tracy = new Tmac(); tracy.shots(); } } class Tmac { public void shots() {System.out.println("i took 30 shots"); } }
I am writing a histogram class that is supposed to grab data from an instructor provided class called histogramData.class. Unfortunately, even though it is in the directory specified in my classpath, NetBeans keeps reporting that my reference to histogramData is bad.
Do I need to import it like I import other Java objects? If so, do I specify the class file (histogramData.class) or is that unnecessary?
Did your instructor put that class in a package? Cause then you would have to import it in your file after setting your classpath to the directory above the package. For example: c:\Rockets\Data\histogramData.class with histogramData in the Data package. You could have your file in Rockets and then import Data.*.
I have the histogramData.class file in the c:\Program Files\Java directory, which is in my classpath variable. I don't know what to do from there.
Did your instructor give you any information about how to use that file? He must have said what class is in it (probably histogramData) and how to use that class. You should only need to import if it's in a package. What environment are you using, Eclipse?