7,116 Posted Topics
Re: for (byte j = 1; j <= i; j++){ ... If i is 2, this inner loop will be executed twice (j=1 and j=2) If i is 3, this inner loop will be executed three times(j=1 and j=2 and j=3) etc | |
Re: You CAN declare variables in an interface (Language spec chapter 9.3). | |
Re: I know this is marked "solved", but here's some more info that may be helpful. 1. The console problem is generic to IDE's. NetBeans has it as well. It's a Java thing, as ~s.o.s~ noted. 2. You can achieve the same result easily by using a BufferedReader on System.in as … | |
Re: Line 7 you have new Room(...), but Room isn't a class, it's an interface. You can only "new" a class such as RectangularRoom. But why aren't you adding the Room that's passed in as a parameter? And, you create a new list each tine this is called, and that goes … | |
Re: I use Eclipse. If you refer to a method that is not defined Eclipse offers you a number of possible fixes. One of those is to create a method in the appropriate class with the appropriate signature. Used with a little forethought this can save a whole heap of typing, … | |
Re: The data for a JTable is held in its TableModel. To add a row, you add it to the TableModel, eg [url]http://www.exampledepot.com/egs/javax.swing.table/AppendRow.html[/url] | |
Re: Presumably you are not passing any args to the main method. In Eclipse you can do this in the Run Configurations dialog, in the tab labelled (x)= Arguments | |
Re: A member can't be both static and instance. I think there may be confusion between references and objects here. In masijade's example one is a reference variable. It is static. new Integer(1) is an object. It's an instance of the Integer class. Instance variables are not the same as instances … | |
Re: [QUOTE]it is impossible to define a local (§14.3) enum, or to define an enum in an inner class (§8.1.3).[/QUOTE] Java Language Reference version 1.6 section 8.9 | |
Re: Are you using jmf, quicktime, or what? Each of these have methods to return all the characteristics of a movie. | |
Re: [QUOTE]Also, how do I get my to run my client on a different machine and connect to my own machine? I tried connecting my client to my public ip (cos my server's in my machine), but it wouldn't connect. [/QUOTE] "localhost" 127.0.0.1 usually works, public IP is likely to be … | |
Re: [QUOTE]Hello, I've looked all over for the solution to this problem, but they all present a similar solution to this one and they all don't work.[/QUOTE] Well, actually, they do, which is why you see it described so often. It's not the solution that doesn't work, it's your implementation of … | |
Re: I assume that's part of a method? You declare the ArrayList within the method, so it will vanish each tine the method terminates. You also initialize it to a new (ie empty) ArrayList every time. It needs to be declared and initialized somewhere outside the method. | |
Re: +1 for the above. This was a debate that was settled in the industry in the 1960's. Call it modularisation, delegation, encapsulation, whatever. It's best to break code into small understandable units, and in Java that means classes & methods. | |
Re: [QUOTE]it is not giving desired result.[/QUOTE] Come on now, what is that telling us? Describe [I][B]exactly [/B][/I]what is going wrong - what [B][I]exactly [/I][/B]did you expect and what [B][I]exactly [/I][/B]did you get? | |
Re: If you have JDK 6 installed (and if you haven't, do it now!) then you already have a pretty neat, useful, free, 100% supported database installed and ready to go. JavaDB (based on Apache Darby) is part of a standard JDK6 install. It's very unlikely that you will need anything … | |
Re: I guess you don't want to write a sound hardware driver or anything too low-level, so have a look at JMF - the Java Media Framework. This gives you an API you can use to play media files within some app that you write for yourself. It's about as straightforward … | |
Re: I don't know anything about matlab, so ignore this if its wrong, but, if Areas is a class that wouild be consistent with the error message "Undefined function or variable" (a class is neither a function or a variable). Is "t" a thing that can refer to a class as … | |
Re: Use a javax.swing.Timer to schedule the pull updates. Easy, Safe. ps: Java 6 (1.6) introduced the SwingWorker class to handle exactly this kind of situation (background task with progress reports and a final result to the GUI) - it may be a bit late for your code, but have a … | |
Re: Its not common to see one package per class like that. Normally you would have a package, say "chess", with all those classes in it. That way you can make best use of the different scopes (private/protected/public etc) to share the things you want to share between your classes while … | |
Re: "Enhanced for loop" - new in Java 1.5, and very good. Read it as "for each double d in numbers" It copies each element of numbers in turn to a new double, and executes the loop once for each. You can use this for arrays, lists, all kinds of collections, … | |
Re: Dunno about your threads - it looks somehow much more complex than I would have expected just to multithread these searches. But anyway, you haven't fully followed my correction to your regex, so your regex is still wrong, but this time it's too liberal. By not escaping the . with … | |
Re: First fix this basic problem. To compare two Strings for the same content you can't use ==, that just tests that they are exactly the same object. You need string1.equals(string2) | |
Re: NormR1 wrote:[QUOTE]You can not define a class inside of a method. [/QUOTE] Sorry Norm, that's wrong. Just try this: [CODE] void m() { class C { } new C(); }[/CODE] You can define a class in a method, and its scope is the method, just like a variable defined in … | |
Re: Its a special method that is called when a new instance of a class is created. It's used to initialise anything that needs to be initialised for a new instance. Every class needs at least one, and if you don't supply one the compiler gives you a "default" constructor that … | |
Re: A char is just that, ONE character. 'and' is not a valid char. You want to do a switch on Strings? Don't we all. You can't. It may be introduced in Java 1.7. Have a loook at Hashmap - it allows you to build a lookup table with Strings as … | |
Re: [QUOTE]is that how it works, 1) create a reference to the interface (reciever). 2) use a constructor to allocate a reference (r) and make it equal to the object reference, 3)then call the interface by a method (sendText), which would put an argument/parameter in it 4)implement teh interface on a … | |
Re: Is the class not serialisable because the writer didn't declare it as such, or is there some real reason why it cannot be serialised? Most classes that just contain ordinary data can be serialised - it's normally only a problem if they have handles into non-Java stuff in the operating … | |
Re: Java is checking that retCode will always have a value assigned, no matter which path through your code is executed. If, for example, the getConnection fails, it will go straight to the catch, and retCode will never have a vaue assigned to it. You can either intialise it when you … | |
Re: Perform you function in a Swing Worker Thread, not on the Event Dispatch Thread. I have no time to explain this now, but Google will help. | |
Re: Perform you function in a Swing Worker Thread, not on the Event Dispatch Thread. I have no time to explain this now, but Google will help. | |
Re: Also, if your test char is 'X' then lower-casing the String will guarantee no matches. To do a case-insensitive match, convert both the String and the test char to the same case (lower or upper, doesn't matter, as long as they are both the same). | |
Re: To expand on what norm said: A char is a numeric primitive - its a 16 bit number that's used to hold a Unicode value representing an individual character in some chosen characterset. Primitives like char do not have methods. A String is an Object that holds some text as … | |
Re: It depends on how you want to access the data. Do you intend to read it all in at the beginning, or do you need to read things in dynamically, as queries? Similarly, when/how do you update the stored data - transaction by transaction or all in one go? | |
Re: NormR1 wrote: [QUOTE]Your are expecting the constructor of your class to return a value. If you look at the syntax for a constructor you see that it does not return any value.[/QUOTE] Sorry Norm, that's wrong. You don't get to specify the return value because a constructor ALWAYS returns the … | |
Re: The Date class should help. It holds not just the date but also the time in mSecs. Its default constructor initialises it to the exact time it was created. Its getTime() method returns mSecs, so you can do this: [CODE] long start = new java.util.Date().getTime(); // do whatever long end … | |
Re: Hi jon An (non-static) inner class has access to the instance variables of its containing class, and so it must be accessed through an instance. Static inner classes have no access to instance variables. [url]http://download.oracle.com/javase/tutorial/java/javaOO/nested.html[/url] | |
Re: Because Integers are final, and can't change, maybe the compiler optimises by creating one Integer(5) and pointing both refs at it (like Strings). ? ??? | |
Re: readObject returns an Object, and given that it's reading it from a Stream at runtime, there's nothing else it can do. You have to cast it to the right class before you can use it fully. There's no way to avoid an unchecked cast in this case. You may want … | |
Re: Check that the while loop is being executed by putting a print statement in it. Similarly use prints to confirm that the right cases are being executed in all those nested switches | |
Re: In general: if you hide your internal implementation behind gettersthen you can change the implementation without breaking any other code that uses your class. Ways in which you might change include: Changing the private data type (eg Date to Calendar) Waiting until someone requests a value before creating it (eg … | |
Re: 1. animals[i is an Object (as far as the compiler knows, because that's how you declared it), and Objects don't have a makeNoise() method. The code checks that this particular Object is in fact a Cat, the uses the cast (Cat) to tell the compiler that this particular reference to … | |
Re: I say "yes". Would be an even better algorithm if you replaced "100" by "n" thus making it general | |
Re: How about some basic debugging? after line 12 print the name and the strRegex to see if they are both what you expected. ps does this mean that yesterdays dangling metachar thread is now "solved"? | |
Re: [QUOTE]I am a graduating student, taking up BS IT. Unfortunately, i don't have a talent in the field of programming[/QUOTE] I don't mean to be funny here, but maybe you should be looking at a different career path? Better to face the facts now than to launch into some field … ![]() | |
Re: create a new method in the subclass to pass the call on to the superclass, yhe call that instead public void superA1() { super.a1(); } | |
Re: Windows? Put the jar in your JRE (not JDK) installation folder in the JRE6/lib/ext subfolder. If by API you mean the api documention, that can go anywhere. | |
Re: My guess is that there won't be many people wantinmg to go thru your code line by line debugging it (me included), so here's the next best thing - some help for you to debug it yourself. What I don't see in the code is a whole load of System.out.println(key … | |
Re: "not working" in exactly what way? If there's an exception or error message please give the complete text. If the result is wrong, please let us know what you expected and what yuou got. Is dancersList a non-null instance of List<aClass1>? | |
Re: [QUOTE]to keep DaniWeb a student-friendly place to learn, don't expect quick solutions to your homework. We'll help you get started and exchange algorithm ideas, but only if you show that you're willing to put in effort as well.[/QUOTE] OK? |
The End.