llaspina 19 Light Poster Team Colleague

Now that's just silly!

java.lang.NumberFormatException: For input string: ""

One of the text fields was blank and your code tried to do an Integer.parseInt on it. Make sure you fill in all the relelvant text fields and make sure the code is processing the data from the text fields properly.

llaspina 19 Light Poster Team Colleague

Yes, try removing it. You are attempting to add the data with resultSet and also with a update query statement. Do one or the other, not both.
If the code is not working, it should be throwing a SQL Exception. What exactly does the exception say? Instead of sending the exception to a JOptionPane, you might be better off using printStackTrace() on it. Then you will at least know exactly which line of code is throwing the exception.

llaspina 19 Light Poster Team Colleague

I wrote this a while ago because I wanted to implement the Fletch readability index.

The question really has nothing to do with Java (but of course you can express the method in Java). The basic idea is that every group of vowels marks a new syllable. Then you can make this simple rule more precise by adding exceptions (not Java exceptions, English exceptions).

Given a word, just iterate though the letters with a for loop and the String charAt method. Write a boolean isVowel method to make the syllable count easier and more readable. You can also use the String split method to beak up the string into an array of strings at the vowel grouping marks.

llaspina 19 Light Poster Team Colleague

Are you getting a sql exception?
There is no need for ResultSet here. The sql insert should take care of everything you need.

llaspina 19 Light Poster Team Colleague

Massive is relative, but I expected it's too long to just post here. That's why I suggested git.

llaspina 19 Light Poster Team Colleague

Please post your code or a link to it on github.

llaspina 19 Light Poster Team Colleague

The way I have handled this in the past is by creating a simple text based messaging system and using UDP to broadcast the messages. This requires that all the clients have a thread running that just listend for incoming messages. When a UDP packet is received, that thread needs to update your data model, but it CAN NOT update the UI. In Swing, only the EventDispatch Thread can update the UI. This leaves you with something like this:

   if(newCardPlayedOrSomething) {
      //change some data to bring the client in sync with the server.
      javax.swing.SwingUtilities.invokeLater(new Runnable() {
         public void run() {
           methodThatUpdatesUI();
         }
      });
   }

Are you using Datagrams? (for example, see http://docs.oracle.com/javase/tutorial/networking/datagrams/clientServer.html)

llaspina 19 Light Poster Team Colleague

There are a number of ways of storing Time. The java.util.Date object stores date and time. You can use it to just store time, but it's not ideal. In answer to developers' frustration with this and other issues around java.util.Date, new APIs were added to Java8.

The best fit for your use case is probably LocalTime.

Instead of reading the time in as a double, read it as a String.
You can then use DateTimeFormatter for parsing the time into a LocalTime object.

llaspina 19 Light Poster Team Colleague

To say that an aglorithm works means that we tested it on some input values and verified that it gives us the right answer.
What input did you check the math with? How many kids were you assuming?

From my earlier post:

To prove toourselves that we really understand the task, let's say we have a family of 5: mother, father, and three kids. The father make $1500 per week. How much money pocket money does the wife and each kid get?

So, let's walk through this example with your code:

//salary input 1500.
salary = (salary/2);  //now salary is 750, half went to house.
salary = (salary *1/3); //now salary is 250. This is how much we are saving.
salary = (salary *1/3); Now salary is 83.3333 Why?
salary = (salary *1/2);  Now salary is 41.67. No, wrong answer.
System.out.println("Pocket money obtain by one parent: " + salary);

Now, lets forget the code, like I suggested, and do the problem.
The whole salary is 1500.
Half goes to the housr, so 750 is left.
One third gets saved, so 750 - 250 = 500 remains to dived as spending money.
At this point we realize that you were not dividing up the problem correctly. The first part of the problem is to determine how much spending money is left for the whole family. We just did that part now and you never did that in your program.
Now, how …

llaspina 19 Light Poster Team Colleague

Since you have not done this type of problem before, start by doing the problem. By that I mean, play the game. Get some black and white chips or poker chips or cards. Line them up and play the game. Or work out examples on paper like you did in your post. Create enoguh examples that you understand the algorithm and you can either solve the puzzle or declare it unsolvable.

Once you can solve the probme by hand, try to converty the algorithm you discovered into code in the language of your choice.

This puzzle may be famous, but I have not heard of it. It looks like a simpler version of the 15 puzzle (which is very famous). You might learn something by researching the 15 puzzle since this seems like a one-dimensional variation.

llaspina 19 Light Poster Team Colleague

This is really not a Java question. It is an algebra question, and we are being asked to represent the answer with Java code.

I recommend we start by forgetting about Java and just try to understand the question. If we can't solve it, how can we teach the computer to solve it?

We are being asked to:

Write a program that allows you to input the salary of a person and the number of children he has and output the pocket money obtained by one of the parents and one child.

To prove toourselves that we really understand the task, let's say we have a family of 5: mother, father, and three kids. The father make $1500 per week. How much money pocket money does the wife and each kid get?
If we can answer that, then try to abstract it:

  • What if the father makes $1600 instead?
  • What if the father makes $1200?
  • What if the father makes x dollars per week? Can we express the answers in terms of x?

Once we are able to express the answer in terms of x, we are close to being able to write a program to do this calculation for us. Of course, the number of children also needs to be a variable.

~s.o.s~ commented: "If we can't solve it, how can we teach the computer to solve it?" - Brilliant +15
llaspina 19 Light Poster Team Colleague

Just to illustrate Hiroshe's point, I received an email from a recruiter looking to hire a developer for an application in the medical field in New York. I also teach programming and wasn't looking to change jobs, but I was curious, so I responded. (I was also wondering why they contacted me since I don't think I enough experience for the job). The recruiter asked me about the languages and technologies I've used and then informed me that they need someone to work with Ruby on Rails. Even though I have never used Ruby, they were willing to bring me in for an interview if I was open to learning it. Not only do I not have a degree in computer science, I don't even have the skill set they are looking for and they still wanted to interview me.

Since I teach computer science and math to high school students, I can relate to the boredom, especially if students are not very interested or motivated. If you can find some projects to do with your best students that will help you develop your own skills and you won't be bored. It may also better prepare you for a transition into the industry.

If I have a strong class, I may be able to have students work together to build something interesting (using techniques or technologies new to me) and if I don't have a strong class, then I still may have one or two talented and motivated students willing …

llaspina 19 Light Poster Team Colleague

One option is to store each row as an element in a list. For instance, say the table stores Pets. Create a Java object called Pet which has data fields matching the columns in the table. This is basic the concept behind ORM (object relational matching).
Then you could do something like this:

ArrayList<Pet> petList = bew ArrayList<>();
while(rs.next() ) {
  int id = rs.getInt(0);
  String name = rs.getString(1);
  String breed = rs.getString(2);
  petList.add(new Pet(id,name,breed) );
}
llaspina 19 Light Poster Team Colleague

You need to store the Staff object as you search for it. An easier way to do this is with an enhanced for loop which uses Iterators for you, but they are hidden.

    Staff displayMe = null;
    boolean found = false;
    for (Staff s : staffList) {
        if(s.getIdNo().equalsIgnoreCase(Search1)) {        
           found  = true;
           displayMe = s;
         }
     }
     //now you have the Staff object you want to display if found.
     //just for testing purposes, start with this:
     System.out.println(displayMe);
llaspina 19 Light Poster Team Colleague

Sorry to hear about your trouble learning Java. Programming should be fun and it can be, but if you fall behind or if a project is assigned that you aren't ready for yet, it gets frustrating. If you like this stuff and get into it, you can learn it well with or without a teacher. The most important thing is to NOT GIVE UP. Be methodical about what you are working on and force yourself to do (and learn) one thing at a time.

Post ALL your code. Add comments before your methods explainine what you want to do. Forget about what you don't understand for a minute and write down what you want to do in plain English as a comment before every method you wrote. Then post everything.
Getting a button to switch tabs only takes a few lines of code.

Which IDE are you using?

llaspina 19 Light Poster Team Colleague

I'm not sure what you are looking for with ANT and the command line. What is your goal? What are you trying to accomplish?

I use ANT for a few minor things, like uploading files via FTP, signing jar files, and copying some files from the build directory to another place for deployment. I put these tasks together with ANT so that afer building my application, I can quickly sign my application and then upload it to the site my customers run it from using JNLP. I never bothered editing build.xml; that's why I use an IDE. So netbeans uses ANT to handle the build process and I use netbeans so I can focus on writing my program. If you want to play with ANT, the Apache reference might be a good place to start.

You can run a java program from the command line with the commmand java [program name] followed by any parameters you want to pass to the main method. Your IDE (Eclipse for you, Netbeans for me) runs this command for you and you can configure any command line parameters in the run properties. Are you trying to create a command line (console application) of some kind?

llaspina 19 Light Poster Team Colleague

I think you need to give us some examples. What do you mean by "background?" Are you creating a GUI swing app? If so, then the assumption to use JPanel (or JFrame) makes sense. But you can create a GUI app with JavaFX if you are being more modern and you could use the java.awt package if you took some book out of the library from 1998.

llaspina 19 Light Poster Team Colleague

I'm not clear on why a database is being used at all. Is there no server component, just different clients for the various players all syncing with the same database?
I would have the clients all communicate with a server (either with TCP if this is running on a LAN or http REST calls or web sockets). The state of the deck could just be kept in RAM by the server and all the latency problems go away.

llaspina 19 Light Poster Team Colleague

Shouldn't the shuffle method take only a few miliseconds to run, if that? Swingworker is for tasks that take so long to execute that they will make the UI unresponsive. So if your shuffle method takes a second or two to run then it should definetly be on another thread. But unless your shuffle method is actually displaying an animation of the cards gettings shuffled or you have some unusual game that is played with a deck of 25,000 cards, I don't see why a shuffle would take so long.

llaspina 19 Light Poster Team Colleague

I'm trying to get better with the new Java 8 Streams API and this seems like a good candidate. Here goes:

 public static void main(String[] args) {
    final ArrayList<Student> studentList = new ArrayList<>();
    try {
       Stream<String> lines = Files.lines(Paths.get("studentTest.txt"));
       lines.forEach((String t) -> {
          String[] parse = t.split(":");
          if(parse.length<2) return;
          studentList.add(new Student(parse[0], parse[1]));
       });
    } catch (IOException ex) {
       System.out.println("Unable to open student file." + ex.toString());
    }
    System.out.println(studentList);
 }

Less code and more readable. The text file I used is this:
John Smith:78231
Joe DeStudent:78332
Alice DatGirl:67323
Karen Kenderson:45444

llaspina 19 Light Poster Team Colleague

As part of a First Robotics project (FRC) I placed a live video feed from a web cam mounted to a servo inside of a swing application (without recording the video). This was done using the SmartDashboard. It's all open source, so you might be able to grab the code and find what you need.

I have never done video capture, but it's supported in JavaFX 8; you can watch a video here. Jump to minute 39 to see video capture.

For learning JavaFX, I found the Oracle tutorials helpful.
I also read a few chapter of Pro Java FX 2, which I managed to get my local library to purchase.

jalpesh_007 commented: nice answer. +4
llaspina 19 Light Poster Team Colleague

If this is from a summer college class, then the problem may be that the material was presented more quickly than it could be learned. I have found that CS instruction is very poor at some colleges and this project makes me curious: What was the actual assignment? Was this the first assignment?

There are three simple steps to follow when you are building something:
1. Decide what you want to build.
2. Build it.
3. Now make sure you built it correctly. (test it to verify that it meets the requirements)

People often ignore step 1 or 3. Whether building software for a client or completing a school assignment, the first step is to understand EXACTLY what you need to create. Maybe all that is required is just a mock SMS donation system that demonstrates the concept of moving virtual money from one virtual phone number to some virtual charity. That would not be an impossible project after a semester of work.

llaspina 19 Light Poster Team Colleague

My house also has aluminuwm siding, but not everywhere. Moving the range extender to an exterior wall that has vinyl siding made a difference. It's not great, but it's better.

The device has no visible antenna. Can I just add a high gain antenna to is somehow?

llaspina 19 Light Poster Team Colleague

I purchased a Linksys N600 PRO Wi-Fi Range Extender because I would like to be able to work in my backyard. The product claims to expand coverage up to 7500 square feet which I take to mean a radius of around 85 ft. Maybe I should expect less because outside walls decrease the signal. But I did not expect to have the signal vary so much and for my laptop to frequently lose the connection. The setup software tests the signal strength where the extender is plugged in, so I am sure it is close enough to my wireless router. Working on my deck, a mere 30 feet from the range extender and less than 60 ft. from the router, the signal sometimes gets lost. Note that I'm not complaining about the speed. When I have a connection, the speed is fine. It's just furstrating to frequently have NO connection.

Should I return this and purchase a different product? Are the range extenders with visible antennas better?

llaspina 19 Light Poster Team Colleague

stultuske: Thanks for filling in the missing acronym: jsapi.
That was really my issue with the LetMeGoogleThatForYou answer. A google search and the jar finder didn't quickly lead me to the required library. I haven't played with the Java Speech API, but it looks interesting and the Oracle link you posted shows just how long this has been around.

llaspina 19 Light Poster Team Colleague

The snarky comment listed as the first reply wasn't justified. This jar was not that easy to find. Looking through maven I tracked it down:
http://search.maven.org/#search%7Cga%7C1%7Cfc%3Ajavax.speech

From the above link you can download freets-1.2.2.jar, and the docs are here:
http://freetts.sourceforge.net/javadoc/index.html

Looking through the jar, I did find a few classes in the javax.speech package. These are no documented in the source forge docs, but they are included in the download. (You can also download javadocs from the maven central repository.

llaspina 19 Light Poster Team Colleague

I'm not sure what level we are looking for, but the MAA publishes books covering the USAMO which has the same format as the IMO (with easier questions). The first couple of problems on the Putnam exam (the ultamite college exam for math enthusiasts) are easier than (high school) Olympiads. I used them to help prepare a student of mine a few years ago.
You can also get problems on-line here: http://www.maa.org/programs/maa-awards/putnam-competition-individual-and-team-winners

The Putnam book Kiran Kedlaya is much better than just having the questions because he includes explanations and comments on the problems.

If you search Amazon for IMO problems you will see more resources than you could possibly work through.

For programming contests, I am currently working on a high school level workbook using problems from the Long Island HS Programming Contest, held at St. Joseph's College every year. The platform most students use at this contest is Java (with Eclipse, but netbeans is what my students use). Some students code in VB and C++ is also allowed.

A professor at Stony Brook University wrote Programming Challenges, a book focusing on the ACM sponsored college level programming contest ICPC. USB does much better at these regional contests than any other school on Long Island and they even finished ahead of Cornell and NYU in recent years.

llaspina 19 Light Poster Team Colleague

I feel like this is a very old way of doing things. If you can, I would move the form fields into the Applet or (better) a JNLP application.
But if you want to get your JavaScript talking to your applet, look here:
http://docs.oracle.com/javase/tutorial/deployment/applet/invokingAppletMethodsFromJavaScript.html

llaspina 19 Light Poster Team Colleague
llaspina 19 Light Poster Team Colleague

Pom.xml defines the project dependencies. If you are just a beginner to java, then you have a TON of functionality to play with from the core libraries that come with the core JDK. Your IDE downloads whatever additional jar files your project needs by reading the pom file.

llaspina 19 Light Poster Team Colleague

THe suggestion to disable Java in the browser and better yet uninstall it is just silly. When security holes are disovered in Windows, do we suggest that all users uninstall Windows? Java powers a large number of businesses and many users need Java installed to get their work done. Although Java is not very popular in the browser, when it is used in modern web apps there is often no way of using the application without using the Java applet. For instance, two of the most popular gradebook / Student management systems run over java applets or JWS. Most high schools on Long Island use one of these systems, so the suggestion to uninstall Java is certainly not being followed in schools.

Hopefully any remaining vulnerabilities will be fixed very soon, but we may have to wait until February for a more complete solution fom Oracle.

Does anyone know of an actual exploitation (virus, DDOS attack, stealing confidential data) being executed? Or is it just proof-of-concept code that was run?