|
Chinapwns posted:Why do people use arrays? This might sound stupid but it seems to me that ArrayLists are better in pretty much every way. You'll see char arrays used to store passwords (rather than String objects) because it's always passed by reference and is mutable (Strings are not the latter). This allows the password to be zeroed out when it's no longer needed, which prevents the password from being potentially dumped out as part of a heap dump. But, yeah, starting with Java 5, there's rarely a good reason to use an array over a List implementation. For what it's worth, I hope nothing you write is explicitly returning an ArrayList. You should always return a List reference, as that gives you the freedom to use whatever implementation of the List interface that you want without having to worry about passivity issues.
|
# ? Sep 10, 2010 05:06 |
|
|
# ? Mar 28, 2024 17:03 |
|
Chairman Steve posted:You'll see char arrays used to store passwords (rather than String objects) because it's always passed by reference and is mutable (Strings are not the latter). This allows the password to be zeroed out when it's no longer needed, which prevents the password from being potentially dumped out as part of a heap dump. edit: That would be difficult to implement in a web application unless the front end framework supported use of char arrays. Fly fucked around with this message at 15:53 on Sep 10, 2010 |
# ? Sep 10, 2010 15:46 |
|
Fly posted:I can't believe I've never considered that. Yeah, it's a pretty big deal actually. It's trivial to pull passwords out of running java apps which is why their physical security is important. If you look at any of the javax.crypto classes, using PBE always requires you to pass in a char [] as the password.
|
# ? Sep 10, 2010 17:20 |
|
TRex EaterofCars posted:Yeah, it's a pretty big deal actually.
|
# ? Sep 12, 2010 13:55 |
|
Alternatively, you could use Reflections to modify the underlying character array within a String object.
|
# ? Sep 12, 2010 16:36 |
|
I'm having trouble getting integer values from a byte buffer filled with signed 16 bit little endian audio samples. I am getting it mostly right, as strange as it sounds, but I'm getting little spikes in my data that look like this... The spikes have a difference with the rest of the curve of 256, 2^8 so I know that a I'm loving up my bits somewhere. This problem has been found and explained in this thread, however their solutions do not work for me. http://forums.sun.com/thread.jspa?threadID=5420508 These are methods I have tried, they all result in the same type of noise being introduced into my output. code:
code:
code:
Edit: Ended up writing my own wav file processor and reading the samples straight out of the file instead of relying on audioInputStream.read(). Oh well, at least it works. Kaltag fucked around with this message at 16:28 on Sep 14, 2010 |
# ? Sep 13, 2010 16:10 |
|
Kaltag posted:I'm having trouble getting integer values from a byte buffer filled with signed 16 bit little endian audio samples. Is there a reason you're not just switching the ByteBuffer's order into little-endian and then just getting a ShortBuffer view of it and reading straight from that? Short is Java's signed 16-bit integer type, after all.
|
# ? Sep 15, 2010 08:19 |
|
inklesspen posted:Is there a reason you're not just switching the ByteBuffer's order into little-endian and then just getting a ShortBuffer view of it and reading straight from that? Short is Java's signed 16-bit integer type, after all.
|
# ? Sep 15, 2010 16:16 |
|
Fly posted:He might want the 16 bit values to be unsigned, which would require using a larger type than short or Short. In that case he could use a CharBuffer. Char is Java's unsigned 16-bit integer type, after all.
|
# ? Sep 15, 2010 18:43 |
|
I'm at work right now and I'm working on pulling some data from Google Maps using their geocoding API. When I enter a url (example: http://maps.google.com/maps/api/geocode/xml?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=false) it displays a page written in xml format. How do I extract data from this using java? Specifically I'm looking for the formatted address and the lat/long coordinates. Any help at all would be much appreciated.
|
# ? Sep 15, 2010 19:15 |
|
Jewbert Jewstein posted:I'm at work right now and I'm working on pulling some data from Google Maps using their geocoding API. When I enter a url (example: http://maps.google.com/maps/api/geocode/xml?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=false) it displays a page written in xml format. How do I extract data from this using java? Specifically I'm looking for the formatted address and the lat/long coordinates. Read it in and use XPath to get what you want out of it.
|
# ? Sep 15, 2010 19:24 |
|
Jewbert Jewstein posted:I'm at work right now and I'm working on pulling some data from Google Maps using their geocoding API. When I enter a url (example: http://maps.google.com/maps/api/geocode/xml?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=false) it displays a page written in xml format. How do I extract data from this using java? Specifically I'm looking for the formatted address and the lat/long coordinates. If you can use groovy at all it's really pitifully easy: code:
|
# ? Sep 15, 2010 19:29 |
|
osama bin diesel posted:Read it in and use XPath to get what you want out of it. OK, but how do I get the results to change from just a bunch of text in my browser to an xml file that I can use XPath on?
|
# ? Sep 15, 2010 20:52 |
|
Jewbert Jewstein posted:OK, but how do I get the results to change from just a bunch of text in my browser to an xml file that I can use XPath on? Open the URL in Java instead of your browser http://download.oracle.com/javase/tutorial/networking/urls/readingURL.html
|
# ? Sep 15, 2010 21:03 |
|
Well that depends how you are accessing the data. If you are accessing it inside a program make a URL object out of it and open a stream to it and feed the stream into DocumentBuilder (iirc). If you just want to save what is in your browser go to file and save as.
|
# ? Sep 15, 2010 21:07 |
|
Worked! Thanks guys!
|
# ? Sep 15, 2010 21:34 |
|
If you ever need to do anything beyond a simple URL (POST parameters, and possibly even for a URL with a query string), Apache's HttpClient library is pretty durn nice: http://hc.apache.org/httpclient-3.x/
|
# ? Sep 16, 2010 00:59 |
|
Im rather new to Java so can anybody help we out with this problem: I want to take 100 random generated numbers (from 1 to 6) from a array and count the times each number occurs without using any if statements or switch statements anywhere. Basically where i am at now i have created a two dimensional array that sort each numbers into coloumns like this: code:
So any tips? HKBGUTT fucked around with this message at 12:47 on Sep 26, 2010 |
# ? Sep 26, 2010 12:33 |
|
You're trying to do it all at once. Break down the problem to smaller pieces, do one piece at a time and print out each piece's internal values to make sure they are what you intended.
|
# ? Sep 26, 2010 12:47 |
|
I am in posted:You're trying to do it all at once. Break down the problem to smaller pieces, do one piece at a time and print out each piece's internal values to make sure they are what you intended. code:
|
# ? Sep 26, 2010 15:45 |
|
Well i need to the following things: 1)Print all the numbers. 2)Find the average of all the numbers. 3)Find the number that occured the most. 4)Measure how long before the number '6' was generated. 5)Never use IF or SWITCH. So i need to save all the numbers somehow.
|
# ? Sep 26, 2010 16:18 |
|
HKBGUTT posted:Well i need to the following things: How are you going to test for whether a number is a six without using if or some horrible hack?
|
# ? Sep 26, 2010 16:27 |
|
Hey, now- the ternary operator isn't necessarily a horrible hack. Depending on how that list of output needs to be returned, you still don't necessarily need to store all the numbers.
|
# ? Sep 26, 2010 16:59 |
|
But you can easily translate any one-way conditional statement into a for-loop, to get around the "don't use an if" restriction:code:
code:
Sorry, I thought this was the Coding Horrors thread for a second.
|
# ? Sep 26, 2010 17:05 |
|
Yeah it is a school asignment, and the asignment says: Dont use If or Switch for some reason. And it also specifies that the random numbers must be added to a array.
|
# ? Sep 26, 2010 17:18 |
|
Jonnty posted:How are you going to test for whether a number is a six without using if or some horrible hack? Use a state-machine!
|
# ? Sep 26, 2010 17:25 |
|
HKBGUTT posted:Yeah it is a school asignment, and the asignment says: Dont use If or Switch for some reason. And it also specifies that the random numbers must be added to a array. Ah. Presumably they're doing the "we want to teach these concepts by forcing you to use then for a problem where they don't actually belong" thing programming courses like to do.
|
# ? Sep 26, 2010 17:27 |
|
HKBGUTT posted:Yeah it is a school asignment, and the asignment says: Dont use If or Switch for some reason. And it also specifies that the random numbers must be added to a array. use while(), be all
|
# ? Sep 26, 2010 17:40 |
|
Yeah, so far the only sollution i've found is to use some horrible combinations of while and for loops but it really looks terrible. Elegance is not specifically required in this task, but still.
|
# ? Sep 26, 2010 18:01 |
|
This isn't tested, but this should get you going:code:
|
# ? Sep 26, 2010 18:07 |
|
I have a very specific problem. I have a java program that monitors an executable's PID (well, actually it monitors the javaw.exe launched by this parent executable, so I can't get it by any conventional means I've come across). The program sleeps in a loop until that PID disappears. Up until now, I've been using a Runtime exec call to tasklist.exe and parsing its output. The problem is that tasklist is not a native executable in Home versions of Windows (and the other problem, naturally, is that this program will only work on windows). Is there a way to call up a master list of processes and subprocesses natively in Java? I'm not averse to installing custom packages.
|
# ? Sep 26, 2010 19:50 |
|
Vergeh posted:Is there a way to call up a master list of processes and subprocesses natively in Java? I'm not averse to installing custom packages. If you're using Sun's JDK 1.5 or newer then there is a native executable called jps that lists all Java processes. It seems jps is implemented at least partially in Java, so you might be able to use its source code as a guide. It's located in package sun.tools.jps, I think.
|
# ? Sep 26, 2010 20:11 |
|
I'm trying to use a StringTokenizer and I need it to count anything that isn't a character of the regular alphabet as a delimiter, for example: "the, thr3e people." will result in: the thr e people Is there an easy way to set up this delimiter besides manually typing in every single possible non-alphabetic character?
|
# ? Sep 27, 2010 21:19 |
|
StickFigs posted:I'm trying to use a StringTokenizer and I need it to count anything that isn't a character of the regular alphabet as a delimiter, for example: Sound like something regular expressions were made for.
|
# ? Sep 27, 2010 21:22 |
|
Does anyone know of a solid library for parsing/tokenizing java sourcecode? I'm dealing with some hairy code generation/emission stuff related to a test framework, and I really don't like the idea of simply tossing some regular expressions at the problem. Ideally, I'd like to be able to just walk through an AST and identify expressions so I can add logic to deal with some new operators and semantics.
|
# ? Sep 27, 2010 21:28 |
|
Sereri posted:Sound like something regular expressions were made for. Where would I find a list of regular expressions useful to my situation?
|
# ? Sep 27, 2010 21:43 |
|
Internet Janitor posted:Does anyone know of a solid library for parsing/tokenizing java sourcecode? I'm dealing with some hairy code generation/emission stuff related to a test framework, and I really don't like the idea of simply tossing some regular expressions at the problem. ANTLR, a parser generator for Java, has a grammar for parsing Java 1.5 as one of its examples. It's not the easiest program to work with, but it should be able to do what you want.
|
# ? Sep 27, 2010 21:47 |
|
StickFigs posted:Where would I find a list of regular expressions useful to my situation? I'd combine this and this The regex in case should be [a-zA-Z] /E: JavaDoc posted:StringTokenizer is a legacy class that is retained for compatibility reasons although its use is discouraged in new code. It is recommended that anyone seeking this functionality use the split method of String or the java.util.regex package instead. Sereri fucked around with this message at 21:51 on Sep 27, 2010 |
# ? Sep 27, 2010 21:47 |
|
I have been looking far and wide for a Math resource to use with Java Micro Edition. There seems none to be found that provides sinh() and atan(), or even just exp() and pow() to build the formulars myself. Edit: To be specific, I need to make this work in Java Micro Edition code:
This mostly sorted itself out. Jave ME's Math-class not having exp(), pow() and log() kinda blows, thought. Mayheim fucked around with this message at 12:47 on Sep 28, 2010 |
# ? Sep 28, 2010 07:54 |
|
|
# ? Mar 28, 2024 17:03 |
|
Here's really candid interview with James Gosling - some interesting tidbits, including a bit about microSPARC that was a touchscreen LCD in the early 90s - which the people leading that were heavily involved with the iPad later. http://basementcoders.com/?p=721 http://www.basementcoders.com/transcripts/James_Gosling_Transcript.html
|
# ? Sep 29, 2010 05:01 |