User Profile

Collapse

Profile Sidebar

Collapse
cordeo
cordeo
Joined: Jul 22 '08
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • cordeo
    replied to I'm new, basic conversion question
    in Java
    Suggestion a) is nice. Concerning regular expressions, they might not be very suitable for the original poster (who was not even familiar with parseInt). Let's not make it too difficult for some who is new to Java.



    017 as octal number and 0x1a as hexadecimal number are valid when directly written in Java. For example, a ==b, a == c and b == c after these 3 lines of code:
    Code:
        int a = 017;
        int b = 0xf;
    ...
    See more | Go to post

    Leave a comment:


  • cordeo
    replied to I'm new, basic conversion question
    in Java
    I fully agree. That is what I posted originally, and also why I noticed a problem in the approach of BSCode266.

    On the other hand, I think it is useful to understand that Integer.parseIn t() uses the Character class internally anyway....
    See more | Go to post

    Leave a comment:


  • cordeo
    replied to I'm new, basic conversion question
    in Java
    This sounds quite strange. I'm afraid I don't understand you. BSCode266 suggests possible extra constraints, but keeps this line (from my original code example):

    Integer.parseIn t() will never accept anything that does not fit an Integer, and absolutely performs the required check. I really don't understand why you think my approach doesn't check that. Try it yourself: your input string "99999999999999 9999999" will be refused...
    See more | Go to post

    Leave a comment:


  • cordeo
    replied to I'm new, basic conversion question
    in Java
    The approach does work, but integer is (of course) limited to at most Integer.MAX_VAL UE. If you need support for larger numbers, use Long (Long (Java Platform SE 6)) or even BigInteger (BigInteger (Java Platform SE 6)).

    Long is also limited, but can hold larger numbers than integer. BigInteger is not limited at all, but needs more memory.

    The class Long has a parseLong method. BigInteger has no such method, but you can use...
    See more | Go to post

    Leave a comment:


  • cordeo
    replied to synchronization trouble
    in Java
    try{ this.wait();}ca tch (Exception e){}

    First off all: NEVER ignore exceptions, try writing
    try{ this.wait();}ca tch (Exception e){ e.printStackTra ce(); }

    and look what is happening.
    See more | Go to post

    Leave a comment:


  • cordeo
    replied to I'm new, basic conversion question
    in Java
    There is no need for conversion back to String and doing a comparison with compareTo. An elegant solution is like this:
    Code:
            // Loop through all the command line arguments
            for (int i = 0; i < args.length; i++) {
                // Get the command line parameter as a String
                String potentialNumber = args[i];
                
                // Stores the parsed command line argument
    ...
    See more | Go to post
    Last edited by cordeo; Jan 26 '09, 10:23 AM. Reason: Wrong rendering of code

    Leave a comment:


  • cordeo
    replied to I'm new, basic conversion question
    in Java
    Have a look at Java 2 Platform SE v1.3.1: Class Integer)

    and catch the NumberFormatExc eption which will by thrown if the string does not contain a parsable integer.
    See more | Go to post

    Leave a comment:


  • cordeo
    replied to A TRUE friend should pls help
    in Java
    Send e-mail from a form
    See more | Go to post

    Leave a comment:


  • cordeo
    replied to Unicode problem
    in Java
    HTML text boxes? Java Swing textboxes?
    See more | Go to post

    Leave a comment:


  • cordeo
    replied to triggering multiple actions on hyperlink click
    in Java
    Suggestion 1: Use javascript to issue a refresh for every frame
    See more | Go to post

    Leave a comment:


  • cordeo
    replied to Error while Decrypting the String
    in Java
    You feed the original string into the decoder, not the encoded string:
    Code:
                byte[] dec = decoder.decodeBuffer("Arjunan");
    That should of course be:

    Code:
                byte[] dec = decoder.decodeBuffer(encoded);
    which solves your problem immediately.
    See more | Go to post

    Leave a comment:


  • cordeo
    replied to Java Change Page - Please Help Needed
    in Java
    In order for us to answer your question, some more information about your applet is needed. Can you post some code (about 10 lines) that is relevant to your problem. How did you implement your 'pages'?
    See more | Go to post

    Leave a comment:


  • cordeo
    replied to Java DES
    in Java
    as a second rule,
    2. Catch specific exceptions
    By catching (java.lang.)Exc eption, you also catch things like IndexOutOfBound sException, NegativeArraySi zeException, NoSuchElementEx ception, IOException and others that have nothing to do (at least, not directly) with the code in the try-block. Especially in the case of an empty catch-block, lots of problems that are neatly reported by java are silently ignored, causing

    ...
    See more | Go to post

    Leave a comment:


  • cordeo
    replied to Java DES
    in Java
    I don't have time to put up a full answer at this very moment but as a programming rule: NEVER ignore exceptions by using an empty catch-block.

    It's an often seen beginners mistake, but problems that otherwise would be reported might silently disappear, which is undesired of course. So write:
    Code:
    catch (Exception e) { e.printStackTrace(); }
    and have a look at your console. Not being sure whether this is enhough...
    See more | Go to post

    Leave a comment:


  • cordeo
    replied to Lucene search example
    in Java
    That's a nice analysis of the problems, but not very helpful to a beginner. The real answer:
    Your lucene jar library is newer than the one InMemoryExample was written for. Lucene changed its API. InMemoryExample is based on an older version of the API of Lucene. Changes:
    1. doc.add(Field.U nIndexed("title ", title));
    New code:
    doc.add(new Field("title", title, Field.Store.COM PRESS, Field.Index.NO) );...
    See more | Go to post
    Last edited by cordeo; Jul 22 '08, 07:31 PM. Reason: More backgrounds

    Leave a comment:

No activity results to display
Show More
Working...