JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Oracle's own tutorials are excellent and comprehensive, and kept fully uo-to-date. (But that does mean that they are not always easy).
Be aware that many tutorials on web are out of date to vatying degrees. Java 8 was released last spring and has some major new features (eg JavaFX), and it would be a shame to spend time learning about features that have been superceeded.
If Android devlopment is part of your plans then that's an excellent reason to go with Java.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Depending on your video file formats (mp4 is good), Java has built-in capabilities for playing video files directly in its own GUI - no need to install/interface with an external video player.
http://docs.oracle.com/javase/8/javafx/media-tutorial/overview.htm#JFXMD101

(But if you want to support the meximum possible range of file dormats, VLC is the most capable)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Your loop (line 6) keeps dividing number by 2 until it's zero - then you print it. So of course it's zero.
One fix is to use a copy of number in the loop, so the original number isn't changed.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Simply call dispose() on the containing window (closes it and releases all its resources) and make sure you have no other references to the JTable so the garbage collecter can get rid of it.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Do you just want to close a JTable inside a window that stays open, or do you want to close/free a whole winodw, including the JTable that's in it?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Then you need those numbers (IP address?) in your getConnection call, not just "host"

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

"jdbc:mysql://host:3306/dbname"

is the server really called "host"?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Admins and Mods have access to your IP address.
It's time to end this bull and move onto something productive.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

MIT offered me a scholarship as soon as they heard my my mother was pregnant, but I was too busy correcting Einstein's mistakes in General Relativity to take it up. I was also on the Apollo 11 mission - it was me who took all the photos on the moon (which is why I'm not in any of them).

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

"And of course I know APIs! "

Of course you do, all of them, 100%.
Well. you really had us all fooled for a while there.
Anyway, I'm going back to working with adults now.
Bye

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Remember also that the programming language is by far the smallest and easiest thing a Programmer has to learn.
Much larger is the API (.net, Java SE API etc) withoiut which the language is useless. The Java API is over 4000 classes with tens of thousands of methods...
Also working with others adds a load of compexity - not just code mamnagement, but working with others, some of who will be really dumb...
Then there's designing/structuring programs - no subsitute for experience here

Stuugie commented: This is what I was thinking, great post! +6
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

" If a question can be framed at all, it is also possible to answer it. ~ Ludwig Wittgenstein"

Didn't Godel disprove that?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Either you have a truely exceptional ability or you don't really understand what it means learn or know a language.
Maybe if you post some examples of your best code people here could tell you which it is?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I have to disagree with Traevel about && vs &
Firstly:
The JLS 15.23 says: "&& computes the same result as & on boolean operands. It differs only in that the right-hand operand expression is evaluated conditionally rather than always."

So it depends on if it matters whether the RHS is evaluated or not. Sometimes it's essential that it isn't (eg x!=null && x.something). More rarely it's essential that it is (eg RHS calls a mthod with essential side-effects like lazy initialisation of something, or may need to throw an Exception to reveal an error).

In the most usual case, where it doesn't matter if the RHS is evaluated unneccessarily, the && version has a slight efficiency advantage, that's all.
For that reason most people automatically use && rather than & unless there's a need for the RHS always to be evaluated.

This preference is so deep that when the Oracle tutorials introduce logical operators they don't even mention the & version ( http://docs.oracle.com/javase/tutorial/java/nutsandbolts/op2.html )

(And ditto for || vs |)

ps: if(x!=null && x.something)... is a common idiom that saves a couple of keystrokes compared to the explicit meaning of if (x!=null) if (x.something) ...
This usually happens when null is used as a valid value for a reference, indicating the absence of a real instance. Now Google "Tony Hoare and the Billion Dollar Mistake".
That's why Java 8 has added the java.util.Optional<T> class that, when used as intended, will …

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

20 differ = annualSales,
What is this intended to do? annualSales wasn't initialised explicitly, so differ will just be a copy of its default value of 0

if (n < -1 && n > NUM_EMPLOYEES -1)
Unless NUM_EMPLOYEES is negative, this expression can never be true.

Lots of people (me included) don't have the time to decypher un-indented code.

ps: yes, conventions are matters of opinion, but for Java there are Sun/Oracle's own documented set of conventions that are always used within the Java development community (eg see the source code of the Java API classes), and so those are the ones you should use unless your employer/teacher requires otherwize.

Traevel commented: Agreed! I should've better specified the difference between "opinion" conventions and official conventions. +5
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I would take a few minutes to print out ALL the variables after the server & client have been initialised. My guess is that you will find something that does not get initialised to the same value.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

encrypted = encryptCipher.doFinal(plainText);

Then encryptCipher must be null. Seems you failed to initialise it?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Line 93 is a comment, so the code you posted does not correspond to the exception. Which line causes the NPE?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You could use a layout manager (eg GridBagLayout) that will grow components according to the available space.
http://docs.oracle.com/javase/tutorial/uiswing/layout/visual.html

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's the AES encrypt/decrypt with a system-generated secret key.
As always, Google is your friend. It only took a minute to find
this link to an example of generating an AES key from a password.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Good morning. (Sorry abou the relay in replying, it was bedtime here!)

You are requesting DES and MD5, so I can't believe that will give you an AES implementation. Looking at the docs it seems that the early verisons of java crypto were very limited in their choice of algorithms, and AES was not initially supported in the standard API. I found lots of examples of AES Java code in more recent web sites, so maybe a Google search limited to the last year should be your next step.

ps:Having said that, Taywin's link seems exactly what you need.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

setSize rarely has any effect with a layout manager. setMinimumSize and setPreferredSize are recognised by most layout managers unless they conflict with the layout manager's own rules.
The simple layout managers are really just for simple cases; if you know GridBagLayout then you can use that to force almost any kind of fitting you want.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Which on-line doc are you referring to?
(ps: I'm no expert in this area, but as nobody else has responded I'm also trying to interpret the doc and related tutorials. I'll leave you in peace if you want to wait for an actual expert.. JC)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Why do you think that PBEWithMD5AndDES will generate any kind of AES key?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

This is the downside of not using a layout manager!
Try adding a listener for the resize events and resetting the necessary bounds in the event handler.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The output of the encrypt is a byte array that can contain any sequence of byte values, yet you try to convert that into a UniCode String using your system's default charset and back again and hope that will give the same byte array. Unless you are very lucky, it won't.
If you simplify your code to return the byte array from the encrypt, and pass that as input to the decrypt, you should be able to get that working. Then you could re-consider why you are trying to convert the byte array to String, and what alternatives there are (eg 2-chars-per-byte hex text)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

In real life I would expect to have to do some experimenting to get the right results and sensible code, but as a starting point...
1: Yes, I'd have a JPanel for that whole "File" area
2: How about a JSeparator(javax.swing.SwingConstants.VERTICAL)
3: I would make that a JButton, if only because it's a thing you click.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You can do almost anything with a GridBagLayout, but it's not easy to write, and even harder to read! The simplest approach is just to use JPanels within JPanels to build it up starting from the smallest groups.
At the topmost level a JTabbedPane will give you the tabs and the means to navigate/control them.

(Or the equivalent components in JavaFX)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, it's a bit like length() for arrays - just tells you how many rows there are.
You subtract 1 because the rows are numbered 0 to (n-1) (just like elements in an array).
So if there is 1 row, it's number 0. If there are 2 rows they are number 0 and 1. Etc.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Presumably the row variable contains a row number in the range 0 to (n-1) where n is the number of rows in a JTable, and InteractiveForm.this.tableModel is a reference to the JTable's table model, in which case...

InteractiveForm.this.tableModel.getRowCount() gives the number of rows, so
InteractiveForm.this.tableModel.getRowCount() -1 is the number of the last row

so that code is testing to see if row refers to the last row in the table

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

JavaFX has a rich set of classes to handle animation, so you don't need to mess about with low-level timers or (shudder) timing loops.
Have a look at the javafx.animation.Animation class and its TimeLine subclass, and the AnimationTimer class and related tutorials (this one looks pretty good). It's a higher-level way of dealing with events over time that will need you to do some re-structuring of legacy code, but in the end will save you a lot of tedious coding.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If row numbers are 0-based, you will never get a row number >= rowCount.

With a problem like that it's always quicker and easier to do a little bit of debugging. If you simply print the retuirn values of those method calls on line 3 you will immediately see what's happening.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

How about checking the values of getEditingColumn() and getEditingRow() ?
(Details are in the API doc as always.)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You're getting that error because the constructor you used to create your JTable is a simple one that doesn't build a TabelModel that supports adding rows.

DefaultTableModel is the obvious first choice. To get a DefaultTableModel you simply ask for one, ie

DefaultTableModel tm = new DefaultTableModel(data, colNames);
table= new JTable(tm);

now you have a JTable with a TableModel that supports adding rows.

Setting up the event handler to add the row at the right time is a different problem, but ... one step at a time

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You could create a simple form to capture the info for one quote. Maybe a bit more work than a JTable, but you could make the user interface look a lot more familiar to the user.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

As in my previous post: It's getModel, not getTableModel, and you have to cast the returned value to (DefaultTableModel) because thats where the addRow method is. (Unless, of course, you have defined your own TableModel.)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, a second XOR always takes you back to the original value.
That's not the real problem here. He has a load of additions, reversed by a load of subtractions. Mathematically the order of the additions or subtractions doeasn't affect the final result. But when you stick another operation (eg XOR) in the middle then it does matter which adds/subtracts you do before that operation, and which you do after it. And that's where I think this code goes wrong...

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I may have the answer, but don't have the time to check it out fully. Anyway...

encrypt:
add first 4 sets of numbers
XOR
add last 4 sets of numbers

decrypt (actual):
subtract first 4 sets of numbers
XOR
subtract last 4 sets of numbers

decrypt (should be):
subtract last 4 sets of numbers
XOR
subtract first 4 sets of numbers

(or maybe I just mis-read it in a hurry)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

He adds a load of numbers befroe XORing, and a load more afterwards, so these need to be subtracted when decoding.
ps: Since they are all just added, I can't see the value of those arrays of primes. Just 8 big numbers would do the same thing. And since the XOR just affects the last byte of the long, it has no effect on most of the number anyway (just look athe encrypted values). Any why use long's when they get cast to int for the XOR anyway?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

oh :(

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I noticed the decrypted values are just the original values - 130
That must be a clue to the problem

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Here's the trick:
JTable is just a view, the actual structure and data is in its TableModel.
Get your JTable's TableModel (DefaultTableModel) myTable.getModel(), and add a new row to that addRow(Object[] data)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Which part of that is the problem? Responding to the enter button, adding a blank row to a table, or something else?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

In as PURE OO langage like SmallTalk that's true, but not for Java.
The designers of Java were worried about the overheads of using an Object for simple stuff like numbers or true/false, so they decided to have some data types, called primitives, that are not objects, and have none of the overheads of objects.
The primitive types are:
byte short int long char float double boolean
(notice they all have names beginning with a lower case letter). Everything else in Java IS an object.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Use a modal JDialog to hold the components (see API doc for details)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

No, that's not what it outputs. The actual output is

i=1 , j=0
i=2 , j=0
i=2 , j=1

(all you needed to do is to run it)

Just step through the two loops one step at a time...

i = 0
   j = 0
      i == j, continue outer
i = 1
   j = 0
      print
   j = 1
       i == j, continue outer
i = 2
   j = 0
      print
   j = 1
      print
   j = 2 - exit loop
i = 3 - exit loop
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It would help if yu posted the actual code.
Line 115 you call a method TopCost, but you haven't defined any such method.

Many of your methods are confusing because they set an instance variable, but they also return that value, and when you call the method you ignore the return value.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

stultuske & I usually agree, but maybe not this time.
In my opinion, real projects end up with a lot of code, and structuring that is the single most important skill in software. Working in a team forces you to define a good structure with clearly separated and defined responibilities and public interfaces for all every module.
UML class diagrams force you think about modules, classes, and their interfaces, and to document those in a standard formal way. "Plain English" may be a first step towards the UML, but it's no substitute.
Do all that and, in the end, writing the code is the easy part.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

What you are describing is a large and complex area, so you will need multiple projects to make real progress.
My advice is to start with small simple steps. Pick a simple project from the Projects for Beginners thread, and work through the UML class diagrams all the way to working code. There are many people here who will review and comment on your progress as you go. I doesn't matter much what the project is (although an MVC structure will give you some decent classes and relationships) - it's just something concrete to make a start with.
Working with others on a joint project is the ultimate goal, but unless you have already developed some relevant skills you will find it hard to get a team to welcome you.
Good luck!
J

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You can skip to a new line any time by using a \n (newline) character. eg
System.out.println("\nHello");
will print a newline followed by Hello

Your loop's end == false test is only executed at the start of each iteration. So in your second iteration you enter stop, set the boolean, but you still execute the rest of that iteration before looping back to line 17 to test the boolean end exit the loop.
One solution is to use a break; statement to exit the loop immediately, eg (pseudocode)

while (true) {
   get the name
   if (name is "stop") break; // exit loop immediately
   ...