Christian Kindler

Greenhorn
+ Follow
since Apr 16, 2009
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Christian Kindler

As Matthew already said above, a Date object has no format. The toString() does some formatted output for you, but it will be always the same. If you want to have your Date as a String in certain format, you have to use a DateFormat again.
12 years ago
There is a known bug in TimeZone.inDaylightTime(), see Bug ID 6609359.
Instead of doing a lot of formatting/parsing you should use a Calendar when converting or calculating date/time. There are some examples which can be found with google, e.g. this one.
12 years ago
If you want a shopping card after checkout, keep the old one. Do not use @Remove, just make sure that your shopping card is empty after checkout. The example from the tutorial simply shows you that there is a @Remove annotation and how it is/can be used. But it might not be the best solution for the functional problem.

Regarding your technical question

Is there a way to get a new instance of ShoppingCart injected via a standardized way (dependency injection)?



I would be surprised if there is one and how it would fit in the lifecycle.

Roel De Nijs wrote:But I'm sure you'll be a SCJD very soon.



Hope dies last.

I submitted my assignment on May the 20th and I am still waiting...

mark goking wrote:did you try calling the jTable.setRowSorter() in the table header's event method when it is clicked?



The problem with installing/removing the row sorter as needed is, that the table will restore the unsorted state when the RowSorter is removed.
15 years ago
Hi there,

I want to use JTable's standard sorting mechanism with TableRowSorter which works fine. But I want to have the control about when sorting is done. Sorting is triggered by JTable if the TableModel what is not what I want. I want to occur sorting only if the user clicks on the table header and by explicitly calling the sort method. Is there any way to achieve this?

Regards,
Christian
15 years ago
Hello,

working with JDesktopPane/JInternalFrame, I want to show a simple information message in a modal(!) dialog. According to the docs, this should be done with JOptionPane.showInternalMessageDialog(). This works fine, but as the window icon (the icon for window decoration in the upper left corner of the dialog) the typical Java coffee cup is displayed instead of my frame icon.
I could implement the message dialog as a JInternalFrame and customize the icon, but this dialog wouldn't be modal. So is there any smart possibility to have the frame icon (or a icon of my choice) as the JOptionPane message dialogs window icon?

Regards,
Christian
15 years ago

K. Tsang wrote:No title for server because no GUI.



I agree with you that for a server application a GUI might be a ad idea. But:

  • you are not allowed to use command line arguments other than the single mode flag
  • you are not allowed to use command line property specifications
  • all configuration must be done via a GUI
  • no manual editing of any files


  • So how do you specify the port and the location of the database file when running in server mode?
    I think there are more important things to bother about than static imports.
    Ask yourself: what is the benefit of using static imports? I think in most cases, the code gets less readable, so it should be obvious which class is used with static imports. For instance in unit tests everyone would know that org.junit.Assert.assertTrue() is used when assertTrue() appears in the code, so it's ok here.
    A helpful thing when having deadlocks is: calling "kill -3 PID" on the command line, where "PID" is the process id of your java process. This will give you a detailed dump where you can see at which point your code is waiting for acquiring a lock. This works on unix systems, I don't know if you have a similar possibility on windows.

    Roel De Nijs wrote:Hi Patrick,
    I also used the singleton pattern and had just 1 getInstance() method without any parameters. I can hear you think: "but how did you pass the database location" Well I extended the sun interface and added a method to initialize my Data-class and that method had the parameter with the database location. This init-method must be called first, so before any other call to the Data instance was made. If you called the read-method (or any other method) before the init-method, you got an IllegalStateException.



    I also use the singleton pattern and a init method. But I am not sure what to do if the init method is called more than once.

  • ignore further calls to the init method after the data class instance is initialized, or
  • throw an IllegalStateException if the init method is called and the data class instance is already initialized, or
  • throw an IllegalStateException if the init method is called and the data class instance is already initialized and if the given parameter is different from the parameter used to initialize the singleton

  • If you allow multiple threads to access our data class simultaneously (for read operations, using ReadWriteLock), there is one important thing to know: RandomAccessFile.length() is NOT thread safe. So if you use RandomAccessFile.length() (e.g. to make sure not to read beyond EOF), use it within a synchronized block with the RandomAccessFile object as mutex (like you would do with calls to seek/read methods).

    I made some tests with multiple threads and had java.io.EOFExceptions thrown from RandomAccessFile's read methods and it took me a while to find out that unsynchronized calls to RandomAccessFile.length() was the reason.

    See also: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4823133
    The following code is from Bates, Bert and Kathy Sierra. "SCJP SunĀ® Certified Programmer for JavaTM 6 Study Guide" (Master Exam):



    Because there is no no-arg (default) constructor I would assume that the compiler would complain something like this:

    Numbers.java:13: cannot find symbol
    symbol : constructor Numbers()
    location: class Numbers
    Numbers negatives = new Numbers();
    ^
    1 error


    But the code compiles without errors and the output is -3 -1 5! Apparently the var-arg constructor matches the call with no args. The same with methods: a method go(int... x) will be executed when calling go() and there is no method go() without parameters.

    Maybe this is obvious to others (to me it was not), but it might be a good idea to to include a hint on that behaviour in exam preparation books...

    I really start to hate var-args...
    Hi there,

    the following code will not compile:


    Test.java:12: reference to go is ambiguous, both method go(int...) in Test and method go(java.lang.Integer...) in Test match
    go(7);
    ^
    Test.java:13: reference to go is ambiguous, both method go(int...) in Test and method go(java.lang.Integer...) in Test match
    go(new Integer(7));
    ^
    2 errors


    Question 1: is there any possibility to get a call to one of the go() methods compiled?
    Question 2: if the answer to question 1 is "no", why does the compiler complains about accessing the methods an not about defining the to go() methods?