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

If you plan on making your Vector3 class immutable, you have no option but to "return" Vector3 from your "multiply" method.

Without the restriction of immutable classes, it would be as simple as modifying the state variables of that given instance; you don't even need "v3".

public void multiple(int x) {
  this.num1 *= x;
  this.num2 *= x;
  this.num1 *= x;
}
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

What do you mean by "call back"? The simplest and the logical way would be to change the return type of your method to "Vector". Some other approaches would be to pass in a reference to Vector and update the Vector in your "multiply" method or have a static member in your main class but then again not recommended.

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

Pass a folder name (relative or absolute) to your application using the command line arguments/some other means, create a file object for that folder, invoke the "listFiles" method on that File object which returns a list of all the files (and directories) in that directory, traverse these files and do what you have been doing till now.

final File dir = new File("some/dir");
for(final File imgFile : dir.listFies()) {
  // assuming the directory contains only images
  doSomethingWithImgFile(imgFile);
}

If your directory doesn't contain only image files, look into the "listFiles" method which accepts a filter. Read Javadoc for more details.

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

Does garbage collection occurs in PERM Area of Java Heap ?

AFAIK, yes.

This aspect doesn't come into play a lot when doing regular development and using already existing libraries but becomes apparent when you implement custom classloaders and manage class loading dynamically.

One e.g. would be Tomcat servlet container. Let's assume that Tomcat creates a separate "classloader" for each web application deployed. If out of the many running web apps if one of the web apps is stopped, the corresponding classloader goes out of scope along with the objects/classes created/loaded using that classloader. If now, for some reason a permagen GC is triggered, the classes along with the classloader would now be garbage collected. If you run the JVM with the -verbose:class switch, this can be easily confirmed by the log message "Unloading class somepkg.xxx".

kvprajapati commented: :) I'm looking forward to seeing more great stuff from **your** blog posts. +12
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

The simplest solution would be to use the "startsWith" method of the String class and inspect each and every dictionary entry whether it starts with the user input. But this approach can become unwieldy if the dictionary has a *lot* of entries since it means scanning the entire dictionary for every character entered by the user. Look into the "trie" data structure which is meant for exactly these kind of use cases if the "startsWith" solution doesn't suit your needs.

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

IMO implementing hybrid protocols has always been a problem.

Just thinking out loud here but it seems that in your case the server has no way of knowing when the "file transfer" has completed and the user now wants to pass across a string message to the server. Also, I don't think the "while" loop at the server end would "terminate" unless the client socket output stream is closed (which would in turn trigger -1 being read thus breaking the loop).

My suggestion would be to implement a small protocol between the client and the server in which the server knows "how much" binary data the client would be sending thereby giving the server a logical condition to break out of the loop. An example of this protocol would be (all messages termiated by line breaks):
BIN:1024 (client would now initiate a binary transfer of content length 1024 bytes)
TXT:1024:UTF8 (client would now initiate a text content transfer of size 1024 byes and encoding being UTF8 -- which would be anyways default in case it is ignored)
DIE (client has decided to quit; the server can now safely close the client socket)

An alternate solution would be to use RMI in case the client/server would always be JVM bytecode compatible and the use of raw TCP sockets is not a requirement.

EDIT: As far as your code is concerned, I'm personally not a big fan of exposing variables to a greater scope than …

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

Glad to see that interacting with fellow C#ers on Daniweb has helped you excel in your assignment. If you ever think of giving back to the community, just help out others in need in the C# forum. It would increase your knowledge along with helping out others who are struggling with concepts/assignments. Not to forget that we are more than happy to have someone become a regular here. ;P

Good luck. :)

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

hi i want send an url to the blackberry mobile..,the user should not understand the url from which server he is downloading..,Is it possible?If yes How?

You can try to hide the URL for a casual user by using a URL shortening service like http://goo.gl/ . If you can't use public services, you can create a simple servlet which mimics these shortening services. This would result in the user not having the original URL but the miniature version which redirects to the original one.

If your end goal is to *completely* hide all the details, you can again set up a servlet which takes the real path of a resource and streams it to the client. For e.g. this servlet would be responsible for mapping http://yoursite.net/img/x3434 to a "sad-smiley.jpg" etc.

If you can extrapolate on the kind of "hiding" you are looking for, maybe I can suggest more solutions.

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

Showing the values of "batchFilePath" and "params" when this code execute would help. Anyways, I personally don't like the "parameter" concatenation part of the code since white-spaces or special characters in parameters might mess things up. Why not just pass the batchFilePath and parameters as it? For array concatenation, read this.

Also, is this "batchFilePath" just the file name? Or is it the complete path?

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

TIL about custom keywords in Firefox. Mind == Blown :-)

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

You need to tell us:
* The directory structure
* The command you are executing on the command line

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

You might find a similar thread helpful.

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

What code are you using to "spawn" the batch file in Java?

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

i got a such type of error in junit+struts2 +spring

If you are "testing" your web application as opposed to individual Java components (which is what JUnit does), look into frameworks specifically tailored for those needs. IMO, a proper abstraction here would be to use Cactus or HttpUnit for testing your "web" requests. Use JUnit if you want to test your *individual* Java components, not the entire HTTP request/response cycle.

After a bit of searching, I found a tutorial which uses Cactus for testing a Struts web application which you might find useful.

peter_budo commented: Useful link, thanx +16
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

You can place the JAR file anywhere, just make sure you provide the full JAR path when specifying the classpath for the java command.

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

The PATH environment variable is typically used by OS to find executables so that you can simply do "javac SomeFile" instead of "/usr/bin/jdk/javac SomeFile". The classpath is a Java specific property which tells the VM where to find all the necessary class/JAR files. (There is also a CLASSPATH environment variable which again shouldn't be messed with; there are better ways around it like setting classpath when firing javac or java).

In your case, you simply need to "set the classpath" when "invoking the java command". E.g. java -classpath mysql.jar:yourapplicationjar pkg.Main

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

Like already mentioned, tell me how do you exactly launch the application right now. Use the template provided in my previous post to launch your application by setting the appropriate classpath.

~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

Do you have the GNU Regex Java library jars in your runtime class-path? It seems that the JAR which you got in turn depends on GNU regex library so having a JAR for the same in your classpath is a requirement.

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

i know the method will be the same and both will essentially do the same thing. but why two ways to initializing arraylist?

The second form is called "programming to an interface". Any further use of "myList" in your code would adhere to the "List" interface and as such would allow you to change the implementation class by just changing a single line.

This distinction plays an important role when it comes to designing an API since you wouldn't really want to bind your users to a specific implementation which might change in the future. Establishing a common interface (by using either Java interfaces or super-classes) helps when it comes to re-factoring and writing unit tests.

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

How are you launching the application? Make sure that the driver JAR is listed in the classpath when you launch the application and you should be good to go.

java -cp app.jar:mysql.jar your.pkg.MainClass

Also, never ever mess with your default JDK installation. If your application requires a third-party JAR, supply the same using the -cp switch when compiling and running Java programs rather than "pasting" JARs to the JDK directory.

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

You can't directly execute a Java file i.e. pass it to the 'java' process and execute it. You need to first compile it to a class file which is in turn passed to the 'java' command. Also, read this article which lists the pitfalls when using Runtime.exec.

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

Not sure if any of you have read this, but heavy stuff there. It's so sad that someone had to go through so much his entire life. The note, yet again, shows us an unseen facet of this world we live in.

RIP Bill Zeller :`(

PS: For those who don't know, Bill was the developer of "Graph Your Inbox" extension.

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

By statements do you mean "code"? If yes, then JProfiler which is included with JDK 6 can be used for CPU profiling and at the end of the run gives the total time taken by each method till now. Search around for CPU profiling JProfiler.

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

I'm not really sure what the question here is; have you decided on making a web app and need help with that or are you still trying to come up with a solution? (i.e. it can either be a web app or a standalone app)

Also, what do you mean by "I need source files to customize the feature"?

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

But the problem is how to place all these files in client machine drives(C:/test/ or D:/test/) from ftp through web server...

The way you normally download files using the HTTP protocol and browser? You provide the customer a "link" to your FTP server file, the client clicks on it, you stream the data from the FTP server to the client via the web server etc.

or give me some ideas how to integrate ftp features in web browser????

I don't think there would be any way a client would be able to directly access the FTP server without providing the client authentication details.

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

Then follow the instructions specified in my first post of this thread. You'll probably want to use a FTP client library (like Apache's) in your web application to list all the files and give the option to the customer to download it. All the heavy lifting (listing FTP server files, downloading them) would be done by the library and your application would just act as a mediator.

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

Ask the client to install an FTP client like FileZilla. Then downloading files is just a matter of dragging from the right pane (FTP server) to the left pane (client directory). If that's not possible (asking customer to install FTP client), then the approach mentioned in my previous post in the way to go (at least doesn't make any assumptions on part of the customer).

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

Is it required that the user uses your web application for downloading files? If yes, then in that case, your web application would have to act as a "man in the middle" and stream data from the FTP server to the client.

For each client request:
* Retrieve the FTP URL and credentials and use an existing pure Java FTP library to connect to the FTP server
* Stream the retrieved FTP file to the client

Also, given the restriction that for a given HTTP request you can only allow the client to "get" a single file, to download all the files, either you'd have to create/show separate links for those files to the client or "pack" them together in an archive and serve it to the client.

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

SerializedThread is an inner class i.e. a class which depends on some outer parent class i.e. there is an association between your class Main and SerializedThread. When you try to serialize SerializedThread, it also tries to serialize Main class (which doesn't implement Serializable) hence the error.

A couple of solutions: make the main class implement Serializable (not recommended) or move the SerializedThread out of Main (recommended).

Alex_ commented: solved +3
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I've asked the mods to update the score board for us.

Done and done. Enjoy! :-)

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

Look into the Arrays.fill method for filling a specific array range with a given character.

But are you sure you have to do this? I mean, the "remaining" places in the array would change based on the change in buffer size. Just make sure you have got the requirements right...

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

Without the relevant code you are using plus a small sample of the input file, there is no way for me to assist you. Your best bet would be "debug" your code in an IDE like Eclipse or Netbeans and find out exactly what is happening.

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

Are you talking about re-using the character array for something else? If not, you've got me all lost there; post some sample code/pseudocode as to what that *something else* is and what you are doing right now.

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

how we can make sure those old characters are not there

You don't need to; read my previous post again. read() returns an int which represents the number of characters read. So even when doing your last read if your buffer isn't full, it really doesn't matter since you know "which portion" of the array contains the newly read values. If you'll look at the original snippet which I posted, I use a String constructor which creates a String object based on the "valid slice" of the array using this same return value of read() method.

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

If you've just started out with Java, give the forum sticky (by yours truly ;-)) a read. It's a decent intro (jam packed with information).

If you are looking to get started in a quick and dirty way, nothing beats the official tutorials (click on the Getting started link).

BTW, if your question/query was resolved, please click on the "Mark this thread as solved" button at the bottom of this thread. Good luck.

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

I'm not sure why you use the word "flush".

It goes like this: you create a char array (which initially contains all '\0' characters) and pass the array to the read method. This method fills up the "char" array with the characters read and returns the "number of characters" (n) read. You then utilize from the same char array `n' characters which have just being read. Rinse and repeat with the same array; the next read() call simply overwrites the old data; there is no flushing. Simple, no? :-)

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

In your source code i.e. Main.java file change class HelloWorld to class Main .

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

The name of your class should be the same as the name of your Java file i.e. Main.

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

I'm not sure what your issue here is because the snippet I posted would work *out of the box* without any modifications as far as the reading and writing part is concerned. I'd recommend reading the Javadocs for the read() method and writing small snippets to understand how it actually works.

~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

Users log in with their username and password (maybe I can somehow incorporate google OPENID)?

OpenId4Java (though I haven't used it personally)

What I'm not sure is if JSP/JSF gives the ability to parse HTML at a certain URL to see if it contains words

I think Apache HTTPClient should do the trick when it comes to reading HTTP URL's. For a high level analysis of HTML documents, look at this thread.

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

> how to store an image from one directory to another directory using jsp?

Can you explain a bit more on what exactly are you trying to do here?

> MoveTo or CopyTo method of java.nio.file.Path class.

AFAICT, Path class is JDK7 only which is still in its "preview release" stages.

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

A sample snippet:

private void process(final Reader reader, final Writer writer) {
    try {
        final char[] cbuf = new char[8 * 1024];
        int len = -1;
        while((len = reader.read(cbuf)) != -1) {
            // translate is your method which takes a string and translates/encrypts it
            writer.write(translate(new String(cbuf, 0, len)));
        }
    } catch(final Exception e) {
        throw new RuntimeException(e);
    }
}

Given that the buffering is done by the method, you need not even use a Buffered reader/writer; a File reader/writer should suffice.

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

As far as wrapping in an executable is concerned, I've heard good things about JSmooth. If that doesn't suit your needs, there is always Launch4J.

Of course, this assumes that you already have *everything* bundled up in a JAR file for which you can use Eclipse or Netbeans as already mentioned by James.

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

Is that a single character being read? If yes, that method is painfully slow. Like already mentioned, if readLine() throws OOME, it is possible that your entire file contains a single line. In that case, just use the read() method to read a specific number of characters rather than an entire line. 8Kb char buffer would be a good start.

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

But like we normally have static fields in a normal class (there are so many uses of them), why can't we benefit from them in their local class ?

Do you have any scenario in mind which can be handled properly *only* if local inner classes are allowed to have static members?

What is meant by "maintaining the state at the local class level" ? If its the state of the objects, how does allowing non-final static fields interfere with this maintenance ?

It does not interfere, it simply isn't required IMO.

But modifying the static variables of a class may well be desired in some cases ?

In *which* cases? Also, why would modifying the state of a class which should ideally be visible to the declaring method be desired?

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

Rebellious much?

The OP made the mistake of:
* Labeling the question as urgent which implies his/her question is more important than someone else's personal life
* Posting stuff which can't be tested by someone else (you see that database code, right?)
* Ignoring suggestions already posted or at least no responding to them

The aim of this forum is to provide answers and help folks learn. If all you want is to dump some 1000 line code and expect people to fix it, then there are paid homework services out there.

That being said, your post is unjust because it evaluates the entire thread based on the view point of the one asking for help but ignores the view point of those rendering it.

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

Here is wishing all the members of Daniweb (spammers included) a Happy New Year! :-)

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

Why do local inner classes not allow static variables ? The static fields of the classes could at least have been allowed access from the local method ?

Because static members make little sense when it comes to "local inner classes" since these classes belong to a scope as opposed to another class or a top level package. The "outer" world is not aware of this local inner class and always deals with instances of this class which are typically exposed via some sort of interface.

If there is any state that has to be maintained at the "local inner class" level, it can be easily done by doing the same at the enclosing method level. But probably the biggest reason might have to do with preventing the external entities from modifying the "class" level state of this inner class. Hence, only final primitives are allowed to be declared static when it comes to local inner classes.

class DamnIt {
    
    void damnIt() {
        class Test {
            static boolean bb = false;  // error; not final
            final static boolean b = false; // works
            final static Object o = new Object(); // error; not primitive
        }
    }    
    
}