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

Are all those classes in separate Java files? How are you running the UseDir class?

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

Right, because Set guarantees unique elements, not necessarily in sorted order. If you need to maintain the order of elements, use `TreeSet<String>`. Just make sure the objects you insert in the TreeSet implement natural ordering (by implementing Comparable) or be ready to provide your own custom ordering (implement Comparator). Anyways, here is the extension snippet:

public static void main(String[] args) throws Exception {
	final List<String> lst = Arrays.asList("a", "b", "c", "a", "c", "b");
	final Set<String> set1 = new HashSet<String>(lst);
	final Set<String> set2 = new TreeSet<String>(lst);
	System.out.printf("Original list: %s%n", lst);
	System.out.printf("Unique values: %s%n", set1);
	System.out.printf("Unique values sorted: %s%n", set2);
}
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

You need to tell us the type of values you have in the `List'. Assuming you have simple strings in the list, you can do:

// untested
final List<String> lst = Arrays.asList("a", "b", "c", "a", "c", "b");
final Set<String> set = new HashSet<String>(lst);
System.out.printf("Original list: %s%n", lst);
System.out.printf("Unique values: %s%n", set);
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> can any one tell me how to find unique values in array list?

Assuming your items of the `List' implement an appropriate equals/hashCode() method or the Comparable interface, converting it to a `Set' would be the simplest way to get the unique elements.

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

> I'll try your last snippet. The problem was that I'm not using File, but FileWriter, and FileWriter seems to be unable to write to places that don't end with '/'.

FileWriter and File are in no way related and serve completely different purpose. FileWriter takes in a File object which relieves you from using "/" or "\". Try it out.

> I guess I'll have to have the user specify a filesave path...

Yes, or just hard-code it, which wouldn't be nice. Just make sure you validate the path entered by the user and throw a BadConfiguration exception if it points to a non-existent path or a file instead of directory.

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

> 0. I added that "/" and everything is fine now.

As I have been mentioning repeatedly, you should never have a need to deal with "/" or "\" when dealing with files in Java. The different File constructors make it possible for you to manipulate paths in java in a platform agnostic way.

> 1 - How do I get it to write to My Documents folder instead of the home folder (because the name My documents changes with language).

There is no system property for "My Documents" so you would have to hardcode the directory name or read it from a configuration file.

> 2 - How could I avoid using trailing? Remember that getProperty(user.home) returns the home without the trailing \.

Read point 0's explanation.

> 3 - Also, you use a different object for the file, is there any problem with mine? Why are so many ways of creating files with Java?

Yes, the problem with your approach is that you explicitly use path separators which lead to non-portable code.

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

> Put simply i'm asking "What are the most common and effective languages used in industry?"

Try to stick with the ones taught in your curriculum since you would anyways expected to know them once you are done with your degree. AFAIK, C++ and Java are pretty common these days in universities. Pay close attention to the concepts since once understood, they can be replicated in almost any decent language.

After that, if you "feel" like learning a language for fun and expanding your knowledge, there are many good ones out there. The trick is to try out many languages and stick with the ones you are most comfortable/you have the most fun in.

EDIT:
> I was wondering what the best languages to know are as i really cannot be bothered learning loads

Wrong attitude; there is no *best*, if there was, we wouldn't have the plethora of languages we have right now. Also, I'm not sure why learning or trying out "loads" of languages is a "bother" for you? :-)

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

> Now, I tried to follow S.O.S's advice regarding filepaths, and I came up with this:

You are still relying on string concatenation for building up file/dir paths. Also, what exactly happens when you say "doesn't work"? Exception? Here is a simple snippet which should work and uses File constructors instead of "+" on Strings.

// try..catch..finally left out for brevity
public static void main(String[] args) throws Exception {
	final File homeDir = new File(System.getProperty("user.home"));
	final FileWriter writer = new FileWriter(new File(homeDir, "a.txt"), true);
	final PrintWriter pWriter = new PrintWriter(writer);
	pWriter.printf("%s -> %s%n", "home", "a place you can always go to");
	pWriter.close();
}
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> Adding to that, it might also be worthwhile using System.getProperty("file.separator") to ensure compatibility on as many systems as possible.

Or better yet IMO, try not to mess with FS paths thinking of them as strings and use appropriate constructors:

final File homeDir = new File(System.getProperty("user.home"));
final File defaultFileStore = new File(homeDir, "data.txt");

The appending trick will work in this case but would haunt you in case you are picking up the base directory from a configuration file and someone decides to add the trailing \ or / for you. In that case, appending will result in you ending up with two path separators after the directory name, not good. :-)

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

> I try to connect with mysql (port-3306). Above code works properly in localhost but when i try it with ip of my server (173.255.216.128) it gives following error

This seems like a configuration issue. Are you able to ping this host? Are you able to connect to this host via a SQL UI client like MySQL workbench? Is the server under your control or have you bought this MySQL hosting?

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

If you want to distribute your application to users, just package your JAR along with shell scripts for specific platforms, just as it is done for applications like Tomcat etc.

If you are using such shell scripts, it would be pretty simple to put in the sudo in the script and all the user will see is a password prompt. Something like:

# runserver.sh
sudo java -jar httpserver.jar

This way, your users won't be aware of "sudo" in the script and would just have to type in the password, as intended.

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

AFAIK, you require "superuser" (also called as "root") privileges for binding to ports below 1024 and `sudo` does exactly that, run the program as a "superuser". From the sudo wikipedia entry:

By default, sudo will prompt for a user password but it may be configured to require the root password, and will require it only once every 15 minutes per pseudo terminal, or no password at all.

As you can see, it by default happily accepts the logged in user's password (just to confirm you really are you) before running commands as root. This can of course be configured differently to make sure sudo actually requires 'root' password but that's a different story.

Also, though admin users are almost like "superusers", there are a few areas wherein you actually require a superuser and you have stumbled upon one of them. The solution? When testing use a port which is above 1023, something like 8080. I don't do my development on a *nix box but there is a thread on SO which talks about the same stuff, maybe you can draw some inspiration from there but using a different port would be the easiest.

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

> My question is whether this has been a new feature added to java 6 or am i missing something ?

This compiler enhancement was added in Java 5. The above code compiles fine in Java 1.4. I'd recommend getting the most recent version of the SCJP book if you plan on giving SCJP 6 to avoid such inconsistencies.

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

Depends on how good your preparations are. Kathy Sierra books are pretty good when it comes to certification preparation, for e.g. this one for SCJP 6(called something else now but doesn't matter AFAIK).

The secret is to not just "read" the book but also try out the examples "without" blindly copying them from the textbook. I do know that this might be a far cry for someone who wants to give the certification ASAP but still worth a try. Google around for "SCJP 6 mock exams" for practice problems.

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

As you both have already observed, there are a few limitations with the current voting system. These are:

  1. You can't add a comment without adding/removing reputation
  2. You can't "undo" a up/down vote or reputation. Once an up/down arrow is clicked, closing the window which pops up just removes the ability to add a reputation comment. The up/down vote remains.

Both these are pretty much implementation details and can be much better explained by Dani but AFAIK these are on the TODO list. :)

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

You are by default capable of awarding x and y number of points to the user where x and y is your power to influence a fellow Daniweb member's reputation in a positive and negative manner respectively. For e.g. you can positively influence by +4 and negatively by -1. AFAIK, these values come from your current reputation points you have (which is 47 right now).

Daniweb doesn't have the concept of awarding "varying" reputation wherein you can award selective number of points. Also not sure if it was a typo, but in your case you are awarding 4 reputation points and not 1. Another concept which comes into play here is the "upvotes" and "downvotes". This metric is something which is helpful for measuring the usefulness of a user's post. You can't add reputation without influencing the vote count by +1 and -1 for up and down votes respectively. But you can of course just "upvote" a post and not add any reputation to it (there by remaining anonymous). Again, this value isn't customizable and would never change (as opposed to rep power). No matter your reputation, up/down votes would always influence the total up/down vote count of a user by 1.

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

I have deleted the groups since they didn't have a lot of members to begin with. I'll probably kick off a discussion in the mod forums related to this since this is pretty close to deleting threads on demand, which we don't allow right now. I'm sure you would exercise caution when creating your next group and not assume you would be able to delete them as required.

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

> But when you need quick answers you always want to get in touch with someone who is online.

This more or less amounts to " paid consulting" (if you want to get things done your way) and there are quite a few sites which engage in this sort of activity. This is one of the reasons why beginners get flamed on well known technical IRC channels. They join the channel expecting "quick help" but are disappointed when they are told off by the regulars there.

Of course, not saying that such places absolutely don't exist, it's just that if you need quick online help, folks would expect you to shell some money.

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

This seems like a direct-copy paste of http://letshare.it/blog/regular-expression-beginner.html

Do you own that content?

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

From the Javadocs:

Causes the currently executing thread to sleep (cease execution) for the specified number of milliseconds plus the specified number of nanoseconds. The thread does not lose ownership of any monitors.

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

Which version of HttpClient are you using? 3.x? Also, I could have sworn the default port for HTTPS was 443...

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

Moved the thread.

BTW, consider the possibility of your account being compromised and some third party entity already knowing your current user name and password. You should ASAP get your password changed and then think of finding out *how* exactly this happened.

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

Adding on to others, it also pays to know that cloning in Java is pretty much broken and for practical purposes you are better off using other alternatives (hand rolled copy constructor).

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

I'm not sure why you are assuming that there would only be 1000 submissions per day? Any reason for limiting the last part to 3 digits/characters? Any reason to not try out a pattern like "yyyyMMdd-HHmmssS" which automatically handles the resetting for you?

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

Having looked at the URL above, I have a hunch that the database server version should be the same as the client driver version for optimal operation.Could this be the cause?

You can try updating to a new version but I doubt that's the reason why this is happening. If it were, why wasn't it happening previously? Do you run any database heavy jobs around that time or is it that the hits to your database are maximum at that time? I've read about prepared statement failing due to dumps going on at the database level for MySQL.

A temporary solution (if you are in need for one) might be to put a try...catch around the prepare call and try preparing the statement again if it fails for the first time. Other than that, your best bet would be to try to understand *what* special processing happens at around that time or recollect what else was changed during the move.

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

We need more details; what else was changed during the move? Which MySQL version are you using? Which client driver and what version? How frequently are you getting this error message?

A link you might find helpful: http://stackoverflow.com/questions/4380813/how-to-get-rid-of-mysql-error-prepared-statement-needs-to-be-re-prepared

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

Some idiot had cleared all cookies on my machine after using some of his email account, I can only remember my youtube user name but no password, and when i was creating youtube user account i specified a email account which is not really exist, now, i am trying to retrieve my password, but no hope of recovering it....is there anything can be done to get my old youtube account, i just love it, it has all my collections and weird comments

You do realize that if this was possible, it would be a big gaping hole in the system since it would allow hackers to gain access to accounts just by knowing the user name, no? :-)

jingda commented: Sure make sense :) +0
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I did something similar a long back when I was playing around with Python. You can find my scribblings here; just adjust the method calls and you should be able to understand how it works. The trick here is to think in terms of co-ordinate, try to plot stuff on a piece of paper and then code for it. Also, please make sure you use the code only as a reference and try to come up with your own implementation. ;-)

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

A pity I missed that; you just need to append the database name at the end of your URL. Example here.

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

> Is there a way to make it retry the connection

Automatic retries? Not that I'm aware of. Of course, it's dead simple to just loop over for a given number of times before giving up completely.

> I set the timeout to 500Secs and it still timesout in like 5-7 secs...

The timeout exception need not necessarily be of the client socket (in our case the socket used by the Driver). Server sockets can also have timeouts which might be the reason why you are getting time outs (which again is not surprising given timeouts in your ping). Are you able to connect to the database in consideration using some sort of SQL explorer like workbench?

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

Are those your real login details? If yes, please edit them out.

Regarding timeout, are you able to ping the given host from your machine (ping tribalwars.db.4489877.hostedresource.com)? Also, what happens when you comment out the DriverManager.setLoginTimeout(100) line? I don't see a port number mentioned in there; is the db in consideration running on default MySQL port?

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

Basically give the members the ability to make their own queries

Or you could just, you know, remember the folks who rub you the wrong way

Or just ban those who rub you the wrong way, if you have banning powers that is. ;-)

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

Vector class *has* become obsolete. If you need a synchronized List, just wrap the plain old ArrayList class inside the Collections.synchronizedList call. In short, don't use Vectors unless you are tied to an API which forces you to use it.

Also, don't rely on synchronized collections when it comes to handling race conditions; they synchronize individual calls and not logical calls which you actually should have synchronized.

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

I always felt one more in the list is required. Like if user who started thread was last to reply on that thread and that thread is still unsolved. It means that user is expecting someone to answer

...or has already got an answer and is thanking the ones who helped him solve the issue. :-)

But really, IMO for those who help out, monitoring the forum once a while (every 3 hours or so) for new replies is pretty much a trivial.

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

A thread containing a link to the most frequently asked questions might be a good idea but to make individual threads sticky is not really worth it. It would just end up resulting in a proliferation of sticky threads in a given forum and thus reduce the effectiveness of a sticky thread.

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

At the bottom of each forum, the legend/meaning for each icon is given. The only one missing from the list is: http://images.daniweb.com/vbulletin/statusicon/thread.gif which denotes a normal thread: i.e. a thread which you have already read, is not *hot* (err.. I mean popular) and you don't have any posts in it.

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

You might find it helpful if you think of class loading and initialization as two different things. For e.g. when I write "StatKlass.THE_ONE", the class-loader loads the binary representation of the class StatKlass (i.e. the .class file) but *doesn't* initialize it.

EDIT:
> Lets wait for SoS to comment now..

I already have given my comments. :-)

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

You've got things mixed up; re-read my post and try out the example. Kashyap provided a way for "explicitly" initializing a class whereas I talk about implicit initialization in my first post. The entire process is mentioned in the specification.

A class or interface type T will be initialized immediately before the first occurrence of any one of the following:

T is a class and an instance of T is created.
T is a class and a static method declared by T is invoked.
A static field declared by T is assigned.
A static field declared by T is used and the field is not a constant variable (§4.12.4).
T is a top-level class, and an assert statement (§14.10) lexically nested within T is executed.

So basically, whenever you try accessing a static field (except for constant variables), the class would be initialized.

warlord902 commented: Thanks for directing towards specification +2
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Yes, the class initialization has to complete (executing static initialize blocks and initializing static fields) before you can access the 'con' static field which implies initializing the other static fields. But there is an exception to this rule: the class initialization does *not* take place if you access a "constant variable" (final declaration of primitives of string in your class). E.g.

public class Test {

    public static void main(final String[] args) {
        System.out.println(StatKlass.THE_ONE); // will *not* cause initialization of static fields (e.g. conn)
        System.out.println(StatKlass.NOT_THE_ONE); // will cause initialization of static fields (e.g. conn)
    }

}

class StatKlass {

    public static final int THE_ONE = 1;

    public static int NOT_THE_ONE = 0;

    public static ServerConnection conn = new ServerConnection();

}

Many people get confused between class loading and class initialization and assume that all static elements would be initialized when the class is accessed for the first time, which isn't the case as we see above.

Also, if your class implements an interface and it has "fields" (public static final by default), those won't be initialized when the class is initialized. They have to be explicitly referenced for the initialization to take place. Same with super interfaces of an interface.

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

AFAIK, this is expected. The IP address assigned to you by your ISP is the external IP address whereas the unique IP addresses of each of your network machines are "internal" addresses which aren't viewable to the outside world. This is one of the reasons why browsers don't just rely on IP addresses for client identification but use a token mechanism like passing token (session id) using cookies or by appending it to the URL (another one is client using proxy servers).

So to answer your query, this isn't just about "different" computers but about public IP addresses. A solution around this would be to use a token mechanism i.e. generating hashes and assigning them to clients which connect to your server and "destroy" or "invalidate" the hash when the client logs off or a certain period of inactivity is observed.

masterofpuppets commented: thanks for the suggestion :) +5
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

To add to Davey's post, the moderator team normally treats "Keep it legal" cases with highest priority given that having copyrighted content around for a long time without proper attribution might end up putting Daniweb is a big mess. That is one of the reasons why no warning is issued for the "Keep it legal" infraction; two strikes and you are out.

Hope that clears up the reason why you were banned.

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

I think you should first try with NetworkServerControl simply because it seems more logical than setting system properties (at the JVM level) and relying on the derby driver class loading to start the server.

Regarding the properties file, I think you just need to create the properties file with the contents as per your need and make sure it is on the classpath (look into how to set classpath for a given JVM process; tip: java -h). Also, read this.

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

Have you tried using the NetworkServerControl API as mentioned in the second point linked in your post? If yes, what kind of problems are you facing?

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

AFAICT, that isn't blue, it's green and gray. It means that:

  • Either you were awarded reputation in a forum where reputation doesn't count (e.g. Geeks Lounge)
  • You were given reputation by someone who doesn't have enough rep power to influence you. As an example, take a look at this member who awarded you reputation in a technical forum but it still showed up as gray.

There is another color, red, which means that you were given a negative reputation (typically given when someone doesn't agree with your post and wants to negatively influence your reputation).

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

I'm not sure what exactly you are after here? Featured member/poster isn't about fame or fortune; it's about getting to know a bit more the regulars who lurk on Daniweb.

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

1) Must you be a sponsor to be a feature poster?

No.

2) Do you need a certain amount of post, solved threads or reputation.

No, it's a hybrid algorithm where we take into consideration a lot of things. The primary requirement is that the member should have posted long enough for us to *know* more about that member. We are pretty good at valuating folks (after having spent a lot of time moderating) so you can be rest assured that good folks always get a chance. And as already mentioned, you can always recommend some... :-)

You must first go without sleep for 36 hours before being subjected to numerous hard-hitting questions like 'What you did last Summer' and 'what you had for breakfast'

Can't say I disagree. ;-)

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

> http://translate.google.com/translate_tts?q=Daniweb

This URL gives me a 404 (document not found) hence doesn't yield anything. The actual URL should be: http://translate.google.com/translate_tts?ie=UTF-8&q=hello&tl=en&prev=input .

I'd recommend using a property HTTP library which offers sufficient abstraction, something like HttpClient or Resty. A sample test code using Resty can be found here.

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

Daniweb members who are interviewed for the Daniweb monthly digest/newsletter get the title "featured poster". These members are typically picked up by site administrators based on factors like contributions, frequency of visiting Daniweb etc.

Admins typically have a list of 'to be interviewed' folks but if you feel that someone fits the role for an interview (including yourself :>), you can always PM Davey (aka happygeek) and that name would be added to the 'to be' list.

jonsca commented: They told me it was based all on looks... this changes everything! +0
jingda commented: I thought is has to be the mumber of post you have, this prove me wrong +0
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

The problem with this approach is that the welcome would seem kind of forced. And not to mention the possibility of the answer being forced as well. It might go something like this:

OP: Hello, can anyone help me with xxx? Thanks.

New-Member: You are almost there, just change yyy by zzz and you should be good to go.

I-Just-Saw-Sunshine-Member: Yeah OP, you should totally follow what 'New Member' has written down. That being said, New Member, welcome to Daniweb. Hope you enjoy your stay here. Looking forward to working with you.

Just to be clear here, as long as your posts are 'on-topic' in the forum you post, it isn't against the rules but if your posts start becoming more of a welcoming committee speech and less of a valid answer, it's annoying for everyone.

That being said, you "can" do it without violating the rules but with that long speech, it would be considered annoying. A simple "Oh and BTW, welcome to Daniweb" added at the end of your post or a simple reputation comment "Welcome to Daniweb" would be much more desirable.

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

You need to create task objects when you are iterating over the resultset. These task objects can be then pushed inside a list. You can then use this list as you see fit i.e. to run the tasks etc.

// untested pseudocode
final ResultSet rs = stmt.executeQuery();
while(rs.next()) {
  // create new task object
  taskList.add(task);
}
// close resultset, statement and connection

// somewhere else
for(Task task : tasklist) {
  // execute task
}