Im writing a simple program to understand classes and objects. Basically what I have is a file called Program.java where I have my main method.I have another file called Person.java which I want to use to create Person objects. That person can have a name, email adress, phone number, etc.I put both these files in the same folder.in Program.java my first statement is:
My problem is that when I compile Program.java i get an error message saying that the package Person.java does not exist.So my question is, when you create a class that you want to use for objects, how do you import that class into your class with the main method so that you can use instances of your other class?
I am puzzled by a note in the book I am reading (by Mala Gupta). Page 55 says "All java components you've heard of can be defined within a java class: import and package statements, variables.....". But the online oracle doc (tutorial) clearly says the following 2 statments:
"If present, package statement must be the very first line in a file"
"To import a specific member into the current file, put an import statement at the beginning of the file before any type definitions but after the package statement, if there is one. " (Here).
So, how can import and package be present inside a class ? (This seems to go against the 2 statements from oracle online tutorial).
I was wondering if I could write this code in one line.
import java.util.Scanner; public class Test { public static void main(String[] args) { Scanner sc = new Scanner(System.in); char ch = sc.next().charAt(0); } }
Can I combine "import java.util.Scanner","Scanner sc = new Scanner(System.in);" and "char ch = sc.next().charAt(0);" in one statement? The object created from the class Scanner may be anonymous but it doesn't concern me!
I am trying to write a program, which includes an import data option. This option is used to import information from a text file.
The data is read from the file and objects are created and added to the student's record (The text file contains some information of the courses that the student is taking).
So my question is, how do i import information from a text file ?
and after they are imported, how do i create the objects in order to add them to the student's record ?
I would like to build a GUI where by I can import a text file and interrogate certain values and then display them in a window. Thing is I would like to know what window type that will support this. i.e Panel,internal frame,dialog box.. etc etc... I am using Netbeans.
I am trying to figure out how to import a txt file that has a color and a four digit number. Everything that I have tried comes up with some kind of error.
I couldn't find an edit button. I need to store the String and int from the txt file into an array. The problem that I keep having is that the compiler seems to want it as either two ints or two Strings.
Label is not a valid type., TableView is not a valid Type., etcera
This exception I then solve with placing an import tag inside the .fxml file.
However as I do not know each import name, I have to look this up like writing down:
Label label = new Label();
inside a class and then place my cursor on it to see which import name Eclipse generates.
This import name i then put inside the .fxml file with <? import ?> beginning and end tags with question marks around it.
Is there anyways to automatically generate these import tags inside an .fxml file even if you don't know the import name for the control you want to use?
How to import data from a file using Object Oriented Programing? I know how to write OOP Java and I know how to read data from a file in Procedural Java but would like to know more about how to do it OOP. Is it the same as reading data process as in Procedural programming?
I have several different PopupWindows that i want to access from the same fragment. I would like for each PopupWindow to be it's own java file. Here is trimmed down code from an example showPopup.java file,
showPopup.java public class showPopup { //public class showPopup extends Activity implements View.OnClickListener{ //public class showPopup extends Window { public static Context appContext; PopupWindow popupWindow; SQLiteDatabase db; EditText edSpeciesLookup,edSpeciesLookupRowid;
[code]...
How do I configure inheritance to allow showPopup() class to reside in it's own Java file and be called from another class (file)? I've reviewed several hours of online resources as well as my reference books with no productive illumination. I've tried a number of possible implementations and extensions such as "public class showPopup extends Activity implements View.OnClickListener{...", and "public class showPopup extends Window.
1.) Is FileReader class the same as File Class. In my book it uses File class to read data from a file, but one of the members here used FileReader so I was wanting to know if it's identical function or not.
2.) When creating an output file, I will use
PrintWriter outputfile("hello.txt")
i just read a new topic of " appending data to a file," meaning if I want to preserve the old file I would have to use this. From my understanding all this does is prevents the old data from being deleted.
Now, in my code if I type ( "hello.txt",true)this would preserve the old data?
i am migrating my web application from Server1 (Tomcat 5 and Java 1.5) to Server2 (Tomcat 7 wand Java 1.6).
In my web application, I have multiple adapters (web clients) that are connecting to external web services, https interfaces, sftp servers etc.
In order to connect with all these external interfaces, i have installed multiple certificates in my JRE keystore on Server1.
Now since the application is going to be migrated to Server2, i need to know if there is any way I can import all the existing certificates from Server1 JRE to Server2 JRE?
Since the application has been running on Server1 for a long time, I am not sure, what exactly is a complete list of certificates that I need to install on my Server2 JRE.
So i am kind of looking how can i generate the keystore file with certificates from the existing server1 JRE and then import it into Server2 JRE.
Does this command provide a list of all the installed certificates on my Server1 JRE?
The other solution i can think of is to manually download/save all the certificates by opening all the URLs in the browser and then import the .pfx files through keytool into my Server2 JRE.
how to make a simple game. I am having trouble when it comes to adding sound though. It tells me to do this:
package net.game.Game;
import java.applet.Applet; import java.applet.AudioClip; public class Sound { public static final AudioClip BALL = Applet.newAudioClip(Sound.class.getResource("ball.wav")); public static final AudioClip GAMEOVER = Applet.newAudioClip(Sound.class.getResource("gameover.wav")); public static final AudioClip BACK = Applet.newAudioClip(Sound.class.getResource("back.wav")); }
What this does is it gets the sound file then gives it a name(BALL=ball.wav GAMEOVER=gameover.wav ect..) and then there is other code in other classes that call the sound so it will run but it keeps giving me an error and I don't know what to do. How can I get it to import the sound? Here is the error.
PHP Code:
Exception in thread "main" java.lang.ExceptionInInitializerError at net.game.Game.stuff.<init>(stuff.java:35) at net.game.Game.stuff.main(stuff.java:62) Caused by: java.lang.NullPointerException at sun.applet.AppletAudioClip.<init>(Unknown Source) at java.applet.Applet.newAudioClip(Unknown Source) at net.game.Game.Sound.<clinit>(Sound.java:7) ... 2 more
I'm making an import/export of xml - I have the import of xml sorted I'm just trying to finish off the export. My export class is called XmlWriter.java. Inside the class I have an updateFile method to update an xml file as such:
public void updateFile(Environment environment,Document doc) { // code }
I then in my main method have
public static void main(String argv[]){ //declare new object of class XmlWriter xmlWriter = new XmlWriter(); //test testUpdate method // xmlWriter.testUpdate(); Environment environment = ;
[code]....
I don't know what to make my variables equal to - eclipse keeps trying to use null but obviously that won't work. The Environment is another class that just contains getters and setters for the 3 different databases (that are in the xml file) and the getter/setter for the environment ID (also in xml file).
Often times i don't remember which package a specific class (like ArrayList) belongs to. Is there an easy way to find that java.util.* is what i need to import, if i wanted to use the class ArrayList ?
I have imported several maven projects but I am trying to import a spring project via eclipse and it is not displaying. I did the following file->import->Existing maven projects->browse (found my project)->finish..... The project does not display and I cannot find it. I tired to do it again and the project cannot import because I cannot select it meaning it is already installed.
I am still playing around with decks of cards, and am now trying to implement some visualizations using Applets.
Here is how I enter my deck of cards into an array list: this works just fine:
String[] Suits = new String[]{"S","H","D","C"}; String[] Values = new String[]{"A","2","3","4","5","6","7","8","9","10","J","Q","K"}; ArrayList<String> deck = new ArrayList<String>(); for(String suit : Suits) { for(String value : Values) { deck.add(suit+"_"+value); } }
The end result of this is an array 'deck' which contains a string representing each of the 52 playing cards. Great.
Now I would also like to use some pictures for future implementations I am working on. I have 52 images (.png, though I doubt it matters) stored in the right place. They are named as "H_5.png", and "S_A.png", for example, just as I named the cards in the previous array. I would like to do something as follows
ArrayList<Image> deckpic = new ArrayList<Image>(); for(String suit : Suits) { for(String value : Values) { deckpic.add(getImage(suit+"_"+value+".png")); } }
Now of course this doesn't work. The line
suit+"_"+value+".png"
is a string, not the name of a file. How I have previously loaded images is to use something like this:
the_pic = getImage("picture_of_pony.jpg");
but of course I can't use the quotations in my card loop, since I want "suit" and "value" to range and not just be the strings suit and value.
This code doesn't recognise the package ( and therefore class ) timetest3, when I try to import it. The package I try to reference/call, follows, and works fine.
import javax.swing.JOptionPane; import timetest3.TimeTest3; public class timetest4 { public static void main(String args[]) { TimeTest3 time = new TimeTest3(); time.setTime(13,45,52);
I have written a library in one project but cannot seem import to import it into my main project whenever I try Maven says it cant find it though it is installed in the repository and the .jar file is in the classpath.
Stack trace org.jclarion.clarion.lang.ClarionCompileError: Class Not Found:com.MyProj.app.MyClass near line:310 (selma012.clw) at org.jclarion.clarion.lang.Lexer.error(Lexer.java:190) at org.jclarion.clarion.compile.grammar.AbstractParser.error(AbstractParser.java:111) at org.jclarion.clarion.compile.grammar.AbstractParser.importJava(AbstractParser.java:463) at org.jclarion.clarion.compile.grammar.AbstractParser.emptyLex(AbstractParser.java:258)