masijade 1,351 Industrious Poster Team Colleague Featured Poster

Wow, you seem to have finally taken the hint. Good job. But, back to this code.

1) you should use (fileSize > counter) otherwise you will wind up skipping the last bit of data in the file.

2) read(byte[]) is not guaranteed to fully read the entire size of the array. It does however return the number of bytes read, so capture this value.

3) Make sure that you only write as much of the array as was read (see above). Otherwise you may be writing old data again (or at least null bytes, which is nearly as bad).

4) Increment the counter with the amount that was actually read (see 2) as well.

Edit: Except for the fact that this should not be done as a Scriptlet in a JSP. Makes much more sense to do this one in a Servlet.

PoovenM commented: Very impressive - you took out time to read that guys code; awesomeness :) +2
masijade 1,351 Industrious Poster Team Colleague Featured Poster

This is just so wrong on so many different levels.

First of all, neither a servlet, nor a JSP has any business, what-so-ever even attempting to open a socket, much less a serversocket.

You do realise that a JSP/Servlet is meant to be run mulitple times, right? And a serversocket can only be opened once, and every other attempt to open it will cause a bind exception, right?

You also realise that accept blocks until a connection is made, right? And since (I assume) it is suppossed to be the applet that makes the connection, and accept is called before enough of the html is served to the browser to even know that it is suppossed to start an applet, that is impossible for the applet to make the connection, therefore, the JSP never finishes, your browser neven gets a complete html, and everything deadlocks, right?

You either need to write a complete, standalone server for the ServerSocket (and whatever service it is suppossed to provide), or you will have to write a class that will be kicked of in the Application context by a ContextListener, to provide this service.

peter_budo commented: I always learn something new from you... +6
masijade 1,351 Industrious Poster Team Colleague Featured Poster

I would have to assume that it is coming from the tee (and that error will only occur on the file handle being read, not the filehandle being written), so I have to assume that the find command is not finding anything. But that also seems strange, as I believe that should have the same effect as doing

echo "" | tee -a filename

which as far as I know should not produce an error. Are you certain the error is happening here.

That error also occurs when a quoted string is not ended properly in the script so the shell continues reading the script as a part of the quoted string, but reaches the end of the file before reaching the end of the string as follows:

#!/bin/sh
var="this is an unfinished string
cat filename  # never gets executed as the shell still considers this a part of the string above
# here the script ends and produces the error given above as the string is not ended
masijade 1,351 Industrious Poster Team Colleague Featured Poster

Google for a third party program for doing this, but it is not recommended. Why take a language meant for creating cross-platform software, and take that exact advantage away by turing the product into a native executable which can then only be run on one platform?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Whether to use serialisation, and whether to use a DB, are not mutually exclusive. There is no reason why you cannot store a serialised object in a DB.

What, exactly, is you want to know? If it is how to se a DB, then consult the JDBC tutorials at Sun first.

parthiban commented: Thanks +2
masijade 1,351 Industrious Poster Team Colleague Featured Poster

Thias sort of thing should not even be attempted by an applet (in most cases). This sort of thing expressly forbidden in most security policies. You may use a signed applet (Google that) and it will allow you some access. To get "full" access, the user using the applet would have to change his security settings (in the JVM not the browser, i.e. he won't find a "friendly" GUI element to do it with).

ajay_tabbu commented: this is really helpfull. +1
masijade 1,351 Industrious Poster Team Colleague Featured Poster

Well, if you don't know how to do it from the command line, you shouldn't be using an IDE yet. And, that you didn't know that this had to do with the classpath, is another good indication that you shouldn't be using an IDE, yet.

Go to this page (http://java.sun.com/docs/books/tutorial/index.html) and do the tutorials there, starting from "Getting Started" down through "Deployment".

As far as setting the library path (which is how most IDEs refer to the classpath when it comes to executing, they refer to the classpath as the buildpath when it refers to compiling), I assume your IDE came with some documentation?

Ezzaral commented: agreed +3
masijade 1,351 Industrious Poster Team Colleague Featured Poster

Google "Java file upload", then rather than writing the stream you get from the request to a file, write it to a DB column using the setAsciiStream, setBinaryStream, or setCharacterStream of PreparedStatement, read the API for that method and the Sun Tutorials (or the MySQL documentation which comes with complete examples) for JDBC in general.


And use a Servlet, not a JSP. And regardless of which one you use, the DB stuff should not be a part of it. Rather that should be in a Bean (or some other external object), not the Servlet or JSP itself.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Honestly, I'm getting more and more disappointed every time I see someone say, "I'm not doing your homework for you." and I'll tell you why...

I've been a programmer for many years now. I've seen many horrible text books, on top of equally horrible professors there are out there - and I've even experienced many myself. Yes, there are going to be those students that really don't want to try, and will go to any length to cheat in order to get by.

And those that want to try will actually try first. Then, if they don't succeed on there own, they will usually use Google first. Then, even if they didn't use Google, they will come here and ask how to do something, providing info about the methods they've already tried. When tey come here and simply provide their homework assignment text (many times nearly word for word), they are simply looking to cheat.

Guess what? Not surprising that they're going to fail, and there's nothing that can be done about that. They will go elsewhere to get what they're seeking. However, there are those who are honestly stuck - even if it's right out of the gate, and they don't know how to start - their books and professors aren't helping, so they turn to the Internet for guidance. This is what help forums are all about: Help. Many people need examples in order to understand how things work - or at least the pseudo code to …

masijade 1,351 Industrious Poster Team Colleague Featured Poster

So write some. If you have problems, and a specific question, then come back and we will help, but for God's/Allah's/Buddha's/<insert additional diety names here>'s sake, Do Your Own Homework, or at least make an attempt at it.

~s.o.s~ commented: :) +21
masijade 1,351 Industrious Poster Team Colleague Featured Poster

No.

Ezzaral commented: Agreed +3
masijade 1,351 Industrious Poster Team Colleague Featured Poster

The problem is quoting. The "last name" should be quoted in the SQL with single quotation marks ('). To avoid errors like this in the future (and to prevent SQL injection attacks), use PreparedStatement and its setString method. See the API for more information.

Ezzaral commented: good advice +3
masijade 1,351 Industrious Poster Team Colleague Featured Poster

The same response I gave in the JSP forum for this question. Move all of this scriptlet stuff out of the JSP into one, or more, beans.

iamthwee commented: You can tell em but they don't listen. +9
masijade 1,351 Industrious Poster Team Colleague Featured Poster

I have the same problem. Try to copy MySQL connector jar file to
%JAVA_HOME%/jre/lib/ext/

Bad, bad, bad. Never copy anything to the lib/ext directory of the jre. Learn how to use and set classpaths properly. If he has the proper jarfile, and places it in the WEB-INF/lib directory of the web application he is trying to reach, the classes will be found. If they are not, he has done something wrong. Either copied it to the lib directory of the wrong application, not copied the right jarfile, or, maybe, somehow or another, changed the tomcat configuration so that it does not look there. Sorry to say it, but all of those things are "his problem", and copying anything to the lib/ext directory is not the answer, regardless of whether or not "it works".

peter_budo commented: I agree. "Never copy anything to the lib/ext directory" +5
masijade 1,351 Industrious Poster Team Colleague Featured Poster

Well, let's just pick a braod topic, say tell me about, and then wait for specific detailed information about our nearly meaningless question, shall we?

Do a little research until you have at least a general idea of what it is you want to do, Google and standard wikipedia are both good starting points, as is your local library. Then hammer out an action plan, and, at least, a loose design plan, and start coding. When you then, have a specific question, come back and we will be glad to help, but we are not going to do your research and/or work for you.

Ezzaral commented: Agreed +2
masijade 1,351 Industrious Poster Team Colleague Featured Poster
// code related to antivirus

There I wrapped "code related to antivirus" in code tags.

Try Google, please.

If that doesn't work, try asking specific questions, not "give me teh codez".

peter_budo commented: I will donate that antivirus ;) +7
masijade 1,351 Industrious Poster Team Colleague Featured Poster

Bind a ServerSocket. If it fails to bind then abort the startup. Since a ServerSocket can be bound only once, only single instsances of the program will be able to run.

And before you ask, no. Just because you bind a ServerSocket, does not mean you are open to network traffic. That only comes into effect once the program starts "listening" to the port with accept().

~s.o.s~ commented: Nice. +24
masijade 1,351 Industrious Poster Team Colleague Featured Poster

And you got it in the first post.

iamthwee commented: too right! +11
masijade 1,351 Industrious Poster Team Colleague Featured Poster

Look at the different Focus and FocusListener classes. I haven't done something like this, myself, yet, but I would assume that you will finds the info there.

Specifically (now that I look at it):
http://java.sun.com/j2se/1.5.0/docs/api/java/awt/FocusTraversalPolicy.html

Ezzaral commented: Helpful info +2
masijade 1,351 Industrious Poster Team Colleague Featured Poster

How To Store Image In Oracle

Use a BLOB.

And Fetch Using Jsp Java Beans.

Use JDBC.

Ask a general question, get a general answer.

Try and start coding something (search for and read some tutorials and definately read the API for the involved classes), then when you are stuck, and have a specific question, then please, come back and ask.

peter_budo commented: How true..."Ask a general question, get a general answer." +6
masijade 1,351 Industrious Poster Team Colleague Featured Poster

The problem is, you have declared an instance variable s.

Then in initializeStuff you want to give it a value, but what you really did was declare and define a variable local to initializeStuff rather than defining the instance variable.

Change:

void initializeStuff() {
        String s = "aaa";
    }

to

void initializeStuff() {
        s = "aaa";
    }

or

void initializeStuff() {
        this.s = "aaa";
    }
fowlergod09 commented: His reply was a great help. Thankyou +1
masijade 1,351 Industrious Poster Team Colleague Featured Poster

Do Your Own Homework.

Salem commented: You tell 'em +6
thekashyap commented: Can't beleive they have so much pocket money now-a-days.. ! +2
masijade 1,351 Industrious Poster Team Colleague Featured Poster

Maybe you're looking for a splash screen. Check out this article:
http://www.javaworld.com/javaworld/javatips/jw-javatip104.html

Edit:

And that "give me the idea immediately" is extremely rude, whether prefixed with "please" or not.
We are not here to serve you.

~s.o.s~ commented: Well said, maye the kids nowadays ought to learn some manners - ~s.o.s~ +14
masijade 1,351 Industrious Poster Team Colleague Featured Poster

I have the feeling that what he is doing, is adding the Vector as a Vector, then clearing the Vector, assigning new values, and adding it to the Hashtable again.

@OP: If this is what you are doing then of course the values are changing for "both" Vectors, because there is only one of them. When you add something to a Hashtable, you are not adding a copy of it to the hashtable, but rather are adding a copy of the reference to the object (in this case a Vector) to the Hashtable. If you then turn around and change the object that was referenced (in this case the Vector again), then you are changing the content for the object referenced in the Hashtable as well, since it is the same object.

You need to create a new Vector, rather than editing the Vector that you have already added.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

dont you think if he wants to go in graphics designer field y in the world he wants to learn java? all he want to do is do his homework.

It doesn't matter if he is interested in it or not. If his major requires a course of this nature, then he has to do it.

In the real world you can't just simply say "I don't like that part of my job so I simply won't do it."

That would be really great. Think about it. One of the workers in a construction company doesn't like to use screw drivers so he simply places a sticker that looks like a driven-in screwhead at every spot he was suppossed to place a screw. Then your house falls apart. But don't blame him he just simply wanted to get his work done and didn't like that part of the job.

Wonderful.

Edit:

Also, whether the major demands it or not is irrelevant. He took the course, he needs to either do the work or take the hit to his record by either failing or withdrawing. Cheating is not and never was the answer. It will catch up to you sooner or later.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

No. Java is pass-by-value and pass-by-value only.

When you pass an object rather than a primitive, you are not actually passing an object. What you have is a variable that is only a reference to an object, and when you pass this, what happens is that the reference value is copied, and the copy is passed. Now you have two references to the same object.

Because of this you can use the methods of the object and see the result outside of the method, but changing the variable inside of the method will have absolutely no effect outside of the method.

You should probably read the following two articles. The second one is the one that is important, but you probably won't understand the terms they use if you do not read the first one.

http://www.javaranch.com/campfire/StoryCups.jsp
http://www.javaranch.com/campfire/StoryPassBy.jsp

BestJewSinceJC commented: A very old post, but a great explanation. I keep seeing people have this problem too... +4
masijade 1,351 Industrious Poster Team Colleague Featured Poster
/*
 * You should give your class a package as it is truely frowned upon these days
 * to place your classes in the "main" namespace.
 */
 
import javax.swing.*;

public class pro1111 {

  public static void main (String [] args) {
    /*
     *  I assume you have your own TextFileInput and TextFileOutput
     *  classes as these are no part of the JDK.  And if so, you have not
     *  imported them.
     */
    TextFileInput in = new TextFileInput("Dates.txt");
    TextFileOutput out = new TextFileOutput("Dates1.txt");
    String line = in.readLine();  // I also assume these classes handle the exceptions
    while ( line != null ) {
      // StringTokenizer is a bit old fashioned.  You should probably look into
      // Scanner and or String.split().  But what you really want is to simply read
      // the entire String and not break it down into pieces.
      StringTokenizer st = new StringTokenizer(line, "/"); 
      int monthNumber = Integer.parseInt(st.nextToken());
      int day = Integer.parseInt(st.nextToken());
      int year = Integer.parseInt(st.nextToken());
      out.println(monthNumberToName(monthNumber) + " " + day + ", " + year);
      // You should also be storing the dates here rather than simply printing them
      // out.  Probably with an ArrayList.  Then, after you have them read in and
      // stored somewhere, you can start using another loop or two to compare them
      // and get them into the proper order.
      line = in.readLine();
    }
  }
   
  private static compareDate(string date1, string date2) {
    // Why do you designate two dates (in String format and it should be String not
    // string) and …
iamthwee commented: well said (iamthwee) +5
masijade 1,351 Industrious Poster Team Colleague Featured Poster

That's because the perl script is running on the server side, so you simply attemtped to open notepad on the server, rather than the client. If you want to open something on the client, then you need something that is actually executing on the client such as JavaScript, or ActiveX controls, etc.