~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I actually meant if there were any more such services that google offers (like ICO to other formats apart from PNG). I mean this is some kind of service that's not well publicized (doesn't show up on google). Where should one look for such services of google ?

Unfortunately I don't have an answer for that; I guess it's one of those "oooh, cool stuff" things.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Daniweb has been experiencing some performance related problems lately. I'm sure Dani and Blud are working on smoothing things out so please bear with us till this issue gets resolved. Updates on the same would be posted here.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I don't think there is any need for a documentation nor one exists I guess. You simply need to dynamically create a URL based on your requirement with a URL template like "http://www.google.com/s2/favicons?domain=" + yourDomain and read by the connection opened. Anyways, since I've a bit of free time, I've written a throw-away code which works; feel free to modify it as you see fit.

package pkg;

public class IcoConverterTest {

    public static void main(final String[] args) {
        if(args == null || args.length < 2) {
            System.out.println("pkg.IcoConverterTest <domain> <outdir> <optional-file-name>");
            return;
        }
        final String domain = args[0].trim();
        final String outdir = args[1].trim();
        final String fileName = args.length > 2 ? args[2].trim() : "favicon.png";
        new IcoConverter().convertFor(domain, outdir, fileName);
    }

}

class IcoConverter {

    public static final String CONVERTER_SERVICE = "http://www.google.com/s2/favicons?domain={0}";

    public void convertFor(final String domain, final String outdir, final String filename) {
        InputStream is = null;
        OutputStream os = null;
        try {
            try {
                final byte[] buf = new byte[4 * 1024]; // 4kB
                is = new URL(MessageFormat.format(CONVERTER_SERVICE, domain)).openStream();
                os = new FileOutputStream(new File(new File(outdir), filename));
                int size = -1;
                while((size = is.read(buf)) != -1) {
                    os.write(buf, 0, size);
                }
            } finally {
                if(is != null)  is.close();
                if(os != null)  os.close();
            }
        } catch(Exception e) {
            throw new RuntimeException("ICO to PNG conversion failed!", e);
        }
    }

}

There are a couple of gotachs when using this service, you can read about them in this discussion.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Would you be using favicons from existing domains or favicons stored locally? If you would be using existing favicons, use the google ICO to PNG converter. http://www.google.com/s2/favicons?domain=daniweb.com

If you want to convert local files, you would have to find some online service like the one you mentioned. Unless the site exposes a programmatic public API, directly using the service might be a bit of pain in the neck along with other implications like taking prior permission of the site owner.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

The extension suggests that it also is an ico image

Codecs don't work based on extensions, I can very well have a PNG with extension WTH and it would open up just fine in applications which support PNG.

Anyways, I personally don't know of any converters but you can try picking up ideas from this thread.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Go here and click download. On the next page, select the platform as "Windows" and click continue. Click on the download link presented on the next page.

Also have a look at the sticky at the top of this forum.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

The problem is in your assumption that a favicon for a site is always a PNG image, which isn't the case. Normally sites use a ICO image format, which is a different image format than PNG or BMP. Read more here.

To confirm this, try downloading the Daniweb favicon and setting it up in Qt Jambi, it should work (assuming Jambi supports BMP). The same shouldn't work with Yahoo, Microsoft or any other sites' favicon.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

It isn't a feature which is exclusive to Eclipse though if you are programming in Eclipse, that solution would make the most sense. Other standalone solutions like One-jar exist (complementary article). IMO, it is *the* solution to follow if running your application currently involves hunting down jar files.

I'd like to ask too, I have added a program to my sendTo folder (vista) so I can right click a .zip or any file and send it to this program "md5sums"

I don't see how this relates to your original query? Anyways, in simple terms, a MD5 checksum is a unique (well, almost) sequence of characters generated based on the file contents and is mainly used for verifying file integrity. E.g. you are trying to download a file from "teh" internet which also advertises a MD5 checksum. After the file download has complete, you can run a MD5 computation utility of the same file and check whether the advertised MD5 checksum is the same as the checksum computed for your local file. If it isn't, something wrong happened during the transit. For more technical details, refer the Wikipedia article for more details.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Yes, something along those lines. For e.g. a enum like:

enum Suit {

    HEART(1) {
        @Override
        public void doIt() {
            System.out.println("I'm a HEART");
        }
    },
    SPADE(2) {
        @Override
        public void doIt() {
            System.out.println("I'm a SPADE");
        }
    },
    CLUB(3) {
        @Override
        public void doIt() {
            System.out.println("I'm a CLUB");
        }
    },
    DIAMOND(4);


    private Suit(int i) {
        this.i = i;
    }

    private final int i;
    
    public void doIt() {
        System.out.println("HI");
    }

}

would be translated to something along the lines of:

class SuitClass {

    public static final SuitClass HEART;
    
    public static final SuitClass SPADE;

    public static final SuitClass CLUB;

    public static final SuitClass DIAMOND;

    private String enumName;

    private int pos;

    private int i;

    static {
        HEART = new SuitClass("HEART", 0, 1) {
            public void doIt() {
                System.out.println("I'm a HEART");
            }
        };
        SPADE = new SuitClass("SPADE", 1, 2) {
            public void doIt() {
                System.out.println("I'm a SPADE");
            }
        };
        CLUB = new SuitClass("CLUB", 2, 3) {
            public void doIt() {
                System.out.println("I'm a SPADE");
            }
        };
        DIAMOND = new SuitClass("DIAMOND", 3, 4);

    }

    private SuitClass(String enumName, int pos, int j) {
        this.enumName = enumName; // teh enum name
        this.pos = pos; // the enum position
        this.i = i; // the instance variable of enum
    }

    public void doIt() {
        System.out.println("HI");
    }

}
NewOrder commented: well understood. thank you +0
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

if they are not classes, how are they generated, where are they kept inside the memory?

Enums get special treatment by the compiler and impose additional restrictions not imposed by regular classes, specifically not having the ability to extend any class since they are automatically made to extend the Enum class. But after compilation, there is no such thing as an "enum", its classes all the way.

Regarding methods; every time you declare an enum constant having class body, a corresponding anonymous inner class is created which extends the enclosing enum class. So for e.g. with the following piece code:

enum Suit {
  HEART {
    public void doIt() {}
  },
  SPADE {
    public void doIt() {}
  };
  public abstract doIt();
}

the classes created would be Suit.class, Suit$1.class and Suit$2.class where the latter two classes extend the Suit class.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

That sounds like a pretty non-trivial task. Look into the jMonkey Engine (jME) which is a 3d game engine and might do everything you need and more.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

After setting the environment variables ensure that they are properly set by checking the same using echo %yourvar% .

You need to run the setEmbeddedCP.bat file *after* setting DERBY_HOME. SOmething like:

c:\> set DERBY_HOME=c:\path\to\derby\home
c:\>setEmbeddedCP.bat

Alternatively, you can set the environment variable in your global environment settings rather than setting it for every session. Right click My Computer -> Properties -> Advanced -> Environment Variables.

IMO better set the classpath when spawning your JVM process rather than messing with the CLASSPATH variable.

java -cp .;c:\derby\somejar;c:\derby\anotherjar

If this is a standalone application, consider better means of packaging rather than relying on environment variables and relative paths of jars. Eclipse provides a way of exporting a runnable JAR which flattens all the dependent JARs along with your class files in a single-standalone jar.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Use code tags when posting code; rad the forum announcements for more details.

Regarding your issue; open the file in append mode. Use the constructor of FileWriter which accepts a boolean parameter for the same. But keep in mind that default/platform encoding is assumed when writing files.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Use the Scanner class for the same. I think this tutorial does a fair job of explaining the same.

NewOrder commented: thanks s.o.s +0
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Subscribe to a forum/thread and when adding the subscription select the "no email notification" mode. This would ensure that the threads which you are watching show up in your control panel plus you won't get any emails for the same.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

You can use relative paths. An HTML element like <img src="/app/images/first.jpg" /> would render an image with the image URL being: http://yourhost/app/images/first.jpg . Assuming your project name is "app", this would require you to create an "images" directory in your project.

From a performance standpoint, you can rewrite the URLs to route all the images requests through a image caching service which would load images which aren't loaded yet and serve the already loaded images from memory rather than doing a disk read. And I'm pretty sure there are other cool ways of serving the images but the one which I mentioned previously is the simplest.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Look into the java.text.MessageFormat class. Also, read this.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

You don't need two while loops for populating your Deque; also your logic is flawed at this place:

character = inputFile.readChar();
                while (!character.equals('\u0003')) {
                    if (character.equals('\u0008'))
                        deck.removeBack();
                    else
                        deck.addToBack(character);
                }

As soon as you read a character which is not '\u0003', the control enters the second `while` and never moves out since you don't change `character` inside the loop.

Since you have your catch block outside your logic, an EOFException would cause the control to move out of your logic and never execute the part which follows.

Also, I hope you are reading a char which was written using writeChar; if not, use a Scanner for reading simple text files.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Is it true that during autoboxing, the type.valueOf() method is called (which creates a new object only if another with the same primitive constant is not in the intern list. This applies to cases where interning is allowed

AFAIK, the specification doesn't require anything of this sort. Yes, it requires that when boxing, cached values be used for certain cases:

If the value p being boxed is true, false, a byte, a char in the range \u0000 to \u007f, or an int or short number between -128 and 127, then let r1 and r2 be the results of any two boxing conversions of p. It is always the case that r1 == r2.

but it doesn't explicitly say that it is the "valueOf" method which would be invoked.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Why is that special treatment?

Because arrays themselves are special. For e.g., every class which supports cloning (implements Cloneable) provides a public implementation for the clone method which shows up when you iterate through the methods of that class.

for(Method m : ArrayList.class.getMethods()) {
    System.out.println(m.getName());
}

prints out the name "clone" because ArrayList implements Cloneable and provides an implementation of the clone() method. This is again true for every other class which implements Cloneable except for arrays. I.e.

for(Method m : String[].class.getMethods()) {
    System.out.println(m.getName());
}

does not print out the "clone" method even though the Javadoc of the "clone()" method of Object class specifically says:

[...] Note that all arrays are considered to implement the interface <tt>Cloneable</tt>[...]

Notice the play of words here; it says "considered" and not "actually" implement the Cloneable interface. I guess this was expected for a language construct which can be assigned to a reference type but doesn't have a programmer accessible class. I'm sure carefully thinking about how arrays are used in Java would give you a few more points as to *why* arrays in Java are special. :-)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Because arrays get special treatment as per the specs:

The public method clone, which overrides the method of the same name in class Object and throws no checked exceptions. The return type of the clone method of an array type T[] is T[].

Ezzaral commented: Nice find. +14
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

You are welcome. I see that this thread was not "marked as solved" even though you found a solution to your original question (which I've done it for you for now). Please ensure that the threads you create are "marked as solved" if a resolution has been reached for the original problem. This might actually help those who search for only solved threads when searching for answers to questions which have been previously asked on this forum.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

@Override ensures that you don't end up *supposedly* overriding a super-class method and wondering why it doesn't work. E.g. every object inherits a toString() method from the Object class. A small typo in your toString() implementation might leave you scratching your head as to why your toString is not being called.

public String toSTring() {
  // something; notice the uppercase T
}

Compilation of the above code leads to no compile time errors. Contrast it with this piece of code:

@Override
public String toSTring() {
  // something
}

The above piece of code won't compile since there is no super-type method by the name of toSTring(). Something that would have normally got caught at runtime can now be caught at compile time. Much better.

Simply put, @Override just makes your intents much more clear to the compiler.

EDIT: Beaten!

tux4life commented: Marvelous explanation :) +8
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

, it is not able to find class B.I have removed all the package declarations from the files.. The unnamed namespace is no longer the one that contains B.java (as B.java is in the home folder and I have moved from my home folder to the pkg folder and am compiling from there, so the unnamed namespace is the pkg folder now)

I'm not sure why that is the case since in the end both are unnamespaced classes. But trying out the same locally works for me so it must be something at your end. Double check the file contents.

Also, when both the files (with package declarations intact) were in the pkg folder and I was compiling A.java from the home folder with classpath set to the current directory, why was the compiler able to find B.java in the pkg directory. Does it check the package mentioned in the source file for classes too, along with the classpath ?

AFAIK, it follows it's own custom dependency check algorithm which really shouldn't concern you since it's not part of any specification and can vary from implementation to implementation.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

:)

Nick Evan commented: Thanks +0
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Even if I remove the package declaration from B.java

Then B becomes part of the unnamed namespace and types belonging to the unnamed namespace are invisible to namespaced types starting Java 1.4 since there is no mechanism wherein you can import those. Your example should work if you also move the class A outside the 'pkg' directory (i.e. remove the package declaration).

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Because each call to `readLine` bumps up/increments the file pointer, so as per your example, you effectively end up reading two lines in a single iteration. Declare a variable which would hold the string read and you should be good to go.

String str = null;
while((str = reader.readLine()) != null) {
  System.out.println(str);
  lineCount++;
}
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Double is a wrapper class whereas `double` is a primitive numeric type. Read this and follow the links in the comments.

BTW, are you by any chance using pre Java 1.5 since for Java 5 and above, autoboxing should have taken care of this for you.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

The error says that you are trying to invoke the method setAttribute with parameters (String, double) whereas the expected types are (String, Object). Simply put, the compiler expects the second parameter to be of any reference type but definitely not a primitive. Convert the `double` primitive value to `Double` and it should work out fine. Look into the Javadoc of the `Double` class.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

AFAIK, you'll get NULL only if you request the value of a form element which is not present in your form. If "name"/"address"/"username"/"password" are valid form fields, their value would be a blank string and not NULL in case you leave those fields blank.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Read the Javadocs for the Console class; it has the answer for your "why".

[...] Whether a virtual machine has a console is dependent upon the underlying platform and also upon the manner in which the virtual machine is invoked. If the virtual machine is started from an interactive command line without redirecting the standard input and output streams then its console will exist and will typically be connected to the keyboard and display from which the virtual machine was launched. If the virtual machine is started automatically, for example by a background job scheduler, then it will typically not have a console. [...]

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

The part in bold is called the enhanced for loop which was introduced in Java 5. The program iterates over the variable number of double arguments (varargs) passed to the method and computes their average.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Lol sorry, I'm a little confused. What's "you/jar/one.jar" or is that just a code? Is that the libray, in my case, bouncycastle (the library is a jar file)? And if so, does that mean I have to put the bouncy castle in the parent folder of "test" and "pkg"?

That was just a sample I posted. You can specify any number of JAR's in a similar fashion. Also, you don't need to move around your JAR's; just put the path where your Bouncy castle JAR lies and you should be good to go.

java -cp .;c:/jars/bouncy.jar;c:/jumping/jack.jar pkg.Main
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster
java -cp .;your/jar/one.jar;your/jar/two.jar pkg.MainClass

Run this from the directory where you have all your compiled classes. For e.g. if your class package is "test.pkg", then run it from the folder which is the parent folder of the "test" folder which in turn in the parent folder of the "pkg" folder which contains your main class.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Make sure you have the required libraries on your runtime classpath. Are you packaging your app as a JAR file or as class files? If you are running your app as a packaged JAR file make sure you have all the required dependencies present in the JAR file. If you are running a class file make sure you specify the -cp or -classpath argument to the Java process.

Edit: I just noticed you have created a lot of posts over the past few days but not marked them as solved. If your problem has been solved, please mark your posts as solved so that it might be easier for someone with the same query to find a solution.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

i know what an interface is. but i dont understand what the use of connecting the objective reference to the interface method and then use it to implement..

Take a look at the Strategy Pattern. A bit more practical explanation.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

AFAIK, you have two options:

  • Use an alternative Java serialization implementation like Jboss Serialization which AFAIK doesn't require your classes to implement Serializable or Externalizable
  • In case you are concerned more about interoperability than speed, use something along the lines of Xstream or Protobuf
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster
BestJewSinceJC commented: very helpful +5
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Assuming you are creating a chat application, there are at least two ways of going about this one:
* Create a language/platform independent protocol for your chat. This has the advantage that a client written in any language can communicate with your server, it need not always be a Java client. E.g. XMPP (specifically aimed at RTC)
* Write and read Java objects, as simple as it gets. The practical drawback being you can only use Java clients to communicate with your server. Technically, you can use any language provided it can serialize/deserialize its object as per the Java serialization specification but we wouldn't go there.

Regarding the common classes: one way of tackling this problem is to create a separate project which contains your VO's and interfaces. The JAR exported from this project would be used by your server application along with being shipped to the client. Again, the catch here being that updating your interfaces/VO's might require that you ship the updated JAR to your client so that it can be operational and still communicate with the updated server.

Also, to ensure that simple updates to value objects (adding helper methods) don't break your existing clients, *always* provide an explicit `serialVersionUID` for your serializable classes. If you don't, an automatic one is generated for you. Simple structural changes might cause a new serialVersionUID to be generated which isn't desirable.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

From this site which is a *very* reliable source:

Oracle has changed the naming for all sun certifications,to fit existing oracle certification names,effective September 1st

Note that this is just a name change,nothing will change regarding the certifications themselves

Naming of the certifications before and after the change


for example SCJP 6 will be called "Oracle Certified Professional, Java SE 6 Programmer" from now on

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Agreed; Java EE would be a much better and official name. Or if not that then maybe another "Java" inside the "Web Development" forums.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Database Design certainly doesn't seem like a catch-all term. Come to think of it, having a single "Databases" forum for some time would help us evaluate whether we really do need a separate forum for each specific database.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

His issue is that the hyperlink created by vBulletin if a user posts a link without using the URL bbcode is broken for wikipedia article links which end with a ).

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

A better option would be for you to configure the same in your web.xml file so that:
* changes can be applied to all the JSP files with a single configuration
* changing the configuration amounts to just changing the web.xml file and not each and every JSP

Also, if this thread has served your purpose, please mark it as solved using the "Mark this thread as solved" link above the quick reply box.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> At a certain moment my code makes this call:

There is no need to spawn a separate process for this; just make sure that the JAR is in your classpath and invoke the `main` method of the class which has that method. E.g.

import your.jar.pkg.MainClass;

public class Test {
  public static void main(final String[] args) {
    MainClass.main(null);
    // The above would same as your Runtime call given that the
    // main class for that JAR file is MainClass.
  }
}
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Instead of using Runtime class, just include the given JAR in your application and use the relevant method of the relevant class.

package your.pkg;

import com.salesforce.lexiloader.security.EncryptionUtil;

class YourClass {
  public static void main(final String[] args) {
    byte[] encrypted = EncryptionUtil.encrypt(bytes);
  }
}

This of course assumes that there is a utility method in EncryptionUtil which takes in a sequence of bytes and encrypts them.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

A downcast is not what you need. Why? Because:

int i = (int)123.123; // 123
i = (int)123.223; // 123
i = (int)123.999; // 123

See the problem?

> double [][] array = new double [(int)row] [(int)col];

This will effectively declare a `double` array of dimensions `row x col` for *each* line read and then effectively discard it. You never save the actual value which you read.

All in all, the approach is flawed on many levels; what is required here is for you to jot down a plain text algorithm and trasnlate it to Java rather than diving head first into code. Reading the introductory Java language tutorials might help the cause here.

Begin with:
- Read a line from the text file and split the contents into a double pair
- Create a new Point class object for the double pair which will hold the x & y coordinates for a given point
- Add the newly created object to a List
- and so on....

You need to write down the "actual" problem statement here rather than what you make of the problem statement. That might help the members here in helping you better.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Google for "jboss download" and you should be good to go.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

The code snippet works out well for me. For which set of data are you getting the loss of precision error? Why would storing a double inside a double variable cause precision loss? The only problem I see is your using double as an array index, which you can't. Why would you want to use a parsed double as an index to your array. I'm not sure what you are trying to achieve here...

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

The runtime error thrown is pretty clear here; you are trying to parse the string "0.0 0.0" as an integer which won't work for obvious reasons and hencefails. Here is something you should attempt, one step at a time:

  • Read a single line from a file, print that line and verify if the lines are being read properly
  • Split the line on a whitespace character; a space in your case
  • Print out both the tokens and verify their value; both tokens should be valid "float" strings i.e. of the format X.Y

Tackle the problem in steps; first try out the parsing part for a hardcoded string. E.g.

String str = "0.0 0.0";
String[] splits = str.split("\\s");
// parse the first part as float; do the same with the second part
// print out the results and verify it