|
ammu23 wrote: I cant execute my java program which is in MS Dos Batch File format.It just blinks when i click on it.What should i do to execute it.
Well you have just repeated the question that I asked you to clarify, because it makes no sense. How can a Java program be "in MS Dos Batch File format"? Either you have a Java program which fails for some reason, or you have an MSDos Batch File which does something similar. Try to explain exactly how you created this program - if it is Java then do you have the source code, and if so can you run it through your debugger?
MVP 2010 - are they mad?
|
|
|
|
|
Try calling the batch file from a command line rather than clicking on it to run it. That way, if you are getting any error messages being displayed when the batch file execution fails you will get a chance to see them.
Possible problems range from errors in the Java code through to not having the java exe in the path. There are too many possible errors to know what to advise until you find more information about why it's failing.
|
|
|
|
|
I want to return an XML document via HTTP. Here is the code:
package gmit;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class XMLServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{
response.setContentType("text/xml");
File file = new File("../webapps/xml/WEB-INF/etc/flights.xml");
FileInputStream in = new FileInputStream(file);
PrintWriter out = response.getWriter();
int i;
while ((i = in.read()) != -1)
out.write(i);
in.close();
}
How do I execute this code? The goGet() method takes two parameters but I don't know what the parameters are.
|
|
|
|
|
numbskull20 wrote: The doGet() method takes two parameters but I don't know what the parameters are.
Is this not your code?
MVP 2010 - are they mad?
|
|
|
|
|
No, I got it from a book. Murach's Java Servlets and JSP.
|
|
|
|
|
numbskull20 wrote: No, I got it from a book. Murach's Java Servlets and JSP.
Maybe you need to spend more time reading the book?
MVP 2010 - are they mad?
|
|
|
|
|
|
numbskull20 wrote: Grest help. Thanks.
I'm not sure whether your response was sarcasm or not but just to clarify my position, which I may not have made clear. Your code (taken from a book that I have not read) contains the following lines
public class XMLServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{
response.setContentType("text/xml");
You then state that you do not know what the parameters to the doGet() function should be. If the book does not explain it how can anyone here?
MVP 2010 - are they mad?
|
|
|
|
|
Plus this is a web question so of it goes to web development forum.
|
|
|
|
|
I think that's arguable, after all it is Java source.
MVP 2010 - are they mad?
|
|
|
|
|
Hello Friends
I have to read a file in binary mode as we do in c++ by using ifStream.
Is there any way in java to do that?
Thanks In Advance.
Yogesh
|
|
|
|
|
You should really make more use of the tutorials[^] for basic questions. Java, like most languages, supports I/O from basic byte/byte-stream right through to Object serialization.
MVP 2010 - are they mad?
|
|
|
|
|
Hello Friends
I created a project in java tht Encrypts and derypts a file.But first of all I want to know Is that Possible If i use the same code in C++ way to encrypt and decrypt the same file thru java Code.
Another Question is Can I convert Directly my java code to C++ file?
Thanks & Regards
Yogesh Sikri
|
|
|
|
|
1. Given the same key, file, and algorithm then yes.
2. Depends on the implementation of the Java code.
|
|
|
|
|
Encryption in C++ is not quite as simple as in Java but it can be done. You may find articles about it either here or via Google. See also my response here[^].
MVP 2010 - are they mad?
|
|
|
|
|
In college, I was given an assignment, to use these methods to sort a list alphabetically from the args array from a cmd prompt input from the user.
I can take in and print out the list, sorted, however, when I sort it, it doesn't print correctly, eg 1 2 3 4 5 might print as 1 2 4 3 5.
My source code can be seen here:
[MySortProgram Source Code]
|
|
|
|
|
You're forgetting to reset maxSoFar, and Bad Things happen when i == 0
|
|
|
|
|
Can you explain how to "reset" maxSoFar? I thought i just gotta swap the index into temp and then change the small to that index and then the temp to the max so far?
What will happen when i reaches 0?
|
|
|
|
|
bmnot wrote: I thought i just gotta swap the index into temp and then change the small to that index and then the temp to the max so far?
Yes, that is right.
But what you're doing now is remember the index of the global max of the entire array, instead of just the part that you're supposed to be looking at. The next iteration you will need the max of a smaller part of the array, not the global max.
The Bad Things that happen at i == 0 are also partially a result of not resetting maxSoFar, it will not search for a new max (since 0 is not smaller than 0), and then swap them anyway. If you found the correct max (maxSoFar = 0 be cause it's the only one you can still scan) then swapping 0 with 0 has no effect, but you'd still have the old max, so strange things happen.
|
|
|
|
|
Okay, I understand the maxSoFar thing now, I'm a bit of a n00b to programming and REALLY appreciate this help. I'm doing it in college and have only been at it about 6 weeks.
Also, how do I get around this i = 0 problem? Cause I've noticed that when I input the strings, they end up in an order that is most definatly not alphabetically!
|
|
|
|
|
Well you could change the ending condition of the outer loop to i > 0 , that should work
|
|
|
|
|
But then would that not stop before the 1st array (list[0])?
I've done this and the list is completly messed up! I've re-upped the code, here is the link.[Source Code]
Could you compile and test it please and see if you can find what the problem is?
Also, as far as programming goes, is this code "messy"?
Thanks,
Niall
|
|
|
|
|
Now you're resetting maxSoFar too often
Oh this is not messy.. just wait until you have to implement things like chordal graph colouring...
About the first element - yes, it would stop before it. But you wouldn't move it even if you did not stop before it. The only candidate for swapping would be itself, and that's not very useful. Also you could see it like this, all following items are already correctly sorted (because of the selection-sort invariant which says that the "last" portion of the array is already perfect), and you only have 1 item left, it must already be in the right place, since it can not go anywhere else. It's not a problem if list[0] was not the smallest element in the beginning - it will be the smallest now (so apparently it got swapped already)
|
|
|
|
|
god i'm confused now!! Where should the maxSoFar go then?
haha. Can you give me some examples maybe with some code to show me? I'd much appreciate it.
Thanks,
Niall
|
|
|
|
|
Maybe so, but then I'd pretty much give you the answer wouldn't I
Seems like cheating..
On the other hand, it's on wikipedia anyway
Here is the code that does it the other way around (starting at i = 0 and finding the smallest element every time)
http://en.wikipedia.org/wiki/Selection_sort#Code[^]
|
|
|
|