Scanner myInput = new Scanner(System.in);
String input1 = "";
...
do {
input1 = myInput.next();
...
} while (....
Split the declaration from the definition and put the definition as the first line of the loop.
Scanner myInput = new Scanner(System.in);
String input1 = "";
...
do {
input1 = myInput.next();
...
} while (....
Split the declaration from the definition and put the definition as the first line of the loop.
In what way?
You do know, it is always helpful if you post exactly what it is that is not happening as expected (along with all compiler/error messages).
I'm sorry, but with some tests, it seems as though simply calling repaint after calling validate accomplishes your goal. (At least it did for me, although without it I also saw what you were experiencing.)
I would normally assume that a call to repaint() after a call to validate() would essentially be redundant, but seemingly not.
Just simply remove those symbols?
Really, those tags are only compiler "hints". They are there only for your convenience, as it is an indicator to the compiler that the following method is suppossed to override a method of an inheritied class. So, the compiler will check that it actually does so, and if it does not find a method, with that signature, in an inheritied class it will alert you that the method is not overriding anything, thereby preventing some possible polymorphism problems (i.e. you wouldn't using polymorphism when you thought you should be).
Add the java bin directory to your system path (not classpath) environment variable, or use the full path to java when executing it.
Uhm, Peter, what's this
authorsLastName = GetAuthorLastName();
;-)
However, with the way it's written (if it compiles at all) authorsLastName is an instance variable anyway (as it is not declared in the method simply defined), and that is probably not a good idea.
Otherwise, knowing exactly what SQLException you get would help. Post the rest of the message. I can almost guarantee, however, that it has to do with what GetAuthorLastName() is returning (or not).
cant u read?ACCOUNTING MAJOR...
And? You took the course so pass or fail, but on your effort. If you are not willing to put forth any effort, why should anyone else?
i dont have any background in this.this is the first and definatly the last cis course ill be taking ever.
Good for you. Now finish this one or withdraw.
i never realised this would be this tough and also i was tld they would be starting frm the very basic,which didnt happen.
Oh yeah! I can add so how hard can programming be, right?
plus i really dont think i nything is wrong with my attitude.i only just registered and this was my first post.
Other than resuesting someone to do your work for you, no there wasn't. Although, that is a pretty big no no whatever the course is.
Also..plz dont waste ur time,i asked fr help..not a favor.
Okay, we won't waste our time. But requsting someone do it for you is asking for a favor, not help. Asking for help is "Can you give some pointers on how to do this? Or point me somewhere where I can find that information for myself?" And posting the small, relevant parts of the code that are actually problematic. Do you see the difference between that and what you did?
Probably not.
A JSP is nothing but a servlet template that the web container parses and then compiles. That is even less applicable for an "exe" than servlets are.
Gods, I'm sorry, but what is this fascination everyone seems to have for turning cross-platform Java applications into a native application? If you want a native application code in something that is designed to produce a native application.
This is an SQL question, but what the heck
SELECT Description, SUM(Quantity) FROM
((Select Description, Quantity, PluCode FROM Sale_Mast_Data)
Union
(Select Description, Quantity, PluCode FROM Sale_Mast_Data_H))
Group By PluCode
Union usually "ignores" duplicate rows. So, if a row in "_H" is an exact duplicate of a row in the other you will only get one copy of it. If you "need" both, use "UNION ALL".
can anyone find my mistake in TrainingZone.java
Yes.
If they are writing everything (or even alot) in main, then they are not using Java properly. They are attempting to perform procedural programming using an Object-Oriented language. Ignore them.
Boss why are u soo rude??
I'm not rude, I just don't sugar coat things. If you are doing "whatever", I am going to say "you are doing whatever", I'm not going to "politely" hint at. People may not (and usually don't) like that, but they do respond to it (even if only to "salvage their pride").
i m not asking any body to solve this for me... OK
Yes you were, and are. Stop dissembling.
dont be rude Understand !!!!
See above.
U r on tech forum not in a corner shop....
You're lucky we're not, you'd only have been embarressed more because everybody would have heard me chuckling. Then you would probably get really made and attempt to do something about it, and I'd have had to teach you a different lesson.
Yes it will work.
The following also works (and should actually be done this way, now):
Vector<File> vector = new Vector<File>();
// populate vector
String path = vector.elementAt(i).getAbsolutePath()
So what did you not understand about his post? Read the API docs for KeyListener.
No. Write two methods. One that takes a String as an parameter, and one that takes an int as a parameter.
If you feel you must do it this way, then Google for "Java instanceof".
Use code tags please. And post the entire and complete compiler messages and/or exceptions you are getting.
Well, what do you have and what error/compiler messages is it producing? We are not simply going to do it for you.
SELECT name, SUM(liters), SUM(amount) FROM salemast GROUP BY name ORDER BY name
Well, we don't know what information you're including in your project either.
And this
I am programming using a Java Editor called "TextMate" on the mac and it often gives me errors that I don't get when I compile using TextPad on the Windows machines at school. Can someone check if this compiles on a Windows machine please?
is obviously a lie, as that code is guaranteed to fail to compile on every platform.
Because, of course, you're suppossed to provide all of that. Why else would he post here, if he still had to do any of it himself?
;)
Why don't you try it and find out?
I'm sorry, but you claim to be jumping into Java quickly, on your own, because you already know a couple of other languages. Well, I need to ask, what "other languages" do you know? Because in that thread you had no idea what "static" was and in this thead, the method you are looking at is extremely self-explanatory if you have nearly any real programming experience at all.
Yes.
I feel I need to qualify this remark.
That method should be final, because if someone extends your class, you will probably wind up with unexpected (and quite probably, for your class, catastrophic) effects if the method called from the constructor is overridden, as the overridden method would be called, rather than the original.
Look at your constructors. You have a constructor that takes as arguments
String, String, char, boolean, Course, Course
but you are calling the constructor with
String, String, char, boolean, int, int
See the problem?
The garbage collector is called by the JVM whenever it is needed, and possibly periodically, otherwise. The gc() method is simply a request to the JVM to call the GarbageCollector, but ionly that, a request. It does not guarantee that the GarbageCollector will be run, or, if it is, that it will be run immediately.
I haven't seen any tutorials for JSP , so I guess I will post this one link that I found.
http://java.sun.com/j2ee/1.4/docs/tutorial/doc/
http://java.sun.com/javaee/5/docs/tutorial/doc/
sed -n '$p' filename
With the exception of that second link which has mainly obsolete, and often times simply bad, tutorials/examples/advice. Roseindia is a blight on the Java world. Nearly everytime I see someone use some really bad practice on many forums and tell them not to do that, they often come back and say "But the tutorial I followed showed it this way!". And where did they get that tutorial ---> Roseindia. Nuff said.
Process p = Runtime.getRuntime().exec(browserCommand+" "+Url_name);
p.destroy();
Oh yes, and it also says this is the compiler/interpreter commands to run the program. Exactly where to I insert or paste this? :
javac SocketServer.java
javac SocketClient.javajava SocketServer
java SocketClient
You don't, if you're using Eclipse for this. Eclipse has it's own compile and run functions (which you, hopefully, already know how to use).
You use those commands if you are compiling and running the things manually from the command line.
Uhm, I'm sorry but you're getting your terms mixed up. What you refer to as declaring the method, is actually calling the method, and what you refer to as defining the method is both declaring and defining the method
public class A {
public static void methodB (String c) { // method declaration
System.out.println(c); // method definition
}
public static void main (String[] args) {
String c; // reference variable declaration
c = "Hello"; // reference variable definition
methodB(c); // a method call
}
}
1. Not urgent. To suggest that this "problem" is more important than anyone else's problem here, and we should just stop everything and "help" you, and you alone, is just plain rude.
2. Post your code and give a complete, but still brief, description of your problem (including all error messages with their stacktraces) and we may help you correct it, but we are definately not going to do it for you. To suggest that we freely do your (home)work for you is also just plain rude, and, more than likely unethical. If we did, how then would you have earned your money or education (not that you learn anything that way).
3. Stop with the sms speak. You have an entire keyboard in front of you use it. That stuff is just plain irritating and the fact that you're using it here says loads about your own work habits if you're so unmotivated that you can't even type the additional 3 (Oh My God 3 whole characters) to type the word please. Not to mention that not everyone who visits these forums is English, and sometimes have a hard enough time with the "real" language. You effectively exclude them everytime you type like that.
Calendar c = Calendar.getInstance();
c.setTime(date);
c.add(field, amount);
c.getTime();
Read the API docs, they contain more than enough information for this sort of thing.
As mentioned, however, you should not be doing this in a JSP. Scriptlets have no place anymore in a JSP. They are only still allowed so as not to break old JSP (i.e. backwards compatability) but you should not be creating any new scriptlets. Use a Bean.
So, someone did your work (or most of it) for you, but left you with a little nugget to complete yourself, and so now, you'll post here (without even removing the comments that clearly spell out that someone else did it) hoping that we do even that litlle nugget for you?
What a maroon! (Spelling intended.)
Do Your Own Homework! This is not a homework service. Normally I would have been more than happy to help point out what was wrong (not do it for you, though), but looking at that code, which so clearly spells out that you didn't do it, and that you're then posting it here, in that form, clearly spells out that you didn't even attempt to finish it, just disgusts me.
You could start by using the correct class
javax/swing/plaf/metal/MetalLookAndFeel
There is a file called classlist in the lib directory of the JRE which contains a complete listing of the classes in the JRE.
Use a Dialog.
I think masijade is refereng something like Tomcat How to on their home page that should be your first place to check if you do not have any books on this topic
Actually, the tomcat distribution contains all of the doumentation for that version. All you need to do is start Tomcat and you can read the stuff locally over http://localhost:8080
You invalidate the session. I would have to look up how to do it in JSP myself, but if your using a servlet, or a filter to accomplish the logout, then that is going to be Java code, and there it is
yourHttpSessionVariable.invalidate();
I hope your not starting every page with the equivalent of
HttpSession session = request.getSession();
// or
HttpSession session = request.getSession(true);
as those create a new session if no valid session already exists. That method should only be used on the initial login every other should use
HttpSession session = request.getSession(false);
this one will return null if there is no valid session.
The best place to do this is in a Filter, as there you can redirect the user to a login site (when no valid session exists), and once the user is logged in the Filter can then redirect back to the site the user originally wanted.
Set a socketTimeout on the ServerSocket and place the accept in a while loop so that it will "interrupt" every once in a while.
I.E.
ServerSocket ss = .....
ss.setSoTimeout(1000);
while(true) {
Socket s = ss.accept();
// do whatever you normally do with s (if it is defined);
// check whatever you want to check to possibly reassign your ServerSocket and then do so
}
He/She wishes!
Here we go again.
A JFrame is a top-level component. It can not be "added" to another. Use a JPanel.
1) Declare a package. You should never place anything in the "default" package.
2) The classname should be Capitalised.
3) The line you're refereing to makes no sense. First of all I believe you mean println
not printIn
(the first one is a lowercase L the second one, yours, is an uppercase I). Secondly that's a method and you are using it as a (I don't know what). Thirdly you're declaring it (private, protected, public keywords are only used in declarations) which makes even less sense. Thirdly, no matter what you wanted to do with it, the line is imcomplete (and basically just wrong).
4) You do realise that if (0 < 20)
will always be true, right? And, I definately would not want to wear shorts and sandals when the temperature is at least 13 degrees fahrenheit below freezing.
5) And I will assume that you simply haven't even started attempting to get input from the user yet, regardless of what that comment says.
That's now how I wanted to do it.
I know iwould have to do this
WriteTxt.setCMYKColorFillF(00, 99, 100, 00);
WriteTxt.showTextAligned(0 ,"Hello", 100, 20, 0f);WriteTxt.setCMYKColorFillF(00, 00, 00, 00);
WriteTxt.showTextAligned(0 ,"World", 120, 20, 0f);The problem with setCMYKColorFillF is that u can't specify what text of string you want to change.
It should be like WriteTxt.setCMYKColorFillF(00, 00, 00, 00, "World") or something like that.
Well, I'm sorry. There are a lot of things I don't like, that doesn't mean I don't have to do them. darkagn has it correct, create one of your own. Or, search the library you're using (I don't know which one it is) and see if there is a another method (or simply an overloaded version of the same) that does what you want, if not, as already said, implement a "convenience" method, yourself. If the method your using doesn't allow what you want, directly, then you aren't going to be able change that (you could always suggest an enhancement to whoever produced the library, though).
So, do you want Java or JavaScript? You seem to be using them interchangeably, which they are not. They are two completely separate things.
And, you are neither opening, nor closing, applications on the client (i.e. through the browser) from the server in either JSP or Servlets. All you are doing to "open" the app is sending the content. The browser is "opening" the app, but it could, depending on its content associations, do something entirely different.
You may, and I stress may, be closing something using JavaScript (although I doubt it), but definately not with Java. And if you claim to be, please post that code, as I do not believe it (except maybe with an Applet with all security policies opened up on the client, which would be possible, but I, if I worked there, would immediately stop working there, if that is the case).
And I do not have to tell you anything. So keep the demand of your last statement to yourself. You have been going on and on about this topic for months now, always insisting on being able to do something that you either cannot, or should not do (at least not the way you think it will work). The one time you actually (I believe by accident) did something right (in simply sending the content of the file to the browser after having set the content type and disposition headers and letting the browser decide how to open it) you …
change from show() to setVisible(true) .... and find a better tutorial, that one's outdated.
No, no. I wasn't trying to be harsh before. Sorry, if you took it that way. You're right here, about the cause, anyway, but there are a few other things as well.
public void service (HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
HttpSession session = req.getSession(true);
res.setContentType("text/html");
PrintWriter out = res.getWriter();
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//Loading Sun's JDBC ODBC Driver
theConnection = DriverManager.getConnection("jdbc:odbc:Dew", "", ""); //Connect to emaildb Data source
Statement theStatement=theConnection.createStatement();
String Fn = req.getParameter("p1");
String Ln = req.getParameter("p2");
String Em = req.getParameter("p3");
String un = req.getParameter("p4");
String updateString = "UPDATE T1 SET Fname =?, Lname=? WHERE username =?";
PreparedStatement pStmt = theConnection.prepareStatement(updateString);
pStmt.setString(1, Fn);
pStmt.setString(2, Ln);
pStmt.setString(3, un);
ResultSet theResult = pStmt.executeQuery();
theResult.close();//Close the result set
theStatement.close();//Close statement
theConnection.close(); //Close database Connection
}catch(Exception e){
out.println(e.getMessage());//Print trapped error.
}
}
should be
public void service (HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
HttpSession session = req.getSession(true);
res.setContentType("text/html");
PrintWriter out = res.getWriter();
PreparedStatement theStatement = null;
Connection theConnection = null;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//Loading Sun's JDBC ODBC Driver
theConnection = DriverManager.getConnection("jdbc:odbc:Dew", "", ""); //Connect to emaildb Data source
String Fn = req.getParameter("p1");
String Ln = req.getParameter("p2");
String Em = req.getParameter("p3");
String un = req.getParameter("p4");
String updateString = "UPDATE T1 SET Fname =?, Lname=? WHERE username =?";
pStmt = theConnection.prepareStatement(updateString);
pStmt.setString(1, Fn);
pStmt.setString(2, Ln);
pStmt.setString(3, un);
int num = pStmt.executeUpdate();
} catch(Exception e) {
out.println(e.getMessage());//Print trapped error.
} finally {
if (theStatement != null) try { theStatement.close(); } catch (Exception e) {} //Close statement
if (theConnection != null) try { theConnection.close(); } catch (Exception …
Your "fix" to allow here cobbled together Statement to work, is, technically correct (although there is no reason to do a separate + "'" for everyone of the single quotes), however, she should not be using a cobbled together statement in the first place. What happens if one of the variables used contains a single quote (')? The statement will be broken. For that exact reason, the statement is also left wide open to SQL injection atacks.
@OP, use a PreparedStatement and its set... Methods
String updateString = "UPDATE T1 SET Fname =?, Lname=? WHERE username =?";
preparedStatement pStmt = conn.prepareStatement(updateString);
pStmt.setString(1, Fn);
pStmt.setString(2, Ln);
pStmt.setString(3, un);
int Upd = theStatement.executeUpdate();
And, if you have this code as a scriptlet in a JSP, remove it. Place all actual "code" into one (or more) beans. Scriptlets are strongly discouraged in the current version of JSP.
Umm, peter, I thought you knew this one. ;-)
str = servletData.toString();
I believe should be
str = new String(servletData);
or
str = new String(servletData, charset);
if the "bytes" are neither ascii, nor UTF, nor the local charset.
The second one (with the toByteArray()) is correct, but if its not working then check out the charset variation.
And Merry Christmas and a Happy New Year! (and if you're not Catholic/Christian/Other Derivatives don't take offense). ;-)