- Strength to Increase Rep
- +6
- Strength to Decrease Rep
- -1
- Upvotes Received
- 9
- Posts with Upvotes
- 9
- Upvoting Members
- 6
- Downvotes Received
- 0
- Posts with Downvotes
- 0
- Downvoting Members
- 0
Re: [QUOTE=neutralfox;865110]Hello everyone, What is the key in this program? How can I change the key? [/QUOTE] The key is simple a sequence of 16 random bytes created by the KeyGenerator. It's actually the same 16 bytes as returned by getEncoded() -- your raw[] array in this case. If you want … | |
Re: I assume that "by threads", the assignment means sorting with several threads in parallel. So you need to: - know [URL="http://www.javamex.com/tutorials/threads/"]how to program with threads in Java[/URL] - pick an algorithm that can be parallelised. This essentially means one that uses a "divide and conquer" strategy to work on different … | |
Re: If you want a literal to be a long, you need to suffix it with L: [code] use=1000000000L; [/code] If the literal is small enough to fit in an int, then you can write it as an int (without the "L") and it will automatically be converted to a long. … | |
Re: Normally, you get the number of bits dictated by the key size (e.g. 512-bit key = 64 bytes) minus a few bytes (11, I think) of overhead. For the gory details, see the so-called PKCS #1 standard: [url]http://tools.ietf.org/html/rfc3447#page-35[/url] However, if you're worrying about this, you may be doing something wrong! … | |
Re: Agree about the two ints for number of trains in UP vs DOWN direction. One thing, though-- did your tutor mention to you about [URL="http://www.javamex.com/tutorials/threads/thread_safety.shtml"]thread-safety[/URL]? If you have multiple threads accessing some data (here, multiple Trains accessing variables on the same Track), you need to use some mechanism to make … | |
Re: Essentially, you need to make sure that whatever call is blocking is actually inside the background thread. I don't know the library you're using, but I'm guessing that the call to up.upload() is blocking. (Put some logging on or run in the debugger to find out.) | |
Re: OK, so the basic idea is that you can use sine and cosine to convert from an angle to a position on the screen. If r is the radius, then the (x) and (y) coordinates are r * Math.sin(angle) and r * Math.cos(angle), where angle is measured in radians (so … | |
Re: As people have mentioned, you need to use asymmetric encryption at the very start of the conversation to send the sessiion key to the server. Use RSA for this. Essentially, you create a public/private RSA key pair as follows: [code] KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA"); kpg.initialize(2048); KeyPair kp = kpg.genKeyPair(); KeyFactory … | |
Re: I can't see a problem with writing this in Java. For the checksums, you could look at the MessageDigest class, or just use some other fairly strong hash function. MD5 isn't necessarily the best choice: it's designed to be a [I]secure[/I] hash function, and trades performance for that security. IMO, … | |
Re: You have a couple of options: - Use the [URL="http://www.javamex.com/tutorials/io/bytebuffer.shtml"]ByteBuffer[/URL] class (link is to a tutorial I wrote in case helpful), for example: [code] ByteBuffer bb = ByteBuffer.allocate(4); bb.put((byte) ...); bb.put((byte) ...); bb.put((byte) ...); bb.put((byte) ...); int intVal = bb.getInt(0); [/code] - More efficiently, just manually code it with shifts … | |
Re: For more effective programming, [B]don't[/B] try and memorise this list; bracket expressions appropriately so that any programmer can read them whether or not they have also memorised this list (practically nobody has). OK, it's probably safe to assume that most programmers know that * and / have priority over + … | |
Re: You don't actually have to go to all that trouble, though... [code] int val = Integer.parseInt(str, 2); float f = Float.intBitsToFloat(val); [/code] | |
Re: For the [I]general[/I] case, essentially, you break the exponent down into a series of "multiply by x" and "square then multiply by x" operations. If you imagine the exponent in binary (without trailing zeroes), then for each bit position that there is (ignoring the highest bit), you need to square … | |
Re: I think I'm missing something here -- as I did when you asked a very similar thing in another thread. If you just want to extract the substring between two character positions, then use the substring() method. So if str is "mnp1011000jie", then do: [code] String str1 = str.substring(0, 3); … | |
Re: Not sure if this is what you mean, but once you have the binary number part "0101010" etc as a string (i.e. you've stripped off the other parts of the string), to convert to an int or long, look at Integer.parseInt() and Long.parseLong() -- pass in "2" as the "radix" … | |
| Re: Erm... I wonder if the solution your instructor wanted you to get at was to just make the loop go up to 5? |
Re: Create a class to represent your "seg folder", then give it two String fields: name and description. | |
Re: As the previous poster says, I think the whole point of your assignment is to demonstrate that a self-made LCG with bad parameters [I]doesn't[/I] work very well. As well as the abovementioned link, you may be interested in this article on my web site about the [URL="http://www.javamex.com/tutorials/random_numbers/java_util_random_algorithm.shtml"]java.lang.Random algorithm and LCG … | |
Re: Look at the ByteBuffer class. You can wrap a ByteBuffer around some bytes that you need to decode, then set the byte order on the buffer to either little/big endian (or the machine's native type), then pull out ints etc. Similarly, to ENCODE a value in little/big endian, allocate a … | |
Re: Erm.. of course that last example is TCP, not UDP... @bachma7 -- if you're going to cross-post to multiple forums, please have the courtesy to tell people that that's what you're doing. In your [URL="http://www.java-forums.org/networking/14158-multi-clients-connect-udp-server.html"]previous post[/URL], I gave you some pointers and you mentioned you were getting an error and … | |
Re: Difficult to wade through this code, but general recommendations to start finding the problems: - if you're subclassing things like Ellipse2D, don't spuriously have extra variables like 'x', 'y' that duplicate functionality of the underlying class -- you'll just tie yourself in knots keeping them up to date. When you … | |
Re: As the previous poster mentioned, the easiest way to do this is to get your image into a BufferedImage somehow or other, then call getRGB() on the pixel you want. If your image is in a file, then you can usually call ImageIO.read() to load that image into a BufferedImage. … | |
Re: I don't think the fact that the machine is quad core should really make any difference -- all of your stuff is executing in one thread (the GUI thread) anyway. What may make more of a difference is how fasd a SINGLE core can run compared to your other machine. … | |
Re: Erm... silly question, but are you sure the file exists...? if you test (new File(filename)).exists(), what does it print? | |
Re: On average, you really wouldn't expect to perform so many recursions as to get a stack overflow error: even with your list size of 16,000, on average, you'd expect to go to around 14 or so levels of recursion (2^14 = 16384). But in the WORST case, quicksort will require … | |
Re: By the way, you should be very wary of just making your program call Runtime.exec() and "sitting back and relaxing": if the other process logs anything out (to either the standard output or error stream), you [B]must read the contents of those streams[/B] else things will generally freeze. If you … | |
Re: I think the way you're storing things is a little bit odd, and that's tying you in knots. You've declared variables that duplicate one another: on the one hand, you've got the separate 'day', 'month', 'year' variables. And on the other hand, you've got the Calendar. Start by deciding on … | |
Re: An important thing to understand is that there are [B]two types of exceptions[/B]: [LIST] [*][B]checked exceptions[/B], which are thrown when your code (or some code in the Java libraries) explicitly throws them; in this case, methods that throw such exceptions must be declared as throwing them, and code that calls … | |
Re: String.split() really can help you out, I think. If I understand rightly, the thing you're dissatisfied with is that the suggestion strips off the terminating punctuation from the strings. The expression's a bit more involved, but you can do something such as the following: [code] String[] sentences = str.split("(?<=[\\.!?]+)(?![\\.!?]+) *"); … | |
Re: You should never call sleep() in the UI thread (in other words, directly in response to a button click or some other UI handler). To make the variable visible from another thread, you need to declare it somewhere where it is visible! Possibilities include having a subclass of Thread that … |