javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Maybe because I don't know how MACs work I don't understand you, but:
Where is the file saved?
The full path.
Use that as argument

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
Scanner inFile = new Scanner (new FileReader("grades.txt"));
PrintWriter outFile = new PrintWriter ("output.txt");

You need to set the exact path of your files. Not just their names, but where they are in the disk.
Where have you saved your files?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The import DBManager cannot be resolved

You need to import the class:

<%@ page import="package.DBManager"%>
peter_budo commented: Good answer, but you should let him sweat little +22
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Hello, for the project I'm working on, I need to be able to access say, a JPanel object that was created from the execution of a Jar file, and use it inside another class outside of the Jar file. Any ideas?

Thanks

If you want to access any object, you need to have a method that returns it. If you want to use the classes and methods that are in jar you need to put the jar to your classpath.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

It is because you don't pass "realName" from update.jsp to next.jsp in the request.
Maybe you can put them as hidden fields at the update.jsp. (I don't really use javabeans)

<form name="formName" action="next.jsp">

<input type="hidden" name="realName" value="the value from the bean" />
<input type="hidden" name="userName" value"the value from the bean" />

<input type="submit" value="next" />
</form>

To tell you the truth, I don't use javabeans so I can't tell you for sure how to pass their values to the hidden fields. If it was my project I would have first look for some tutorials or examples on javabeans

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

So the conclusion is only servlet can mapping.

Actually, I've never seen JSPs being mapped. From what I know you map servlets because, the servlet you define, is just the class name. But you cannot call class names, you need to map it to a url. So it is like saying what is the url of the java-servlet-class you created.
But for JSPs, they can go directly to the url. No mapping is needed.
Now if it can be done I don't know, but I am sure that it is not needed

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Can somebody show me how to create a simple two column for strings? I need a sample code. Thank you for those who will help me.

Actually even if we wanted to help, what is this:
a simple two column for strings
I have never heard of it. What do you mean?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

There is no reason to do it for jsp. What are you trying to accomplish?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Thanks for this javaaddict ..
:)
cant we add several records without over writing the existing content of the text file...if so please provide the code

If you have any further questions you should check first check the API for the classes you are using. You will probably find there what you need.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Search this forum for examples on how to use this class:

BufferedWriter

BufferedWriter wr = new BufferedWriter(new FileWriter("filename"));
wr.write("something");
wr.newLine();


wr.close();
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First of all we need to see the code at the servlet.
Second, you can have a hidden parameter in the jsp and the user clicks update to change its value:

<html><head>
<script language="JavaScript">
function update()
{
var r=confirm("Are you sure?");
if (r==true)
  {
document.form1.action.value='update';
document.forms[0].submit();
  }
else
  {
document.form1.action.value='';
  }
}
</script></head>
<body>
<form name="form1" method="post" action="controller/servlet">
...
...

<input type="hidden" name="action" value="" />

</form>
</body>
</html>

Also check these 2 links:

http://www.w3schools.com/default.asp
http://www.w3schools.com/js/default.asp

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Is formula a String? :

formula = "((10000.00+4000.00)*(30/100))";

If yes then this will not work:

double amout = Double.valueOf(formula);

The String formula has to have a numeric value. Like "2" or "-100.345".
If it has value: "((10000.00+4000.00)*(30/100))" it will not work.
You need to extract the numbers from the String formula, turn them into numbers (parseDouble() or parseFloat()) and then apply the operators (+, -, *, /)

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Do not even look at this code , just write java code to calculate total sale price from user inputs .

I get it now.
I was sent a PM from chingkoysilog (the OP) asking to give him the solution of an assignment that involved salespersons and calculating some total values per products and salespersons.

He probably found the solution from the internet in C++ and now wants someone to convert it in java.

If chingkoysilog disagrees then please correct me, by posting your code and explaining what is your problem so we can help you.

ithelp commented: ok. +12
iamthwee commented: yeah he got the code from daniweb +22
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I would suggest that you stop working on this servlet thing and start learning some basic java because this error is very basic and usually done by beginners.

You declare the Map in one method locally and you try to access it from another method.
Declare it globally or declare another Map in "doGet" depending on what you want.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Is this even C++ ?

What is this:
<strong class="highlight">for</strong>

It seems to me that you copy-pasted from the source code of a web page and by posting it like this, we get the impression that you don't even know C++ or you didn't bother to post it in a readable way for the rest of us.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

When you open an existing file and you try to write some stuff in it, the old content is automatically deleted and overwritten by the new data. There is an option at the constructor of BufferedWriter class that allows to append the new data or overwrite the old ones.

BufferedWriter writer = new BufferedWriter(new FileWriter("fileName"));

writer.write("some stuff");
writer.newLine();

writer.close();

Check the API for BufferedWriter for further information because I don't remember very well the exact syntax of the methods I used. You will also find what you are looking for.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

This method returns numbers from 0 to 1: Math.random() In the for loop take a number between 0 and 1. (0% - 100%)
If the number is lower than the percentage print, else don't print.

0 ------ 5% (0.05) ------------------------------------- 100% (1.0)
|---------|---------------------------------------------------|
|
^
If the number is here (between that space) then print. If it is outside of that space don't print

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

What is the total?

Are you saying that, you will have for example a loop running 50 times.
Sometimes the loop will print, some times it will not:

for (int i=0;i<50;i++) {

if (something) System.out.println("detected"); //5% of the times, this will be printed
else System.out.println(""); //nothing printed

}

Is this what you are trying to accomplish?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Read this:

Do not hijack old threads merely to post "give me teh codez". If you have a question about an assignment, start a new thread and post the code that you have as a start.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

It depends where you declare it. You should put the declaration before the login.

Also we would like to see some code if you want further assistance

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

how many days will it take to get perfect with core java?
any shortcuts?

You got that response because of this:
how many days

It takes YEARS, many years; there are NO shortcuts.
And no one will ever be perfect in core java. What you do is learn how the language works and then you learn how to find solutions to your problems. Once you have the solution, you implement it in java.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

And why do you need properties file for this. Why don't you try javascript?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Then why don't you look at this link:
JSP database connectivity according to Model View Controller (MVC) Model 2

It is at the top of the Jsp forum.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

http://java.sun.com/j2se/1.5.0/docs/api/java/util/Properties.html

propFile.properties:

promptName = My Name is:
name = Neo

FileInputStream inputStream = new FileInputStream("propFile.properties");

Properties prop = new Properties();
prop.load(inputStream);

String s1 = prop.getProperty("promptName");
String s2 = prop.getProperty("name");

System.out.println(s1 + s2);
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Hi everybody.
I have a problem and I need some suggestions.

A few weeks ago, my monitor suddenly turned off on its own. Then I shut down my computer and switched it on again, and after 5 minutes the monitor turned off again. This happened several times in a row.
Some hours later I turned on the computer and it was working OK.
But recently when I turn the computer on, the monitor periodically switches on/off for several times before it "stabilizes". The little green light the monitor has also switches on/off.

What do you think is the problem? Do I need to buy a new monitor?
If it helps, I have a ViewSonic VE710s.

Thank you

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The " System.out.println() " writes to the standard output, which in your case is the server. If you check the server you will see it written.

But this:

Hello!  The time is now <%= getDate() %>

is displayed at the page/browser and the: <%= getDate() %> is replaced by whatever the method returns. In your case the method returns this:

return theDate;

So this:
System.out.println() is written at the server
and this: <%= getDate() %> meaning this: return theDate; at the browser

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Actually your initial code was just searching for the 1st and 2nd number.
If you want sorting, then the algorithm is entire different.
It depends on your specifications. I mean the easiest way to do this, is first to sort the array and then you will know that the 1st number is the first element of the array, the 2nd number is the second element of the array.
Sorting is easy. It is more difficult to find the second number without sorting, which why I was referring to your specifications. Maybe you were asked to find the 1st and 2nd without sorting

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The answer is very simple. You declare 2 variables:
"min"
"secondMin"
that hold the values of the "min" and "second min". So why don't you declare 2 more values that will hold the indexes:

"minIndex"
"secondMinIndex"

int min;// declare variable
int secondMin;// declare variable

int minIndex;// declare variable
int secondMinIndex;// declare variable

.....

if (values[0] < values[1]) { 
		        min = values[0];
		        secondMin = values[1];

                       minIndex = 0;
                       secondMinIndex = 1;
		    }// end of if 
			else {
		        min = values[1];
		        secondMin = values[0];

                       minIndex = 1;
                       secondMinIndex = 0;
		    }// end of else

.....

if (values[i] <= min) {
		            secondMin = min;
		            min = values[i];
                       
                       secondMinIndex = minIndex ;
                       minIndex = i;
		        } 
		        else if (values[i] < secondMin) {
		            secondMin = values[i];
		            
// This wrong. You don't want to change the values of the array.
// just save the values[i] to the secondMin variable
//values[i]= secondMin;

                       secondMinIndex = i ;
		        }

Look at my comments in the above code

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I'm not sure about this, but I think using Collections.sort(yourArray) would also do the same thing javaAddict is suggesting. But it seems like your assignment is to write the sorting method yourself, so you'll need to specify what vernon mentioned.

Actually we don't know what his assignment is, that is why I asked for the specifications. His code though seems that tries to compare 2 Strings, which is why I recommended that method.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Well, what exactly are you sorting? What's the input and what is the output supposed to be?

Is it splitting a sentence into words, then sorting the words? If so, "All Big Cats" is already sorted and "Cats All Big" would turn into "All Big Cats". What's the goal here?

VernonDozier is right. Your code doesn't make any sense. What exactly are you trying to accomplish and what are your requirements.

Also the String class has this method:
"compareTo"
It is used to compare 2 strings.
If it returns 0 means that the Strings are equal.
If it returns positive the first is "greater" than the second
If it returns negative the first is "lower" than the second.

So if sorting is your game, you can use this method to sort in the way you would sort numbers:

String a="abc";
String b = "def";

if (a.compareTo(b)>0) { // a > b
  System.out.println("a should go after b");
} else { // a <= b
  System.out.println("a should go before b");
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You can have a form at Main.jsp that submits to the return.jsp.
Create an input field or a hidden field at the main, and take its value at the return.jsp from the request:

Main

<form action="return.jsp">
  <input type="text" name="textName" />

  <!-- OR -->

  <input type="hidden" name="hiddenName value="some Value" />
</form>

return

<%
String textName = (String)request.getParameter("textName");
String hiddenName = (String)request.getParameter("hiddenName ");
%>
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Your class needs to extend the JFrame class

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

javaAddict,
you are so good in Struts 2 now that you don't need any help except that you solution does not work since <s:property="code">
is syntaxically incorrect...
Johnxjean took the time to translate probably something he found in spanigh ont he web, so nice of you to thank him as you did. Modesty will certainly not kill you...

After 9 months I assure you I found the solution. And the code is correct because a) It runs and b) because I am not going to post the entire jsp of hundreds of lines, nor it is necessary to post the exact variable names. The part I posted was sufficient for someone who knows to be able to pick it up. It was an example of how I get it to work. I am not going to post the exact code that I developed for my company
And:
As I stated the solution was found and I don't believe that what you posted was any bit constructive.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

aaa

If you thought that just by posting your problem you would be given the solution, you are wrong

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Actually he wrote something like this:

if (ReverseString.reverseIt(str))

which indicates that the method returns true (boolean) if it is palindrome.
There is a way as you know that checks if a string is palindrome without actually calculating the palindrome.
The reason why you were confused, I believe was the name of the method:
reverseIt which means what you expected.

That is why I am still waiting for him to post the code. We can only speculate without it.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You are assigned to develop a simple Java program to demonstrate the functions provided by the system.

I am sorry but you are mistaken we don't go to the same school, so I am not assigned nor am I required to develop that program. You are.

I would suggest to create a class with attributes:
country, numOfGold, numOfSilver, numOfBronze

and another class that represents a collection of those classes and executes the requirements. (printing, sorting, searching)

Then in a different class create your menu and call the above methods

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Perhaps when I was writing the post I was looking an older version of the code.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I am sorry to disappoint you Godstryke but next time when you want to compare Strings or in general objects use the "equals" method:

if ( reverse.reverseIt(str).equals(str) ) {
}

And please try to be a bit patient, and observative.
You have already replied to a loozax's post with the same question. In this post the question is how to reverse and in the next post was to check the code.

So personally I would be curious to see what code he has written as to comment and offer suggestions and tips, since he has already put some effort to write his own code.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

There are a couple of problems. Be sure to check your code's syntax a little more carefully. Also, consider going through your program step by step using a debugger to monitor the status of each of your variables at different stages.

If you have read carefully the code you would have seen that:

1) the method reverseIt returns boolean not String.
2) the poster doesn't want the solution. He probably has the solution and wants as to check the code. The solution is in the method reverseIt that he wrote and we still wait to see that code
3) your code is wrong and you will get an ArrayIndexOutOfBoundsException if you run it

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First of all you need to tell us what is your problem.
Second, you forgot to post the
ReverseString.reverseIt() method.

We don't need to know how you call your method. The code you posted is correct. You call the method and you print it. What you should have posted is the implementation of the reverseIt().

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First of all I find it surprising that you wrote this code and still couldn't find the answer.
I mean was it so difficult to add this to your code?

if (lineNo==5134)
{
  line = br.readLine();
} else if (lineNo==5100)
{
  line = br.readLine();
} else if (lineNo==5200)
{
  line = br.readLine();
}
..
..
..
 else {
  br.readLine();
}

Of course you code prints only one line because you have only ONE variable "line". If you want to print all of them either add a
"System.out.println" at the place that you read them:

if (lineNo==5134)
{
  line = br.readLine();
  System.out.println(line);
} else if (lineNo==5100)
{
  line = br.readLine();
  System.out.println(line);
}

Or declare an array that will store the line that you want:

String [] lines = new String[N];
int i=0;
.....
if (lineNo==5134)
{
  line = br.readLine();

  lines[i] = line; 
  i++;
} else if (lineNo==5100)
{
  line = br.readLine(); 

  lines[i] = line; 
  i++;
}

But that wouldn't be quite correct.I have noticed the way you read the file:
>> for(lineNo=1;lineNo<10700;lineNo++)
It is wrong. In general you wouldn't know how many lines the file has. So instead of the for loop use this:

FileReader fr = new FileReader("C:\\IMS.txt");
BufferedReader br = new BufferedReader(fr);
int lineNo = 0;

String line = br.readLine(); 
lineNo++;

while (line!=null)
{
  // do whatever you want with the line or the line number
System.out.println("Line Number: "+lineNo+", Line: "+line);

  line = br.readLine();
  lineNo++;
}

Whenever you read a new …

BestJewSinceJC commented: OP didn't mark as solved, although it was solved. +8
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Check the API for the String class. There you will find many useful methods

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I would suggest spalax to start a new thread with your question. This thread is for answering robben's questions not yours. Should we ignore robben who created this thread in order to answer your question?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

And most important: START your own thread. What you posted has nothing to do with with thread. You didn't specify your problem. Even if we wanted to help what code are we suppose to "sent"?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Have you looked the API of Vector?
I assume you didn't because if you did you would have found this method:
Vector.add

Also you need to create a class:

class ClassA {
  private String a = null;
  private String b = null;
.......
}

with public get,set methods.
Then for each row/loop of the database you create a new object of that class and you put that in the vector.

Vector v = new Vector();
while (rst.next()) {
        ClassA cla = new ClassA();
        cla.setMethod...(rst.get....(1));
        cla.setMethod...(rst.get....(2)); //other method

        v.add(cla);
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Classes begin with capital. Methods with lower.

StringConcatenate stringConcatenate1 = new StringConcatenate(); 
stringConcatenate1.stringConcat();

You create an object/instance of type StringConcatenate. And you call the method stringConcat() of the instance stringConcatenate1.

Most of the time different instances have different results when they call the same method:

StringConcatenate string1 = new StringConcatenate("aaa"); 
StringConcatenate string2 = new StringConcatenate("bbb");

string1.stringConcat();  
string2.stringConcat();

That is why we create different instances of the same class.

Also this would only be correct if the method was declared "static"

StringConcatenate.stringConcat();

If the method is static you don't need to create an instance to call it

majestic0110 commented: Excellent response, thank you! +4
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The way you do it with any other method:

public double method(int i) {
  return i*2.5;
}
....
public static void main(String [] args) {
   double r = method(2);
}

Look the java API (java.util.ArrayList) for the methods and constructor of the ArrayList.

Create a constructor at the Alist class that takes as argument an ArrayList. Hopefully you know how to global attributes in classes, that take value at the constructor and can be used throughout the class.

Declare a boolean in the thread Alist. When the run() starts set its value to false. The last command of the run() would be setting it to true. This variable will tell you if the run() method and Thread has finished or not.

Write a get method in the AList that returns theArrayList.

In the main write a while loop that checks if the Thread is finished or not by checking the boolean variable of the Alist.

If it is finished call the get method of the Alist

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Another way with sysdate is:

select * from table where StartDate = sysdate

or better the following will check only the date without taking into account the hours, minutes:

select * from table where  trunc(StartDate) = trunc(sysdate)

With the first, these dates will be unequal:
27/07/2009 12:00:00 , 27/07/2009 12:00:01

but with the second query only the year, month, day will be compared

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Here is another code snippet that might help:

BufferedReader reader = null;
try {
  reader = new BufferedReader(new FileReader("fileName"));
  String line = reader.readLine();
  while (line!=null) {
       // do whatever you want with line
      System.out.println(line);

     // this MUST be the last command:
    line = reader.readLine();
  }
} catch (IOException ioe) {
   System.out.println(ioe.getMessage());
} finally {
   try { if (reader!=null) reader.close();  } catch (Exception e) {}
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

yeah i want them to put in an array, actually i want those data from the database to be display in the JTable, i have 8 columns instead of using 8 vectors i just want to put it in a 2 dimensional Object array, thats why i want to know the record count and also the row and the col from the database...the changes everytime ill search for a record......

You won't need 8 Vectors, but One. Create an Object that represents each row/record and put that in the vector