JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, it's not easy to se the inherited members in particular. It would be great to have an (optional) mode in which all the available methods were listed (with parameters etc) together in one alphabetic listing.
Stick with it... working with the API JavaDoc is an essential Java skill, and it does get easier with practice.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Did you read my previous post???
An exception can only be thrown at run time.
There is no such thing as a "compile time exception".
Where did you read about "compile time exceptions"?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

No, they are package access by default, justlike ordinary methods.

The error message refers to a constructor with a long parameter, but the only constructor takes an int.

Creation or modification of Swing components should normally be done on the Swing thread. Sleeping during a constructor while changing a swing component's visibility, all on the main thread is asking for trouble...

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

In the API doc look for adddXXXListener methods. Don't forget to check all the methods in the "Methods inherited from class XXX" sections.

eg
JButton has no such methods of it own, but it inherits

addActionListener, addChangeListener, addItemListener from AbstractButton,

addAncestorListener, addVetoableChangeListener from JComponent,

addContainerListener, addPropertyChangeListener from Container,

addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener from Component

.. so that's the definitive list of all the listeners youcan add to a JButton.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

There's no such thing as a "compile time exception" in Java. There is no instance of that term anywhere in the Java language Specification. The compiler will check that your code handles "checked" exceptions, but all Exceptions are thrown at run time.
Maybe you are reading something written by someone who does not know correct Java terminology.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You cannot create an onbect of an abstarct class.
The code I showed you earlier prints the actual class of the "g" parameter that was passed to you. In my case that was sun.java2d.SunGraphics2D which is a concrete class that extends Graphics2D (did you look at the source code thatI linked to?)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

pd.getReadMethod() gives you a Method object that represents a "get" method for the Bean. You can call the Method object's invoke method to execute the "get" method it represents and return the result

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You can print the actual class of the Graphics parameter inside your paint method, eg

System.out.println(g.getClass());

and you will see something like (using a JFrame under Windows) "class sun.java2d.SunGraphics2D", which extends Graphics2D
http://www.docjar.com/html/api/sun/java2d/SunGraphics2D.java.html

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, you're right, It's really a subclass of Graphics2D

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The actual parameter that is passed to your paint method will be an instance of Graphics2D - which is a concrete subclass of Graphics.

ps: If you previous posts have been answered then please mark them "solved"

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
class Location {

    double longitude, latitude;

    public Location(double longitude, double latitude) {
        this.longitude = longitude;
        this.latitude = latitude;
    }

    @Override
    public String toString() {
        return longitude + " " + latitude;
    }
}

class City {

    String name;
    Location location;

    public City(String name, Location location) {
        this.name = name;
        this.location = location;
    }

    public Location getLocation() {
        return location;
    }

}

class Tester {

    public static void main(String[] args) {
        City london = new City("London", new Location(48.3, 0.0));
        System.out.println(london.getLocation());
    }

}
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

When the compiler is compiling the Component class, its source code will have an import java.awt.Color; or somesuch as part of its definition. That tells the compiler that Component class needs to use the Color class, and the compiler generates all the necessary code.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes indeed. In fact the complete inheritance tree for JApplet is

    java.lang.Object
        java.awt.Component
            java.awt.Container
                java.awt.Panel
                    java.applet.Applet
                        javax.swing.JApplet

... and so JApplet inhertits methods from all those classes

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Remember also that your class extends JApplet, and you inherit all JApplet's methods and can call them directly.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yet another good example of why not to use a null layout manager!
Swing doesn't know how big the panel is because there's no layout manager to set it. If you use setPreferredSize to give the panel a size bigger than the scroll pane's viewport, the scroll buttons will appear.

kishor.m.n commented: thanks a lot ..its working fine.. +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I can't see anything in the bytecode that would explain a speed difference, and caching at the RAM level isn't going to be relevant, so maybe this is a low-level hardware thing - pipelining and branch prediction at the CPU level maybe???

If you refactor that into a runnable program that produces a simple output automatically then I'm sure a few people here will run it for you and you can consolidate the results.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You can't tokenise an mmddyyyy string by using "/" as a delimiter, becuase the string doesn't contain any "/" characters!
Because the format is fixed, you can simply use String's substring method to pick out each of the three parts, then parse each of those into int values.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It's available from amazon.com at about half price (USD20).

Personally I would avoid books, which are always out of date, and go with online materials.
Oracle's "official" Java tutorials are excellent - not easy, but comprehensive and authoritative, and free. http://docs.oracle.com/javase/tutorial/uiswing/index.html

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You declare the parameter(s) of a constructor just like an ordinary method eg

public CheckDate(String mmddyyyyString) { ...

then call them passing parameters also like an ordinary method, eg

CheckDate cd = new CheckDate(input.nextLine));
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Your set method looks great.
Because you have declared the constructor as "throws InvalidHoursWorkedException" you don't need to try/catch it in the constructor. Just call the set method and if that throws the exception then your constructor will automatically pass that on to whoever called the constructor.

You didn't post the code that used the ssn, so I can't comment on that.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

In your set you just need to check the hours and throw an exception if they are invalid. Your exception class has a constructor that includes the ssn, so just call that (using the ssn variable that you already have) to create an exception object to throw.

If you call that set method from your constructor you must either (a) try/catch the exception or (b) declare your constructor as throws the exception and let Java pass the exception on to whoever called your constructor. Option (b) makes more sense here.

Finally - you will have some code somewhere that calls your constructor or your set method. That's where you need to use try/catch so you can catch the exception and issue a suitable error message to the user.

[remember that the HourlyEmployee class may be called from a command line app, a GUI, a web server, a database app... so it has no idea of how to tell the user about an error. All it can do is create an exception and throw that up to the GUI or web server or whatever where it knows how to tell the user]

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Normally the throws and the try/catch are in different methods as in

void method1() throws Exception {
  ...
  if (...) 
     // there's a problem that I can't fix...
     throw new Exception ("Sorry, it's gone wrong");
  }
  ...
}

void method2() {
  ...
  try {
     method1();
  catch(Exception e) {
     // I tried to use method1, but it's gome wrong
     display some kind of error message
  }
  ...
}
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Ahhh - the old BigInteger trick. What you have found is an over-complicated version. The simplest form is just one short line...

You can use the simpler version of getBytes without any arguments - that just uses the default char set. If you stick to ASCII characters you'll be OK.

Then you can use BigInteger's toString(int radix) method with a radix of 16 to get a hex string, no need for any other formatting.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If you were virus infested then it probably did a lot more than make just one registry entry. It's time to use a proper virus removal program (or programs) to do a complete job.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Oh yeah, Dani's new thread editor tries to be smart about special characters. It makes sense to her, but drives me mad too.
In that case just getting rid of the "REG" should help.
Capturing/echoing the output from the process will help diagnose problems, if you're not already doing that.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Java String literals treat a back-slash as an escape character. If you want a literal back-slash you need to code two, as in

"HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\Test"

plus "REG" is just the short form of "reg.exe" from the help file, so you should delete it and just keep the "reg.exe"

See how that goes

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I have applications running every day that use it.
What exactly did you try, and in what way did it fail exactly?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Java has no direct support for the Windows registry, but it's easy enough to use ProcessBuilder to execute the Windows reg.exe command-line utility to perform registry queries or updates.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Every case finishes with a return, so the extra return false will only be executed if none of the cases is true.
Sometimes this happens with the Java compiler. You know that every possible data will lead to one of your retunrs, but the compiler spots a theoretical possibility that it might not, so you have add an extra return to keep it happy.

Have you tried executing it yet? running test cases will tell you everything you need to know.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The code looks neat, but I don't know what it's supposed to do, so I can'y comment on its efficiency or correctness. If it gives the right answers then it's almost certainly pretty good!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

"Unreachable code"

You need to remove the breaks that come after a return, because executing the return means that the break that follows it can never be reached.

"This method must return a result of type boolean".

You also need to ensure that your code will return a boolean no matter what happens in the switch, including the situation where none of the cases is true.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

No, the break is optional in a switch statement. It's often omitted in code like

switch (something) {
  case 1: 
  case 2:
  case 3:  do something for cases 1, 2 and 3
  etc
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, that's your choice.
Personally I would question why anyone would spend time struggling to master the syntax of anonymous inner classes when they just became obsolete (unless they are working in an environment where Java 8 isn't allowed yet, or breaks existing applications), but hey ho.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Sorry, but yes, the answer is in the API doc!
Just look for the addXxxListener methods (being alphbetical, they're conveniently near the beginnning of the summary list). Dopn't forget to look at the methods inherited from superclasse as well.

Here's a great tutorial
http://docs.oracle.com/javase/tutorial/uiswing/events/
and this page includes a table of whuch events go with which common classes
http://docs.oracle.com/javase/tutorial/uiswing/events/eventsandcomponents.html

Ps with Java 8 lambdas allow you to define a listener in a single concise expression http://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html#lambda-expressions-in-gui-applications

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, static methods are no more thread safe than instance methods - ie not at all unless you synchronise them yourself.
I think the question of modifying the parameters may come down to whether this is a "real" object class (Employee. Bicycle etc), in which case an static method that modified any instance's data could be very "unexpected", or if it's a "service" class like Arrays or Collections which are just a holding area for static methods that definitely do modify their parameters, eg Arrays.sort(someArray).

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The pattern here is a recursive method with a number of obscure parameters that are involved in controlling and tracking the recursion. In order to make it easier to use, there's a simpler public version without all the extra parameters, that simply calls the recursive method with a suitable set of initial parameters.

Note that there's nothing intrinsically static or non-static about that pattern, it just comes down to whether the methods need access to any instance members of the class.

match(int[] a, int[] pattern, i, j )
does not seem to use any instance members, so there's no reason for it to be an instance method. Indeed, there's a strong logical argument that says such a method should be static.
Just declare it static.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I have no expertise in Hibernate, so I can't answer your latest question, other than to suggest using a List, which will definitely be ordered.

guideseeq commented: This is correct post, problem is something with Hibernate PersistentSet but behavior of another member "jwenting" is cheap, unprofessional a very lowly thoughts as well! +3
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The Java Language Specification does have "virtual methods" or "virtual functions" These are jargon from another language. If you have a question about C++ this is the wrong forum.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

option #2 is perfectly OK for this purpose.
option #1 will also work, but makes it less clear that insertion order is important.

No matter how you declare or refer to it, a new LinkedHashSet() will always be in insertion order and without duplicates - that's guaranteed by the API doc.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The Java Language Specification does not have "virtual methods" or "virtual functions" These are jargon from another language. If you have a question about C++ this is the wrong forum.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

No. The order is determined by the precise type of Set that you create, not by how you declare the variable that refers to it.
If you don't want to use Lists, and the order MUST be the insertion order then #2 is appropriate - the class will maintain the insertion order, and the type of the variable will confirm that that's what you intended.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

In the first case all you are asserting about linksSet is that it is a Set. Anyone using linksSet will only be able to use Set's methods. Maybe later you will want to change the implemention eg to a TreeSet for some reason. By defining things that way you can change the implementation without breaking any code that uses linksSet.
(Having said that, in this particular example there aren't significant extra methods in LinkedHashSet that are not in Set. However the general principle applies that you should declare your variables in the least implementation-dependant way you can, to allow for future cdhanges.)

Actually...
If you want to hold a number of items and access them according to their order of insertion maybe you should look at one of the List classes, eg LinkedList or ArrayList

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, if only one is null it will throw an NPE, so it's not the same.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

What do you see when you print rss.getString(2) ?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

rss.getString(1)
Second column of my table is a type of varchar(10)

For some perverse reason the ResultSet get methods use indexes that are 1-based, not 0-based, so getString(1) retrieves from the first column not the second.

String s=resultSet.GetString(1)
System.out.println(resultSet.GetString(1))

The difference here is that println does an implicit toString() on whatever its parameters are, ie it's really
System.out.println(resultSet.GetString(1).toString())
whereas the simple assignment to a String variable does no such conversion

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Thats because the code that sends the result is in an if test that's only true for the second input.

I would keep references to both ClientThreads somewhere in the game, and have a public "send" method in the ClientThread class so the game can send messages to any/all clients whenever it wants. You need to break away from the "receive a line/send a line loop" thinking and allow asynchronous input and output, after all, this is all about Threads...

(edit - addedum):
This code is getting very messy because it doen't use any of Java's O.O. capabilities (except where absolutely necessary). You should be thinking about the objects in the application, and starting to partition the functionality into them. The idea is to get a number of small classes, each of which does it's own thing without worrying about the internals of any other class. The only thing that matters is the public interface for each class.
By way of illustration here's one way to approach a very first pass at this...

class Server {
   // listens for incoming connections, creates RemotePlayers
   // could also do DNS stuff to make itself discoverable
}

interface Player {
   // could be local (console or GUI), remote or computer
   // takes input from user and calls game.move(...)
   public void send(String s); // sends message to user
}
class LocalConsolePlayer implements Player {
   // (already got the code for console handling)
}    
class RemotePlayer implements Player {
   // a user …
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

No, it's more like (just a sketch)

 while(true){
    Socket clientSocket = serverSocket.accept();
    new ClientThread(clientSocket).start();
 }



 class ClientThread extends Thread {

    ClientThread(Socket clientSocket) {etc

    p v run() {
      PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
      BufferedReader in = new BufferedReader(new             InputStreamReader(clientSocket.getInputStream()));
      System.out.println("waiting");
      input = in.readLine();
      etc
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

After your serverSocket.accept(); you need to start a new thread to handle that connection (pass the Socket object to the construtor of your new thread). Then in that new thread open the input & output streams etc. You main thread then loops back to the accept and waits for user2 to connect. When user2 connects you start another new thread as above. Now you have two threads. each handling the I/O from one user. Synchronising them to play the game is where this gets interesting...

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

What exactly are the error messages?