~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster
Ezzaral commented: Excellent song! +0
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I'd personally recommend a file/directory copy utility. This way, he'll get more acquainted with how the CLI clients work and get a taste of implementing a fun utility from scratch. The good thing is that this project can be beefed up if required by adding more options like the way a real copy command works. Bonus points for progress bar etc.

zeroliken commented: you make it sound like it's just a walk in the park ;) +8
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Two ways of doing this:

1) NULL checks every time you add an element. If the "key" is not associated with any underlying set, create a new HashSet, and place it against the key.

Set<State> states = mapping.get(transitionStringToAdd);
if (states == null) {
  states = new HashSet<State>();
  mapping.put(transitionStringToAdd, states);
}
states.add(transitionStateToAdd);

2) If you can afford adding a library, Google Guava provides a class just for this use case: HashMultiMap. It relieves you of the NULL checks but of course something similar is going under the hood. The new code after using this class will look exactly the same as your code snippet.

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

"make" is a standard "build automation" utility which is pretty much available on *nix like platforms. For more info, read this. The core concept is that instead of firing the commands required to "build" a project again and again, you stuff them in a "makefile" and distribute them to the users to allow them to build stuff without knowing the internal dependencies/structure of the project.

Apache Ant is similar to "make" in the sense that it is a build automation tool *but* differs in the sense that it uses "XML" as the automation language instead of a home grown one (like make does). Also you won't be completely able to understand the statement "without make's wrinkles" unless you have used "make". For the time being, just assume that make has it's pretty share of problems. If you need more info, try this.

BTW, Ant is pretty much a legacy solution when it comes to "build automation" in Java land these days. Maven is the de-facto tool for both build and dependency management solution when it comes to Java projects. Of course, it still has its share of problems (using XML being one of them). AFAIK, Gradle works towards the goal of using Groovy, a full fledged DSLish language for build automation and at the same time using Ivy under the hood for dependency management but I'm not sure how it works when it comes to integrating with an IDE (Eclipse/Netbeans).

TL;DR: …

peter_budo commented: Couldn't agree more. +16
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Is the database really running on the port 1521 of your machine? Are you able to connect to that SID using SQL Developer?

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

Although my suggestion was to see all the other suggestions so you won't repeat what's already been thought of. Anything new can be posted here. I would question the need to revive the older threads.

I agree, I have been around for a long time to see how useful thread bumps turn out to be. But the thing is that bumping threads is not against the rule and hence asking someone to "not" bump a thread in my capacity as a moderator/super-mod would be wrong IMO.

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

The difference is that with SSS, you are providing a padding for the millisecond field. So if the milliseconds elapsed are 9, it'll be shown as "009". If you instead had just "S", it would be shown as "9". Regarding the 'E' format specifier, you can simply replace the 3 E's with a single E without any visible change in the output. If you have more than or equal to 4 E's, it'll use the full form of the day of the week. For e.g. with a single E, the output would be 'Fri' but with 4 E's it would be 'Friday'.

Also, the locale for a date formatter is by default the default locale so you can drop the second argument to the SimpleDateFormat constructor.

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

The format `dd/MM/yyyy - HH:mm:ss.S E` should do the trick. For future references, look into the Javadoc of the SimpleDateFormat class.

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

Would i be allowed to make a comment in those threads or would that be "reviving the dead"?

Thread bumping rule isn't an absolute. It's just that 99.99% of the times the bump is irrelevant/off-topic/spam/homework kid, making us a bit strict/wary when it comes to bumping threads. If you feel you absolutely must reply and add a new view point to the discussion in consideration, go ahead.

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

It still displays the old one!? Whyy??

Apart from answering the questions posed above, make sure that you do a clean build and then run the application. It's quite possible that the old image still resides in the build directory of Netbeans. Also, check where exactly is this application run from (search for the dir Netbeans uses) and verify it has the same image in consideration.

peter_budo commented: +1 for clean build +16
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Sorry, but I still didn't get it.

Fair enough. To understand the need for a solution, you need to first have a good grasp on the problem you are trying to solve. So my question to you is: what would be your solution if you are asked to come up with a way to ensure that clients are forced to implement a subset of methods found in an interface? E.g.

interface Template {
  Environment getEnvironment();
  byte[] renderToImage();
  String renderToString();
}

Let's say renderToImage() is a convenience method which uses renderToString() to output the image. If I have to create a class which only needs to implement renderToString(), what would be your solution?

Check here the java docs help me understand even the most complex of definitions:http://docs.oracle.com/javase/tutori.../abstract.html another good def:http://www.roseindia.net/help/java/a...-keyword.shtml

Please don't quote Roseindia, they are content thieves.

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

I'll try to explain this with an example. Let's talk about a simple templating system which is based on a single Template interface. Every different template implementation has a different way of interpolating variables, convention used for representing data etc. But all templates also share a common piece of logic: they all interact with the "environment" i.e. state, they all are capable of being serialized to common formats like PDF, PS etc.

My concern as a template framework provider would be to prevent code/effort duplication for template implementers i.e. classes which provide different template support. To that end, I create a convinience base class which would be extended by all template implementers and which has the common logic required for all templates. But I have two problems:

  1. I can't enforce template writers to override/implement a method. For e.g. I would want each template writer to override the render() method which takes a template, environment and produces a rendered output as String.
  2. I can't prevent instantiation of the BaseTemplate class.

These two problems can't be easily handed by a normal class. Enter abstract classes. You want to enforce template implementers to override a given method? No problem, just make it abstract. You want to enforce non-instantiation? No problem, make the entire class abstract.

Of course, I'll also mention that you can't have abstract methods without making the entire class abstract because as per common sense, you'll really not want to "instantiate" something which isn't complete (yes, …

stultuske commented: never been good at explaining myself :) +12
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

it just increases the size of your code because then you are importing everything from the IO package

This statement is a bit misleading. It doesn't increase the size of your code. If you'll disassemble the class file, you'll notice that classes are anyways referenced using their fully qualified names (i.e. java.io.BufferedReader instead of simply BufferedReader). The imports are anyways used to manage/locate compile time dependencies.

That being said, the reason wildcard imports are not recommended (unless throwing together snippets) is that it becomes difficult to trace which class was imported from what package. This of course if mitigated by using an IDE but is a good thing to know just in case.

peter_budo commented: There you go again, "smart pants" answer. Nice summary :) +16
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Few points:

  1. close() calls should always go in the "finally" blocks
  2. Never use System.exit() to duck out in case of failure. If your code is used in a large/big setting, exitting the JVM in case something fails isn't pleasant. Boolean returns are your friend.
  3. Always check the return status of "delete()" call because file deletion failures are pretty common.
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

It really makes me happy and gives a warm fuzzy feeling knowing that the small amount of guidance provided helped you in the long run. Good luck with your new job! :-)

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

> Is this kinda *odd* for his age?

Ouch, Java... If possible (unless your child is insisting on it), try to avoid Java. He'll get a lot more opportunities to be "enterprise" ready. Apart from Python (which I think you are already teaching your child) there are other better heavy weight languages out there.

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

No, except for the official mail communication, nothing is finalized. All January classes have been moved to February without any further information.

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

In the class file on disk and as part of the runtime class/object data, yes.

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

@sha11e: Strive for correctness, readability and performance; in that order. :-)

BufferedReader ins = null;
static PrintStream ios = null;

Do neither use up memory at this point?

They are simply fields of the given object i.e. names. They don't consume memory in the sense that they don't point to "real" reader or PrintStream at this point in time.

static will never die as its for the entire life of the program

This isn't entirely correct. Class unloading is possible which automatically makes these static stuff go away.

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

hey I just realized I was not supposed to post this code online could someone either delete the thread or my username/personal info

There is no personal information in that thread. The only possible incriminating piece of info would have been the package name which I have removed from the code snippet. If you still are uncomfortable, simply change the profile information which you have entered and you should be golden.

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

You can use JUnit Test Suites to get a fine grained control on which tests get executed. Create a test suite, run it and it will automatically run only the included test classes.

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

think that you should have posted this in the JSP forum

Please report such posts instead of replying to them. This will ensure that the post doesn't lose its meaning after the thread move is done.

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

This is my custom exception class. By the way, I want to create an exception for not allow the user set inches and feet to a negative number. After create my custom exception class, I implement it to my distance class like this

There exists one such exception in the Java standard library specifically for this case; it's called IllegalArgumentException which you would normally see when you try to create an ArrayList with negative size etc.

Also, the custom exception which you have created is a "checked" one in the sense that "compiler" checks to ensure that either the caller catches the exception or propagates it to a higher level. Don't use checked exceptions for something which can be easily prevented at runtime. For e.g. in your case you can always check the parameters before passing them to the Distance constructor. Or better yet, just throw a unchecked exception (like IllegalArgumentException mentioned above).

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

You need to add a type parameter to Distance class only if you have generic types as members of the class. A good example for such a class would be "Node<T>" of a linked list which holds a value of type "T" along with a reference to the next node

class Node<T> {
  private T item;
  private Node<T> next;
}

In your case, you need not make your class generic. You can simply do:

class Distance implements Comparable<Distance> {
  public boolean compareTo(Distance that) {
    // code here
  }
}

I also have a question about generic class. If I make it generic and I have an inch and feet variable. Shouldn't I make it

Nope, the type parameter for the Comparable interface is the class which implements Comparable and not the type parameters of your class.

The last question is about equal method, I don't quite the code you just type up there. I don't understand. Can you explain it a little bit.

Which part specifically? I'm just pointing out that you are missing a condition which will help with "fast" execution of equals in case you pass the same object into the equals() call. For e.g. with your current equals() method, if I do:

Distance d = new Distance();
boolean status = d.equals(d);

The equals() call would go ahead and compare the fields when there is no real need to do so given that we know they are the same objects in memory pointed to …

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

> a reason why you yourself would/could use private constructors, is implementing the Singleton pattern

As a safety measure, if your class shouldn't be instantiated, make sure you throw an exception from the private constructor otherwise it is pretty much open to reflection abuse.

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

Your `compareTo` method isn't proper. In compareTo, you don't create "new" objects but compare the object on which the method was invoked with the object which was passed in. Your current code doesn't work because "k" should ideally be the "this" object. Also, your assignment to "k1" is lost/meaningless since you again reassign with the cast of "obj".

Also, make sure you use `Comparable<T>` where T is the type you are comparing instead of simply Comparable (given that Comparable is a generic interface). This will help you get rid of the cast.

Your hashCode() can be made a bit better by following the code which is used by most hashCode() implementations of the standard library. Something like:

@Override
public int hashCode() {
    int prime = 31, result = 1;
    result = prime * result + ft;
    result = prime * result + in;
    return result;
}

Your equals() method is missing a inexpensive check to make sure that if equals() is invoked on the same object, it returns without checking anything.

public boolean equals(Object that) {
  if (that == null) return false;
  if (this == that) return true; // -> missing this
  // remaining code
}
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> but it would be nice to know that the money got through

Hover over your avatar in any post you make and you should see a "sponsor" badge. Also, try accessing "Area 51" in community center after "clearing your cookies". If these two are as expected, then your payment has definitely gone through.

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

Because mathematically, 10.1 is the same as 10.10 which is the same as 10.100 and so on. You might want to elaborate a bit on the context here to get useful answers.

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

Still doubting if any free game can beat WoW, but I'm open-minded

It still has subscription levels. What we call free is the basic "bronze" subscription which allows you to have a feel of the game without demanding anything upfront. For anything serious, bronze is too restrictive (slots, classes, spells etc.). Silver is a good compromise for casual players but for regular dosages of "fun", gold is the way to go IMO. :)

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

I'm looking for something new to play (got bored of WoW for now)

Try Everquest 2 for a different experience though I must warn that the pace of that game isn't for everyone.

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

> i got this code form the internet where it can delete a file.but when i tried to use it n my own java program it does not work anymore.it always returns 'Could not delete file'.

First thing, never have empty catch blocks in your code, ever, no matter what. Second, your code doesn't handle special conditions where failure to close a stream will result in other streams remaining unclosed thereby leaking file handles. Third, if the file "person.txt" is opened in Excel or some other program, it will allow you to read data from it but block deletion since the file is already open by some other application.

For first point, make sure you always log exceptions or at the very least print stack trace. For the second point, if you are using Java 7, you can write:

try (BufferedReader in = new BufferedReader(new FileReader(f)); PrintWriter out = new PrintWriter(tmp)) {
    String s;
    while ((s = in.readLine()) != null) {
        out.print(s);
        System.out.println(s);
    }
}

And your streams will automatically be closed after the "try" block completes.

For third, make sure *no* other program is currently reading or has the given file open.

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

A label in Java can be used for regular code blocks and IF statements along with their regular usage with looping constructs. So you can have:

something:
if (i == 1) {
  method();
  int j = method2();
  if (j == i) {
    break something;
  }
}

Similarly with blocks:

something: {
  method();
  int j = method2();
  if (j == i) {
    break something;
  }
}

Do keep in mind that "continue" can only be used from within looping constructs considering that's the only place it makes sense.

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

We have been recently hit with a spam wave which resulted in the admins banning a few IP ranges to stop the onslaught. It's a possiblity that your IP address was caught in the cross-fire and hence shows the given message.

Once the admins are online, they should be able to have a look and bring things back to normal. Nothing serious here. :-)

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

What I ment was that in each project (both the lib and the main program) do I have to have that com.stuct package and that Global class with var?

No, having it in one place would be fine. Let's suppose that you have the `Global' class in the library project (called for e.g. jlib). To then use it in your other project (called jAwesome), you'd:
* Import the Global class in any class of the jAwesome project
* Make sure your dependencies are set right. If you are using an IDE (e.g. Eclipse), you can make a project depend on another project
* If you are compiling from command line, make sure you use the -cp switch of `javac` command to specify the jar file of the library project.

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

Look into the "connect()" method of the `Socket` class. Basically, you create a blank socket and ask it to connect to a given destination with a specific timeout. This connect() call blocks until a connection was made or timeout was encountered.

// untested
final Socket sock = new Socket();
final int timeOut = (int)TimeUnit.SECONDS.toMillis(5); // 5 sec wait period
sock.connect(new InetSocketAddress("host", 8080), timeOut);
Majestics commented: ............................................................................................. +8
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I'm not sure why you say that it "doesn't teach programming" given that it helps kids create fun little games which *does* require programming. More importantly it stresses on "logic" which can help kids create games in any other languages they would learn in future.

But if he comfortable with the new C# book, more power to him. Good luck! :-)

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

Dani is furiously working towards rolling out brand new Daniweb website written from scratch. You might want hold off your suggestions and bring them out when she is again in "accepting new feature requests" mode. :-)

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

Al Sweigart has an entire site and a book dedicated for game programming for kids. You might find this and this worthwhile.

As someone who has mentored both colleagues, junior developers and "want to be programmers", I'd recommend against "industrial strength" languages like C#, Java, C++, C etc. unless the kid feels he is comfortable with them. The *most* important thing when it comes to teaching programming is to get them in the "groove" rather than forcing them to learn "popular" programming languages. If your kid craves for more challenging/unique stuff, there's always the "haskell for kids" series by cdsmith which your kid might find enlightening.

Languages come and go, it's the concepts which stay. BTW, as an Indian, it feels good to see that parents are taking the initiative to introduce their kids to the crazy and interesting world of computers. :)

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

Ah, no particular reason. I was assuming the actual code has a real iteration over some items (as opposed to while true) in which case it's better to put the interrupt check in a separate IF statement inside the outermost loop.

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

From your first post, drop the extends Thread. If you want to submit a task to the pool, just make your task implement Runnable or Callable instead of extending Thread.

Also, a clarification - you are not cancelling "threads" but cancelling the "future". This is a big difference because if you use a fixed thread pool, a single thread will be used to execute multiple tasks and in turn return multiple futures.

Now, the simplest solution to actually stop a computation is to "listen" to interrupts.

public Task call() {
  while (true) {
    if (!Thread.currentThread().isInterrupted()) {
      // do something
      System.out.println("Hello world");
    }
  }
  return this;
}

The reason it works if you put sleep() is because, sleep is a blocking call which throws an interrupted exception when the sleeping thread is interrupted from outside. Though sleep works, it's not a good solution because it most probably toggles the thread state as opposed to just checking the interrupt flag.

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

The "build" folder shouldn't be part of your JAR file. Also, make sure that the KTest2 class has a main (entry point) method.

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

Have you checked the JAR file to ensure the manifest really is there? Make sure you are invoking a JAR command which "packages" the manifest file in the JAR. Ensure there is a newline after the last manifest attribute. Read this. Follow up if it still doesn't work.

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

I don't think this solves anything if your purpose here is to "cancel" the underlying computation. Create a task which continuously (while true) prints "Hello world" to the console (STDOUT) every second and set the timeout for that task to be 5 seconds. You'll notice that even after the task has been cancelled, you still get "Hello world" printed to the console. Why? Because, cancel() on Future *attempts* to cancel the underlying computation. Sure, you have expressed your desire that you don't need the future, but this doesn't mean that the "underlying" processing has stopped.

To summarise, unless your "task" is thread interrupt aware, calling cancel(true) has no effect on the computation. If you are iterating over a *large* number of element, with some processing done for each element, you are in luck since you have time window for polling the interrupt status of the thread. If you are invoking a blocking call like doing traditional I/O, you are out of luck and the only way would be to forcefully close the I/O stream/handle.

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

> After getting rid of some running plugins, i got it running. But......The thing is, i am the only active one there..... Anyway Thanks....

As already mentioned, you need to just hang in there and greet anyone who joins in hope that it might spark an interesting conversation. IRC works a bit different from things like Google/Yahoo/Facebook chat. :)

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

AFAICT, the web client works across all browsers (assuming you have no "blocking" plugins installed). Give this link a try and let us know how it goes.

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

My bad, I meant javac. What does javac -version print? Also, does it work when you use javac -source 1.6 -target 1.6 compute/Compute.java compute/Task.java ?

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

We need more details. What is the command invoked to "build" the JAR file? Which version of Java do you have on the Linux box? This error normally comes up when you try to compile code containing generics using pre 1.5 source level.

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

@dheaven:

Having looked at your previous posts, I'm assuming that you are either affiliated with the blog in consideration or own it. Posting self links is not recommended here and is seen as promotion. If you want to redirect users to your blog/help them, link your blog in the signature and refer them to it rather than having links as the post content.

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

Done and done.

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

Deleting thread would be against the forum rules. If you want, I can turn this into a OS or a IDE/Editor thread. So, which one do you want it to be?