JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Unless you are processing a vast number of dequeues against a huge queue then "faster" is not going to be relevant. Do you reeally care if they take 1 microSecond vs 2 microSeconds?
Easy to code, easy to read and understand, easy to debug, easy to modify or enhance - those are the issues that matter (listed in increasing order of importance).
Arrays seem simple, but you have to deal with low-level issues like growing the array when its initial capacity is exceeded, of shuffling down all gthe following elements when you delete one in the middle.
IMHO linked lists are better to work with in every respect, except for the speed of accesing random elements by their index number (but see first sentence above).
As for " linkedlists being old, unfashioned n stuff... and arrays are the way to go" - that sounds like total rubbish to me - anyone else want to offer an opinion?

Final observation: in real life, if this was a critical part of some performance sensitive big application, I would write a small class to encapsulate this functionality, and keep the implementation (array / linked list / tree set etc) private. That way, if it became necessary, I could try different implementations without having to change or break anything else.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

DaniWeb Member Rules (which you agreed to when you signed up) include:
"Do provide evidence of having done some work yourself if posting questions from school or work assignments"
http://www.daniweb.com/community/rules

Post what you have done so far and someone will help you from there.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You can loop through all the keys, or loop through all the values. HashMap has methods that give you all the keys or all the values so you can loop through them. Inh this case you could loop through all the keys, checking the values that each key refers to, and saving that key if it refers to the value you want.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Don't confuse variables and objects. std in the create method is a variable, specifically a reference variable. It's scope is the body of the create method, and it will cease to exist immediately when the method finishes executing. Line 13 does not create a new variable, it just changes the value of the existing variable.
new STD() creates an object, and std = new STD() sets the value of std to be a refeence to that object. In the absence of any other code, std is the only reference to that new object, so when std goes out of scope there will be no remaining references to the object. The object therefore become unreachable, and will be garbage collected at some unspecified later time.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

What's odd about that is that the standard error message containts the complete file name that was used in the command, so if you typed
javaw -jar JavaApplication14.jar
the error message should be
unable to access jarfile JavaApplication14.jar
but it's not. Wierd.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
Unable to access jarfile JavaApplication14

The .jar extension has to be explicit in the jar file name, eg

javaw -jar JavaApplication14.jar

maybe that was the problem?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

As for 5th question
This program is to reverse the array elements

Are you quite sure it doesn't just rotate the elements right by 1 position?

[ edit: original post now updated as per IIM's comment]

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It seems Oracle have rushed out a quick fix (or maybe just a sticking plaster?) for this one...
http://www.oracle.com/technetwork/topics/security/alert-cve-2013-1493-1915081.html

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Java is parsing the last semicolon on line 18 as the statement that the for loop has to execute. Since it doen't contain any code (just a ;) that's what is called an empty statement. It also means the block that starts with the { on line18 is not part of the for loop. That semicolon is a mistake.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

WHat class are you using for your "form" - if it's a JFrame you can call its setTitle method any time to change the title.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Instead of setText, use append to append your new text to the text that's already in the text area. (You may want a new line character "\n" as well)

tux4life commented: Doesn't deserve to be downvoted, the given answer is correct. +13
~s.o.s~ commented: Doesn't deserve downvote +14
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Why not just define the button as the default button - then you can hit enter any time the focus is in the container, plus it gets painted with a highlighted appearance so you know it's the default?

getRootPane().setDefaultButton(findButton);

stultuske commented: that would do the trick allright. +14
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

When in doubt refer to the JLS. Here's what is says: (my bolding)

MethodDeclaration: MethodHeader MethodBody

MethodHeader: MethodModifiersopt TypeParametersopt Result MethodDeclarator Throwsopt
...
8.4.5. Method Return Type
The result of a method declaration either declares the type of value that the method returns (the return type), or uses the keyword void to indicate that the method does not return a value.

I don't see how that could be any clearer; a return type is mandatory, it may be the keyword void.
So IMHO the "teacher" is wrong about methods called "main" in general, and even more wrong about the main method. Scary!

tux4life commented: Yaay, JLS! :) +13
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Capture a proper specification of the scope and important functionality. UML Use Cases are one good way to do it. Don't try to get it 100% complete or correct, because it's going to change anyway. From there you can start an object design (class diagram, activity diagram). Avoid the temptation to start codeing too early.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Any special reason to use convoluted arrays and lookups like that? Why not just have a HashMap<Card, Image> and load that with the 52 cards and their respective images. Then you can just use imageMap.get(card);
(Assumes you hace defined equals method for the Card class)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

mKorbel is going to disagree with me but...
In my opinion, key bindings are the right solution for real-life development, but they are not easy for a beginner. KeyListener is much easier to understand. The more you use key listener the more you will run into its problems and limitations until you are ready to tackle key bindings to solve all those problems. For now, I think you will be OK using key listeners.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

To use the paint method from bbb you need to create an an instance of the bbb class, eg change line 3 to

aaa aaa_class = new bbb(); // valid because bbb is a subclass of aaa
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Headsup! JRE 1.7.15 just released. "Fixes security problems"

peter_budo commented: Well done +15
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

How do I fix this error,

Wrong answer: Just thinking about it for more than about 30 seconds.
Wrong answer: Post it on DaniWeb without sharing the line number where the exception was thrown.

Right answer:
1. Get the line number where the exception is being thrown. See wha the array and index expression are
2. If there's more than 1 index expression on that line then print all the index expressions and corresponding array sizes to find out which it is.

Now you have some hard data you may be able to see the problem, or you could share that data here for more help.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

No it won't. This is Java. Declaring clicked global will simply create a compiler error. Please don't confuse Java beginners by using non-Java terminology and giving advice that they can't follow, and wouldn't work even if they did.

ps: DaniWeb Member Rules include: "Do post in full-sentence English". Members with English as their second (or third...) language won't uinderstand "ur".

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's because the compiler has seen that the two if tests on lines 16 and 20 could both be false, in which case neither of the assignments on lines 18 and 22 will be executed, and the tryAgain variable will not have been initialised by you.
You need to decide what the correct value of tryAgain should be if both if tests fail, and initialise tryAgain to that value when you declare it, eg by changing line17 to boolean tryAgain = true;

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

No need to take it personally. No insult was intended. You would probably be surprised how many beginners would literally copy and paste a fragment like that. You didn't show any code, so I had to guess what it was that crashed.
Anyway, I'll stay out of this thread if that's what you want.
J

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The "... etc etc" was intended to tell you that the code was incomplete. I'm not going to write your program for you. You can find information and tutorials on the switch statement, then use the example I gave you to apply that information to your own program.
I have pointed you in the right direction, but you have to make the journey yourself.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

while(tryAgain = true)

= is assignment, to test for equals use ==

but in this case, since tryAgain is already a boolean (true or false) yu can just say
while (tryAgain)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

rubberman: don't forget that Java chars are Unicode, 16 bits per char, four hex digits not two.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It's possible you have a previous test still running, so the port is still in use. Check the task manager for instances of java.exe or javaw.exe.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You mixed text output and data input streams. They have different formats, and can't be mixed. Either use text streams to send and receive text only, or use a DataOutputStream with a DataInputStream to send and receive different data types (inlcuding UTF Strings).

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Sorry M4.... but that post makes absolutely no sense at all. When posting about Java please use standard Java terminology. If you are not sure, check in the Java Language Specification to see what the correct terms are.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The debug statemengt I'm looking at shows tcid and cwid but it does NOT show the actual array content.
You are updating tcid, but you are not updating the array.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, people will help. You need to explain exactly what help you need...

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
  1. Yes. Swing calls paintComponent when needed. Resizing the container os one reason why a repaint would be needed.

  2. rand.nextInt(255) returns a random int in the range 0-254, not 255. The Color constructor takes three values 0-254 representing the red/green/blue components of the color, so that whole code creates a new color with random R G and B components covering the full range of valid colors.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Because your code doesn't include anything to process key events? (It only has listeners for mouse click events.)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

jalpesh ... those are != tests, so the code is OK.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

presentValue = futureValue/(Math.pow(1+(annualIntrestRate), futureValue));

Just re-read that - where are the years???

xHellghostx commented: Whoops my apologies.. I guess I rushed through it.. But I am getting a huge number as a percentage value. +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Simplest code is probably

      String[] a = {"a","b","c"};
      Vector<String> v = new Vector<>(Arrays.asList(a));

Edit: oops - I missed the fact hat tux4life had already covered this - sorry for the duplication. J

tux4life commented: Exactly :) +13
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You have choices, but what I would do is:
Read one line at a time
Split that on the ';' delimiters
Where one of those splits needs to be futher parsed (like your eg above) do a second split, eg

String[] tokens = line.split(";");
// tokens[2] is now "310000 euros"
String[] money = tokens[2].split(" ");
// money[0] is now "310000" and money[1] is "euros"

And don't forget to use print statements to see what your code is doing!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
> catch(Exception e) {
>    System.out.println("File not found");
> }

This is a mistake. There are many other Exceptions that could be thrown from that try block (eg file access/reading errors, NumberFormatException from parseInt, or an array index exception if there are not enough tokens in the line[] array). By supressing the real exception and printing your own guess you are potentially misleading yourself. You could spend hours trying to fix a "file not found" when the real problem is in the parsing.
Either restrict your catch to the specific exception (FileNotFoundException) or include an e.printStackTrace(); so youcan see the truth.

tux4life commented: Excellent advice :) +13
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You seem to be mixing parsing with a Scanner and parsing with String.split, and getting the two confused.
Your Scanner splits the file by the ';' chars, but you don't use that in your parsing, you just read whole lines. Then you try to split each of those lines on a blank char instead of a ';'.
I would keep the readLine, but then split the line on the ';' character, after that your code is heading in the right direction.
ps: When faced with a bug like this, add a load of print statements to your code so you can see what's going on. Eg if you printed your line[] array you would immediately see that it's using the wrong delimiter.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You are using setText(...), which replaces any existing text. Try append(...) instead

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

.exists down't work

.exists does work. It's been in the Java API forever, and is used in more programs than we can count. The fault almost certainly is either in your understanding or in your code. The most likely problem is that Java is looking for the file in a different directory. Follow bguild's excellent advice and print f.getAbsolutePath() to see where Java is looking for your file.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Your moouseMoved method has a MouseEvent as parameter. MouseEvent has a getComponent() method that returns the conponent (your JButton), so you can use getName on that component

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The isDirectory() method makes it very clear that the File class doesn't see a directory as a file. If in doubt read the API...

public boolean isFile()
...
Returns:
true if and only if the file denoted by this abstract pathname exists and is a normal file; false otherwise

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

To make it more like a c header file full of defines, you can declare pubic static final members, as bguild explained, then at then start of any .java file you can
import static mypackage.MyClass.*;
Now you can simply use the public static member names in that file without needing to qualify them with the package/class names.
For example, the java.lang package contains the Math class, and that has the useful member
public static final double PI = 3.14159265358979323846;
so if you
import static java.lang.Math.*;
you can simply refer to it as PI in your code

rose_anne commented: ok.. understood d way it works now. +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hi jalpesh
Do you have any specific reason for suggestingSystem.out.println(String.format(... rather than System.out.printf(...
I thought that's what printf does anyway?

And what is the rationale for doing both, as in System.out.printf(String.format(" ?
J

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That is part of a loop that will reverse the digits in a number. It makes no sense without the loop.
To see how it works, pick a number and go through that code by hand working out the results for each line.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I agree. The Oracle tutorials are the definitive best source for the most complete and up-to-date training material. The problem is "complete" - which means thety rapidly get into all kinds of detail that can overwhelm the beginner. They start with some high-level overview stuff taht is definitely a good read. Then, as you start to drill down into specific topics that interest you, it's easy to read the first few pages of a topic, then drop out when it goes too deep. The "really big index" makes it easy to see what there is.
If you are coming from Basic then probably the most important single topic to start with is the Object Oriented Concepts topic.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You can usually hold money as an integer number of cents - very few applications ever neen to handle a fraction of cent. int will usually do, or long if you need amounts over 20 million dollars. If you write a simple method to take a value in cents and format it as a String with dollars and cents, dollar sign, commas etc then it's no harder than working in floating point dollars.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Your request is very general, and sounds like it will need more time that anyone here has got.

Strt by reading the starting Java thread, the have alook through the Java projects for learners thread. Pick a project that interests you and try to design/code/test a solution. If/when you get stuck, come back here for specific help.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, you could use the % operator to take the remainder after dividing score by 10.
Now all your values are 0-9 and you have only one test (>= 5) in a single if/then/else

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You need a .class file or .jar file to run javaw, a .txt won't run. But in prinicple there's no problem running javaw from within Java.
ps Runtime.exec was superceeded by the ProcessBuilder class from Java 1.5
You'll find loads of examples on the web.