masijade 1,351 Industrious Poster Team Colleague Featured Poster

Why a collection. Why not directly to a DB, or, worse case scenario, a file (i.e. randomaccessfile)?

In any case, 65k is not much. You could simply increase the maximum heap size.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Partly, both StringTokenizer and Scanner (in this case, especially, when reading a file) are not the fastest tools around. StringTokenizer, for one, is all, but, deprecated and shouldn't really be used, but there are more problems with that than just speed. And Scanner is great for verifying data types before reading and for automatically converting the string to the datatype you need as you read it, but with that comes a fairly large performance hit.

The other part though, was the fact that both the Scanner and the FileInputStream (with the only 1024 buffer size) were making far too many disk reads. A Buffered(Reader/InputStream) will fill it's buffer with as few disk calls as possible (usually one if there were no problems, and it has, usually, an, at least, 8k buffer), then your read calls are made against this buffer (automatically removing line endings when using readLine).

Ezzaral commented: Nice work. +19
masijade 1,351 Industrious Poster Team Colleague Featured Poster
package whatever;

public class Read {
    String DATE_FORMAT_NOW = "yyyy/MM/dd hh:mm:ss";
    SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
    long starttime = System.currentTimeMillis();
    String timeS = sdf.format(new Date(starttime));
    void readFile(String fileName) {
        System.out.println(">> time of exe: " + timeS + " milliseconds: " + starttime);
        BufferedReader br = null;
        try {
            br = new BufferedReader (new FileReader(fileName));
            int count = 0;
            String line = "";
            while ((line = br.readline()) != null) {
                String[] lineA = line.split("\\|");
                System.out.println(">> id: " + lineA[0]+ " >> flag: " + lineA[1]);
                count++;
            }
            System.out.println(">> rows: " + count);
            System.out.println(">>> elapsed time: " + (System.currentTimeMillis() - starttime));
        } catch (FileNotFoundException fnfe) {
            fnfe.printStackTrace();
        } catch (IOException ioe) {
            ioe.printStackTrace();
        } finally {
            if (br != null) try { br.close(); } catch (IOException ioe) {}
        }
    }

    public static void main(String[] args) {
        String fileName = "\\Id.dat";
        Read r = new Read();
        r.readFile(fileName);
    }
}
masijade 1,351 Industrious Poster Team Colleague Featured Poster

I sure he knows that, he just wants a code handout. Which he won't get.

If he posts his attempt at it, he might get help correcting it, but noone is going to do it for him.

masijade 1,351 Industrious Poster Team Colleague Featured Poster
if (number > largestSoFar){
        secondLargest = largestSoFar;
        largestSoFar = number;
      }

of course

And this, of course, will be removed

if (number < largest){
  if (number > secondLargest){
    number = secondLargest;
  }
}

You can also remove all current references to "largest" and then rename "largestSoFar" to "largest".

masijade 1,351 Industrious Poster Team Colleague Featured Poster

You want to assign "largestSoFar" to "secondLargest" before you assign "number" to "largestSoFar", but within the same if block.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

4, 3, 3, 3 and 3

Ezzaral commented: Excellent work! +19
masijade 1,351 Industrious Poster Team Colleague Featured Poster

If this is really what you want, and has nothing to do with XML, then re-read the reply #1.

And to complete, you then delete the original and rename the new to the original.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Read the API docs for FileReader and see if some other method there is better.

Or wrap it in a BufferedReader, then read the API docs for BufferedReader and see if there is yeat another method there that is even better for your purposes.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Would Please tell, is there any algorithm for encrypting and decrypting the media file such as audio and video files. thanks in advance.

Start your own thread, and google is a great resource.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

500 Internal Server Error occurs as a generic error message, when no more specific message is suitable. so check ur code throughly, there might be a minor error

And so what is this? (From the OP)

root cause

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
masijade 1,351 Industrious Poster Team Colleague Featured Poster

You are facing problem while connecting to mysql database ......
i am forwarding you sample code hope this will ressolve u r problem.

code:
import java.sql.*;

public class MysqlConnect{
public static void main(String[] args) {
System.out.println("MySQL Connect Example.");
Connection conn = null;
String url = "jdbc:mysql://localhost:3306/";
String dbName = "jdbctutorial";
String driver = "com.mysql.jdbc.Driver";
String userName = "root";
String password = "root";
try {
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url+dbName,userName,password);
System.out.println("Connected to the database");
conn.close();
System.out.println("Disconnected from database");
} catch (Exception e) {
e.printStackTrace();
}
}
}

completely unnecessary, nothing to do with the problem, and poorly written. Close the resources in a finally block.

follow simple code and make sure mysql connector jar should be in u r classpath.

This was the problem. Of course, you do realise that this thread is over a year old, right?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Ach, nevermind. BlueJ, your whole problem starts there, IMHO.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Yes, 8000 is -MAX_VALUE and ffff is -1.

The conversion to decimal is not be necessary (and I screwed up on the "binary" possibility, as you need to flip the bits there, too ;-) ).

System.out.println(Integer.valueOf("-0d09", 16));
masijade 1,351 Industrious Poster Team Colleague Featured Poster

Post the command you ran that gave the error.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

A bit of game (and there are better ways, to be sure) but, parse it as an int (I know it's the wrong value, but bear with me), get the binary value of that int, lop of the left most bit (the string will only contain enough bits to represent the value) and then parse that as a short with a leading minus sign.

;-)

masijade 1,351 Industrious Poster Team Colleague Featured Poster
masijade 1,351 Industrious Poster Team Colleague Featured Poster

Use tomcats connection pool and add the Driver jarfile to either shared/lib or common/lib (whichever is more appropriate or still exists in that tomcat version) as per the tomcat documentation.

masijade 1,351 Industrious Poster Team Colleague Featured Poster
masijade 1,351 Industrious Poster Team Colleague Featured Poster

Don't do it that way. That is Database specific. Read the API docs for DatabaseMetaData.

Ezzaral commented: Good point. +19
masijade 1,351 Industrious Poster Team Colleague Featured Poster

Most likely those "pages" are pre-generated and then accessed statically (although I didn't look at them, but if they are suppossedly "huge", and still load in the millsecond to 2-3 second range, then this is about the only possibilty).

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Please describe "does not run".

masijade 1,351 Industrious Poster Team Colleague Featured Poster

You can't. You would have to extract it and then execute it.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

That is not the full path to the command. I can guarantee that "." is not what you think it is. Use the full path whether setting the Path or using the full path in the command.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

read it and as you read it write it out to another file, but don't write the last line.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

You need to check how long the last line is before you write it, then use seek to back up that amount.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

They don't have a full environment. Set the environment variables you need (such as PATH) in the script.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Modulus. It produces the "remainder" from a division. I.E. 10 % 3 returns 1 and 11 % 3 returns 2 and 12 % 3 returns 0.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

And, with the way the post reads, so do I. That is the reason it is formulated the way it is. The other is still an option though, which is why it was mentioned.

masijade 1,351 Industrious Poster Team Colleague Featured Poster
Set<Object> check = new HashSet<Object>();
for (Whatever sNum : s) {
  if (!check.add(calculation(codeword, sNum))) {
    // whatever
  }
}

There is no reason to call this "calculation" method multiple times for the same "sNum" (that is extremely ineffecient), and the add method of Set will return false, if the item being added already exists.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

When you add the keys, upper case them, and then uppercase the "search" key when retrieving one. Otherwise, you are going to have to loop through the keys yourself using equalsIgnoreCase to find the right key.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Actually do sudo test .... rather than sudo [ .... ]

masijade 1,351 Industrious Poster Team Colleague Featured Poster

I will be very positive when I tell you that we are not just going to do it for you.

Tell us exactly what problem you are having and we will help you correct it, otherwise, http://www.rentacoder.com/

masijade 1,351 Industrious Poster Team Colleague Featured Poster

decompile that BCEL generated class file, as BCEL does not create and then compile java files, it directly creates/modifies the byte code contained within the class files. Don't expect to get "pretty" code, though.

Once again though, there are generators for specific purposes.

Here.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Nevermind.

You still haven't said why it is you feel the need to generate classes, which, if we knew that we might be able to recommend a finished product, but what the heck.

The answer, then, is no. You will have to actually do things like

println("  public void getVarName() {");
println("    return varName;");
println("  }");

yourself.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

I need how to create a java file dynamically.Also i need to add my own methodes,attributes etc to it and save this java file to a specific directory.

Once again, you are describing a means to an end, would you care to illuminate what the "end" should be?

I.E. What are you trying to accomplish by doing this. What task are you attempting to fulfill by attempting to generate classes on the fly?

masijade 1,351 Industrious Poster Team Colleague Featured Poster
masijade 1,351 Industrious Poster Team Colleague Featured Poster

What are you using to compile?

If you are using an IDE, then you need to add that jar as a library in the project properties.

Edit: As that is the CLASSPATH for an IDE. The System CLASSPATH is good for almost nothing, anymore. Do the following concerning classpaths

1. When running from the command line without the "-jar" option use the -classpath option.
2. When running from the command line with the "-jar" option, you must configure the classpath in the manifest file properly.
3. When running/compiling from an IDE, you must configure the librarires in that IDE's project properties.
4. When running from a web container / application server you must place the jars in the proper locaions (see the manula for the web server / application container in question).

IDE's and web containers / application servers ignore the system classpath. When using the -jar option, both the System CLASSPATH and the -classpath options are ignored and only the manifest file's classpath is used. The only time that the system CLASSPATH is still used, is when running or compiling from the command line with neither the -jar nor the -classpath options.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

There is a tutorial at the top of this forum.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Google for JPCAP

masijade 1,351 Industrious Poster Team Colleague Featured Poster

In Java regex, there is no reason to escape "/", and, if you do need to escape something, then you also need to escape the escape as the escape character also escapes characters in String, in general (i.e. "\\" every place you need a "\").

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Like I said, though, "-1" says that s1 (which is the lesser number the first time, but the greater number the second time) is less than s2, whereby s1 is significantly greater than s2 the second time, not less than s2 as "-1" indicates.

What I am saying, is that you cannot String compare the entire String at once. That comparison is done alphabetically, not numerically. For single characters, alphabetically and numerically are the same, but not for multicharacter Strings. (E.G. alphabetically 10 is less than 2).

verruckt24 commented: Both your posts previous and this one underline a point which o/w can be missed. Good. +3
masijade 1,351 Industrious Poster Team Colleague Featured Poster

Anyways it gives the same outcome which is "-1"

Which is saying that s1 is less than s2. Well, is it? ;-)

masijade 1,351 Industrious Poster Team Colleague Featured Poster
while (room.length() == 0)
  {
    System.out.println("Error: This field cannot be empty");
    System.out.println("Enter the name of the lab this computer is located: \t"); } // this } closes the while
  room = scan.nextLine();
} // so this brace closes the method

I am fairly certain your "first" '}' commented above shouldn't be there.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

convert i to String and use compareTo() function

here is how it works

public class StrCmp {
public static void main(String args[]) {
String s1 = new String("1234567891011");
String s2 = new String("1234567891012");
System.out.println(s1.compareTo(s2));
}
}

Try it with

public class StrCmp {
  public static void main(String args[]) {
    String s1 = new String("1234567891011");
    String s2 = new String("234567891012");
    System.out.println(s1.compareTo(s2));
  }
}

You might be surprised by the outcome.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

If you need a mathematical comparison, and the numbers are too large to store in a long, then no, there is no other (uncomplicated) way than with BigInteger. Now, if you think you must do it some other way, than convert the int that you are to compare it to, to a String, than check the lengths of the String. The longer one is the larger. If they are same, start taking one character at time from the front of each String and comparing them (Strings compareTo is good enough for this). As soon as you find one that is larger than the other, you've found the larger number. Now, is it wise to do it this way? No. It is wise to use BigInteger, as already said.

But, as asked once already, what is it that you are actually trying to acheive? If you are attempting to loop some 1000000000000 times, than be prepared to wait, no matter what method you use. And, if you are trying to loop that many times, than the real question is why? What are you doing that you feel you need to loop that long?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Ach, yeah, and as darkagn say, BigInteger, not BigDecimal (unless you're going to have decimals, in which case you'd have been using float and double instead of int and long, anyway).

masijade 1,351 Industrious Poster Team Colleague Featured Poster

An int is 4 bytes which is 32 bits (31 of which is value and the 32nd is a pos/neg toggle). A long is 8 bytes (63 bits data and 1 pos/neg toggle) so use long and parse that String to a long using Long.parseLong(string). If a long is also not large enough use the BigDecimal class. See the API docs.

Killer_Typo commented: Very well written comment. +7
masijade 1,351 Industrious Poster Team Colleague Featured Poster

One, remove that ";" at the end of the for loop declaration. That ";" ends the for loop.

Also, near the end of the block that is suppossed to be the for loop, remove that guesses++; . Using that statement you would be incrementing "guesses" by two through every iteration of the loop, as you are also incrementing it as part of the loop declaration.

Also, remove that int guesses; before the for loop and declare the for loop as for (int guesses=0; guesses < ichances; guesses++) . Notice that the int is declared in the for loop (since it not used outside of it this will restrict to the for loop), and use simply "<", not "<=", or you are giving them an "extra" guess.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

No, as long as the network is properly setup (and I will trust that the admins no what they are doing). The only thing that could, then, help, is to upgrade the network (possible speed range from 10MBit-half duplex to 2 (if not now 4) GBit-full duplex).