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

The tutorial question seems to be using "UMLish" notation for laying down the requirements/specification but doesn't take into consideration the fact that Constructors don't actually return anything. A constructor would be denoted by something like:

==========================================================
| Rectangle                                                |
==========================================================
- length: double
- breadth: double
-----------------------------------------------------------
+ <<constructor>> Rectangle()
+ <<constructor>> Rectangle(length:double, breadth: double)
+ getLength(): double
+ getBreadth(): double
-----------------------------------------------------------

Anyways, to conclude, just ignore it as a typo and carry/move forward with your solution.

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

Too long a question and many queries lumped together in a single post. You might want to post the minimum code required for presenting the question and add more code if requested. Plus, posting queries in code snippet as comments in a bad idea and I'm pretty sure those who had a look at this thread were wondering what the question was.

Anyways,

Here I am told to add a @Override annotation for this statement and each subsequent clone function declarations in each class, why is this?

@Override annotation enforces at compile time that the method on which this annotation is present either overrides a method of the super-class or implements a method of the implemented interface. In your case, you are overriding the `clone' method of your Element class. This annotation isn't mandatory but is quite helpful since it counters surprises in case you think you have "overridden" but actually you didn't.

class Super {
    public abstract void doIt();
}

class Sub1 {
    
    // notice the typo here; the compiler won't help you out with this one and
    // unless you are using an IDE, you won't be able to find it
    public void doIT() {}

}

class Sub1 {
        
    // will result in compile time error since you are not overriding the 
    // super-class doIt() method
    @Override
    public void doIT() {
    }

}

it returns an error "cannot find symbol" on the calling line; is the function not integrated into the other classes? Why would …

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

> but I would like to know that I haven't been abandoned.

Maybe because those who visit the feedback section are not too much into fancy graphs and charts? Honest question: given the kind of resource investment (programming/hardware/maintenance) this requires, what does adding this/these features buy to the site as a whole?

I can't speak for others but I'm pretty happy with giving the solved thread/reputation points a passing glance. Too many details presented would be an overkill IMO for both the parties.

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

...which implies two things: either the tutorial is wrong or your interpretation is wrong. :-)

If you need more help, you might want to copy-paste the tutorial question here (assuming you are allowed to) so that we have more context.

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

You can't. Either change the name of the method to something other than Rectangle or change the name of the class. Though it completely eludes me why you would want to have "void" as return for a constructor...

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

This page seems to provide the 64bit binaries for 3.6.2 version.

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

The line highlighted in green is your "constructor" definition. Constructors are special methods in the sense that they don't have a return type and you are not allowed to provide one. The name of the constructor should be exactly the same as the name of your class or put in a different way, any method which has the same name as that of the class becomes a constructor and the above mentioned rules apply.

For regular methods, "void" signifies that the method need not or doesn't return anything.

class Box {

    private int mangoCount;

    // Constructor for the "Box" class
    public Box(int count) {
        this.mangoCount = count;
        // notice the lack of return; this special method is automatically called when you invoke
        // "new Box(12)" and is responsible for creating a new "Box" object.
    }

    public int getMangoesInTheBox() {
        // failure to return an "int" from this method raises a compile time error
        return mangoCount;
    }

    public void setMangoesInBox(int mangoes) {
        // returning a "value" from this method raises a compile time error though
        // you can always have a blank/free standing return
        mangoCount = mangoes;
        return; // OPTIONAL
    }

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

> i don't think its part of their rules

That's a bit harsh IMO. Except for a couple of highers ups, everyone here is a voluntary contributor, possibly including the one who'll be reviewing the tutorial.

Plus that's a pretty quick change of view from:

cwarn23, i think the moderators need more time to decide. Am sure its quite a task considering the number of editorials and stories they have to debate on before publishing.

to:

you have a point there/ I've also made the same suggestion before but i don't think its part of their rules.

Anyways, patience is a virtue etc. so please don't lose hope. :)

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

You can, though it would require a bit of effort. Look into Webdriver/Selenium libraries for Java.

peter_budo commented: Haha, two admins on two posts with same solution ;) +16
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Try using forward slashes (//) instead of backward ones (\\) and pass in the integratedSecurity=true property in the connection string if you are using windows credentials. More info on official pages: http://msdn.microsoft.com/en-us/library/ms378988.aspx

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

I don't have a Netbeans installation handy with me but can you try to rebuild the entire project (after cleaning the project) and then right click on the UseDir class and then select run? Also, are you sure that you have different code inside the main() method of both the classes?

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

For some reason almost every Java developer who has seen that song seems to say the same thing. ;-)

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

> And please will you tell me how to use the tags

Whenever you post code, just make sure you enclose it in between the [code] and [/code] tags. e.g.

[code]
if __name__ == '__main__':
....do_it()

[/code]

will render like:

if __name__ == '__main__':
    do_it()
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Nope, if there is anything in a post which is worth a moderator's attention (spam, invalid code tags, flame wars etc.), feel free to use the "flag bad post" link to bring it to our attention.

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

> don't forget those code tags!

Please consider reporting such posts so that moderators can add tags to posts which can't be modified by the OP after the 30 minute time frame.

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

Also have a look at Envoy by Kenneth. Similar approach with a few more abstractions.

Gribouillis commented: thanks for the link +13
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

A simpler approach would be to parse out an object (let's say for example PropertyInfo object) from each line in the file and then do the processing rather than parsing the file multiple times and searching for selective information.

Steps:

  1. For each line in the file
  2. Read the line and split it based on the separator (comma or spaces)
  3. The array returned by split will contain property number, property type, price, and agent id as string
  4. Create a new PropertyInfo object by passing in the four pieces of information e.g. PropertyInfo p = new PropertyInfo(propertyNumber, type, price, id)
  5. After the entire file has been read, you should have a list of PropertyInfo objects.

Now any sort of reporting is as simple as iterating over the PropertyInfo list/collection and retrieving relevant information. This also has the advantage of easing your job in case you need to report some other statistic related to the property information. For e.g. to get the set of agent ids, you can simply do:

final List<PropertyInfo> properties = parsePropertiesFromFile(fileObj);
final Set<String> set = new HashSet<String>(properties.size());
for (final PropertyInfo property : properties) {
    set.add(property.getAgentId());
}
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

RIP Steve. Such is cancer I guess. :-(

BTW, for those wondering about the new iPhone 4S, it's iPhone for Steve. Also, I'll just leave this here.

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

AFAIK, not possible since there is nothing which can be used to infer the type T in there. I'm assuming here that the aim is to ensure a Collection satisfies a given criteria. In that case, the simplest solution would be to create a separate method for the piece of code which relies on the above assumption and have the method signature same as that of the Collections.sort method.

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

> please help me in this problem, how to add /r/n in end of every line of a file in java.

Are you really required to use Java? If not, the simplest and fastest way would be to use "unix2dos" utility if you are on a Unix box or just open the file in Notepad++ -> Format -> Convert to Windows format.

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

> I was wondering which language should learn. I do not want to be a programmer for a job(at the moment I am a young teen) in the future, I would like to be a physicist.

Python and C++ is a pretty good combination. Python is particularly forgiving to beginners and makes learning the subject matter easy without getting down to too many details. Once you are comfortable with the concepts, getting your hands dirty with C or C++ wouldn't be a herculean task.

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

And please, let us know if you have posted the question somewhere else. It seems that the question posted here: http://stackoverflow.com/questions/7657228/call-scanner-within-try-from-another-method-java already has good replies...

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

Make `scan` a private static variable and initialize it in the main() method. In that case, you'd be able to use `scan` in all your static methods. In case you decide to clean up stuff, just remove the static modifier from the scan declaration and all the methods and it should still work assuming you somehow end up initializing scan before accessing it.

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

What exactly is the problem here? You want to test out your binary tree? Also, is it required that you create one and not use the set data structure present in the Java standard library?

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

To add to the above posts, make sure you quote your keywords if you are looking for an exact match. For e.g. if you are looking for sessions word in PHP code snippets, your query should be: site:daniweb.com/web-development/php/code "sessions". Without quoting session, you'll get code snippets containing both the words, session and sessions.

~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

Use the DecimalFormat class.

public static void main(String[] args) throws Exception {
	double[] doubles = {5.300000000000001, 123231.600000000000001, 88.695555555 };
	final DecimalFormat fmt = new DecimalFormat(".00");
	for (double d : doubles) {
		System.out.println(fmt.format(d));
	}
}
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Another solution would be to use the DecimalFormat class.

public static void main(String[] args) throws Exception {
	double[] doubles = {5.300000000000001, 123231.600000000000001, 88.695555555 };
	final DecimalFormat fmt = new DecimalFormat(".00");
	for (double d : doubles) {
		System.out.println(fmt.format(d));
	}
}
~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

They can be thought of as complementary tools as opposed to competitors. Findbugs is the easiest to get started with. Just install the relevant plugin for your IDE (the easiest way; of course you can also run it on a standalone Java project configured in a text editor from command line), right click on your project, click FindBugs and you are ready to go. PMD is a bit more complicated since it relies on rules and rule sets but if you don't mind the defaults, the setup is the same as that of Findbugs.

A note though; sometimes these plugins end up being pedantic, too pedantic. This is especially true for PMD. Plus, you might end up facing a couple of false positives here and there, for e.g. this one. I personally use both though I'm a bit more realistic on what I end up fixing.

Also, it's a bit surprising that the problems discussed in this thread for some reason isn't flagged by Findbugs/PMD though they give good suggestions nonetheless. ;-)

Also read: PMD v/s Findbugs

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

> Is there an easy to use tool that OPs could use to find variable's whose class level definitions are Shadowed by local definitions of variables with the same name?

Not exactly beginner friendly but any serious development house at least has "FindBugs" or "PMD" running on their code bases to identify shadowing and many other serious bugs (e.g. synchronization).

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

Plus we really don't want reporters to be swamped with details and just let them report things which they find inappropriate. We'll handle the dirty job of deciding what should stay and what shouldn't. :)

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

Also, when a member alerts the administrators on a Bad Post, is there a feedback to such member maybe asking for more reasons why the post was flagged as a bad one letting him know the administrators verdict?

Such facility isn't built in the system but the moderator is free to PM the member in consideration and ask for more details if required (mostly done in case of a heated argument). Given that moderators/staff members are more conversant with the rules than regular members, we can pretty much make out whether the post flagged was really worth taking action on. In case there are multiple view points, a thread is created in the moderators forum to discuss the case; nothing too grand. ;-)

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

> the # of solved threads is a bogus value to begin with. It has no real purpose and gives a skewed view of most poster's 'help'. It's even less useful than REP

Everyone get's to pick their own poison - reputation, up-votes and solved threads; take your pick. Plus the concept of solved threads when used correctly can help folks searching for solution to their problem narrow down things. I know this is a utopia but I don't think it is particularly bad to work towards it.

> It's not our place to mark threads solved -- it's the OP's place.

You are in for a surprise; yes it is! Two cases:

  • OP replies to the thread saying his problem is solved but doesn't mark it as solved
  • OP receives a reply which the moderator feels (in his capability as a technical adviser of that particular sub-forum) should solve the problem but the OP never bothers to return back to post or even mark the thread as solved

If moderators don't handle these cases, then I'm not sure who will.

> Just more stuff for the mods to deal with that does not (IMO) add anything to the forum

Yes, I know it's additional work and hence my disclaimer in my original post. :-)

~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

> The criteria to seeing it is being a moderator AND a staff writer.

Good luck getting them reviewed. :)

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

> I've just submitted a tutorial so something should be in there.

Nope, can't see it. I'm pretty sure just the forum name was changed and not the permissions hence the result. Maybe Dani can change the permissions when she is online.

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

Notepad is not a compiler, it's a text editor used for typing in Java code. If you are just starting out, I'd recommend grabbing any text editor which highlights the code for you along with smart indentation. There are a lot of options in there: Notepad++, Gedit, Scite etc. I've also heard good things about "Programmer's Notepad".

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

> Anything that you post in there can only be seen by yourself as well as moderators/staff writers

Just FYI, I can't see anything in there. Are you sure it's not "staff-writers-only"? Or is it that nothing has yet been submitted?

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

Hi folks,

When browsing technical sub-forums, I noticed that there are a few threads which end with the OP replying "Thanks, it's solved/working now!" or something to that effect and are still not marked solved. Similar is the case with one-shot-posters who post a query which is duly answered but never return (or return just to read the answer) to make a reply or mark the thread as solved.

This has the consequence of valid solved threads not contributing to the total "solved thread count" of the sub-forum and the forum in general and more importantly denying +1 solved count to all the members who contributed to the discussion. The problem is that there is no way a thread contributor, who is pretty sure he has answered the OP's question, can mark the thread as solved.

So here is the deal: in case you encounter a thread which you are pretty sure should be marked solved, you can "report" any post of the thread (preferably the first one) with a comment along the lines of "IMO should be marked as solved". Also, please don't shy from reporting threads for which you are the only contributor. ;-)

I can't guarantee the "resolution" of each and every reported post given that moderators have limited time but this at least seems like a step in the right direction.

Ask away if things are still unclear or in case you disagree with something!

jingda commented: Agreed +0
~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

What categories of game do you guys usually play. First person shooter, racing, role playing or what?

Never liked racing games (well, except for Road Rash). I've had my share of action, RPG and strategy games ranging from Diablo, Age of Empires, Half Life etc.

I'm recently more into RPG stuff (Oh Diablo 3, where art thou!), more specifically MMO's. :-)

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

Unfortunately no easy way of doing this. There are two contenders in Java land (assuming you are talking about actually interacting with pages rather than just scraping the web page ignoring the JS part): HtmlUnit and Selenium.

HtmlUnit works pretty good for simple and compliant web pages. I have successfully used it for scraping simple sites like Reddit but failed to find any use when working with JS heavy sites. Plus I've heard bad sort of bug encounters when faced with quirky HTML markup. No generic support when returning collections means lots of casts but I'm sure this is a minor complaint.

Selenium, at least for me, was a pain to set up. Plus AFAIK it is something mainly aimed towards browser driven web application test rather than "scraping" though it can be certainly used as one. I have used it for automating "field" filling and clicks and it has worked out pretty well with code shorter than HTMLUnit. It spawns up a browser instance for simulating your script which I'm not really a fan of but if you can live with it, good for you.

If you are not afraid to ditch Java, I've heard good things about PhantomJS which uses a headless Webkit browser to do its bidding. Plus you get to write scraping scripts in Javascript (not sure if that's a plus for you).

~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?