Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

Rabbi Dan posted:

there is a recommendation in one of my assignment guidelines that i use the java debugger "jdb" but i can't figure out where it is.

it's definitely not in my jre/bin directory where java.exe is, but everything i find on it online says "just type jdb instead of java at the command line" and whenever I do that i get the not recognized command alert.

i'm using winXP.

can anyone help me get jdb running? i'd appreciate it a ton.

jdb should install in the same place as java and javac. If it didn't then you didn't get the JDK and you only got the JRE or some other poo poo that isn't the JDK.

Adbot
ADBOT LOVES YOU

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

zootm posted:

No, they don't. That's what the include directive does but the directive stuff is very old-school and sucks a whole lot; don't use it.

<jsp:include> can take arguments, though; so you can do something like this:
code:
<jsp:include page="nav.jsp">
  <jsp:param name="page" value="mortgages" />
</jsp:include>
These will appear as request parameters on the included page. Then you can just emit a different class depending on the current page/nav entry.

For what it's worth though JSP is probably the worst templating engine ever (other than perhaps "PHP", to which it is very similar), the XML-based version makes it only marginally better, and this sort of pain will haunt you until you stop using it.
While JSP by itself is definitely poo poo to use, do you really think JSP with JSTL and EL is that bad?

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

zootm posted:

Yeah. It bugs the crap out of me. JSTL and EL make it infinitely better, though, especially once you can externalise your own stuff out into custom taglibs.

Can I ask what you prefer using?

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

Lazlo posted:

I need a way to search for a value through a hierarchical list, while keeping track of each descent made. The hierarchy may have an arbitrary number of levels (nodes), though probably less than ten.

I think I can come up with a way to parse each line up using a Scanner, but I can’t think of a good way to keep track of where I’ve been in the hierarchy. Is there a package I could use to make navigating through the list easier?

Example of the input I want to process:
code:
    (1.1)HAS SDE CONTEXT:Subject Class(LNX,13254)[TAG] = Person(LNX,121025)
    (1.2)HAS SDE CONTEXT:Subject Name(LNX,134945)[PNAME] = NAME
    (1.3)CONTAINS:Person Characteristics(LNX,1435934)[CONTAINER] = {SEPARATE}
        (1.3.1)CONTAINS:SubCatagory1(LN,189316-6)[NUM] = 3 no units
        (1.3.2)CONTAINS:SubCatagory2(LN,13177-6)[NUM] = 2 no units
    (1.4)CONTAINS:Summary(LNX,1216511)[CONTAINER] = {SEPARATE}
        (1.4.1)CONTAINS:CDF(LN,15255-2)[DATE] = 20070524
        (1.4.2)CONTAINS:Con Summary(LNX,134568)[CONTAINER] = {SEPARATE}
            (1.4.2.1)HAS SDE CONTEXT:Con ID(LN,4321-1)[TEXT] = A
            (1.4.2.2)CONTAINS:Con X(LN,457621-1)[NUM] = 151 day
            (1.4.2.3)CONTAINS:Composite Age(LN134346-5)[NUM] = 133 day
            (1.4.2.4)CONTAINS:LGT rank(LN,123647-1)[NUM] =
                (1.4.2.4.1)INFERRED FROM:Table of Values Citation(LNX,34567)[TAG] = XYZ
.
.
.
    (1.10)CONTAINS:Findings(LNX,15671230)[CONTAINER] = {SEPARATE}
        (1.10.1)HAS CONCEPT MOD:Finding Site(SRT,G-C0E56)[TAG] = MOD Finding(SRT,T-F1300)
        (1.10.2)CONTAINS:Depth Index(LN,16723-7)[NUM] = 9.81 centimeter
            (1.10.2.1)HAS PROPERTIES:Normal Range Lower Limit(SRT,R-10751)[NUM] = 9.61 centimeter
            (1.10.2.2)HAS PROPERTIES:Normal Range Upper Limit(SRT,R-0055D)[NUM] = 21.5 centimeter
            (1.10.2.3)HAS PROPERTIES:Normal Range Authority(LNX,121528)[TAG] = AFI by GA, Moore et al.(99ALOKA,A18875-005)
In the above, if I am searching for “[NUM] = 9.81” I would find my value on line (1.10.2). I would want to parse up that line, store all the lines that are one below that node (1.10.2.x), and store the categories above it (1.10), and (1).

As long as this file format is a regular language and not gigantic, I'd personally write a small parser in ANTLR. You'd end up writing a baby parser anyhow, but with ANTLR you have a ton of tools to help you, plus it's drat good at its job.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

huge sesh posted:

So i'm working on a highway routing problem and it's looking fairly unavoidable that i'm going to be creating somewhere upwards of 300,000 objects (for the NY map, let alone the US) representing intersections that will be shrunk to allow faster queries. I have heard variously that this is a bad idea in java--object creation has a large overhead and the garbage collector will go crazy trying to keep track of everything.
Who told you this? Any modern jvm is very very good at creating objects and keeping gc to minimum.

In order (for me, at least) to help in any real capacity, can you answer these questions:

How large are the objects? How much RAM do you have to work with? Do you predict these objects will be very short lived or will they persist throughout the life of the appplication? Also, is this a desktop, server or mobile app?

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.
Where are you declaring a new ContentGetter?

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

mister_gosh posted:

As already stated, I tried to take out the fluff, such as variable declarations. I can tell that it is at the line marked HERE that it fails, based on my log4j output which I've also removed.

But that particular variable declaration might not be fluff. The only thing I can see that this could even possibly be is a scoping issue.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

JulianD posted:

I checked to see that's the problem after your suggestion, but I don't think that's it. I added this to my program to see how much memory I had before and after calling the last method of my program:

code:
double freeMem;
Runtime r = Runtime.getRuntime();
freeMem = r.freeMemory();
System.out.println("free memory after creating array:  " + freeMem);
I only declared freeMem and r once; I inserted the last two lines before and after the last method of my program. In doing so, the amount of available memory before and after was 3768200.0 and 3359536.0, respectively. The program doesn't appear to be out of memory, so am I interpreting this incorrectly or is it something else causing the problem?

If you want to see how much ram is available to your vm you should run jstat on the vm running your program. You can see how much ram is available to each object space (eden, survivor 0 and 1, old gen and permanent gen) over the duration of your program's lifetime. It's a really awesome tool and comes with the jdk.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

Cedra posted:

Since FreePastry is used with Java, I figured I'd ask here as well.


I'm using it with a Vista laptop and an XP desktop, though I've made 2 nodes within the same machine, and they see each other, but again, the logger does not provide any "recieved it" messages. :argh:

Windows firewall? Also, whenever I have network issues I always bust out wireshark.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

Cedra posted:

I wish I knew how to make it track my packets, because it doesn't seem to be doing such a thing. I'm doing the usual 'pick an interface then start capturing packets' but whenever I try to start a node nothing on Wireshark seems related to packets being sent around the FreePastry ring.

[edit]Scratch that, I tried capping packets between 2 physical machines and it works, it appears Freepastry wasn't using the NIC to send packets to itself, oops. Now I just need to make head and tail of this information :/

Unfortunately, Windows doesn't have a loopback adapter. You can't use libpcap to capture information on localhost, which is kind of stupid but them's the breaks.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

hexadecimal posted:

vvvv Sorry if this is a really newbie question, but where does tomcat store its logs?
By default it's $CATALINA_HOME/logs/catalina.out where $CATALINA_HOME is the Tomcat installation directory.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

hexadecimal posted:

I see catalina.<date>.log no files with .out extension. I don't see any useful information in those log files, however.

I have a hunch it could be because it runs out of memory, however, and the reason is because I get java.lang.OutOfMemoryError: PermGen space in another java program I run (not webservice, but makes HTTPRequests to webservice) on the same machine.

Is this a valid hunch?

Win32 or Linux or ?

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

fletcher posted:

What's an easy way to encode html entities with java?

Apache Common's StringEscapceUtils.
http://commons.apache.org/lang/

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

necrobobsledder posted:

So has anyone else messed around with dependency injection frameworks / libraries in Java? Google Guice seems to be fine for the jobs we've got, but we've got ourselves a home-brew dependency injection framework that is extremely clunky and I'm trying to get a better grasp on other options before overhauling the clunkiness we've got. I'm trying to keep it simple, but I do know I'm going to have to write a code generator to use any framework since what I'm working with is generated code that would take basically forever to perform the bindings manually. There aren't any dependency injectors that load class files and generate code for found classes according to some rules by chance, are there?

Spring has a DI framework and I've found it decently powerful. With annotations it's not too bad to use, and configuration with Groovy is pretty easy.

To answer your last question, do you have an example of what you're trying to do? If I understand you correctly, you want to do something similar to what Grails does. Grails (uses Spring) will load (and reload) arbitrary classes based on className by introspecting all classes in a given location. The "rules" are basically that the classes have to exist in a certain location. I'm sure you could do something similar.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

necrobobsledder posted:

Crazy poo poo.

Holy poo poo... Well, you *can* pull Spring apart, it's pretty modular.... but I don't think I'd try to do what you are doing with it.

Is there any reason you can't just bundle revisions of the APIs in individual jars and dynamically classload them depending on the version? You could then introspect the classes made available by that classloader (I found a particulary neat way of doing this just now), and make your interfaces that way. Then you don't have to play traffic cop. Or perhaps I still don't get it :smith:

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

Dire Penguin posted:

How do I tell how many elements are in an String array that I've created? If I read in a bunch of stuff to a String foo, then do foo.split() it gives me a String[] but if I want to loop through the elements I don't know how many there are.

e: it's foo.split().length.

e2: Different question. Is there any way to parse a line by quotes? I can't do foo.split(""");

e3: foo.split("\"");

You can also for-each over arrays if you're using JRE5+:
code:
for(String s:foo.split("\"")) {
//code
}

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

Pivo posted:

Hi guys, I'm using Eclipse at work to do Java web dev.

The previous programmer left a lot of useless (and now abandoned) poo poo going to System.out. There are thousands of lines of System.out to search through, many of them are valid. But there are also some annoying ones that happen without fail every 10-15 seconds and result in 09:37:45,585 INFO [STDOUT] null. Very useful. Is there any way I can set a breakpoint on System.out.println?

I figure if I had the JDK source code loaded, I could set a breakpoint on entry to that method, but I don't.

You can't Ctrl+Click into the method and see its source? I just have the standard 1.6 JDK and plain-jane Eclipse 3.4 and I can enter all of Java's standard classes.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

Pivo posted:

As a follow-up, it looks like a class called Logger intercepts stdout so the JDK println is never even called. And, of course, I don't have the source code for the logger. Honestly I've never done webdev in Java before this, anyone have any good links for a quick rundown of logging systems in JBoss? Nearly half of our server logs are [STDOUT] null and the logger logging messages about the logger.

Do you know the package Logger is in? I'll bet it's log4j or Apache Commons' Logger.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.
Hey Pivo, a really good Java tip I have for you is to ALWAYS google for the names of classes or messages displayed when programs throw stack frames. I just googled for "com.arjuna.ats.arjuna.logging.arjLogger" and found a whole bunch of people who asked the same question you did about excessive logging, right on the first page.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

Pivo posted:

Hey TRex, guess what page of Google I pulled that log-quote from? Oh and by the way, my question was only tangentially related to the topic of those particular log entries!

I work for a company that provides online tutoring to children in need. We tutor adults, as well. Would you be interested in learning about our services? Our English tutors are phenomenal!

Kid, I can't read your mind. I thought those were the actual log messages your program generated. Maybe if you were concise about the problem, we wouldn't be having this little exchange.

In any event, gently caress you. If you're gonna act like a noob and then get all bent out of shape when someone gives you a tip, perhaps you should learn how to solve simple problems like this on your own.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

Ghotli posted:

Edit: I've only scratched the surface of the available java frameworks. I come from a ruby on rails background where development speed, ease of use, and the community are a big deal. I looked for these qualities when delving in to the java world.

I'm gonna sound like a broken record but Grails is Java's answer to ROR... unless you just want to run ROR on JRuby.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

capr1ce posted:

What I need to do is store it in a database, and then it needs to be searched against and displayed, and maybe edited in an html form. Is there anything I can do to convert this string back to the 硼 character in the Java code, or is it perfectly fine to put the HTML String into the database and search on that?

Apache has StringEscapeUtils in their Commons Lang package:
http://commons.apache.org/lang/

Specifically, escapeHTML() and unescapeHTML() are what you are looking for.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

Warblade posted:

That's some nice syntatic sugar. Now I just want Java to introduce unsigned values. Which will probably never happen :(

What's sad is the jvm byte code interpreter actually uses unsigned short integers, and the Oak language (which was basically Java's daddy) had specific mention of allowing unsigned modifiers to integral types. Specifically, from the Oak spec:

quote:

Integer Types
Integers in the Oak language are similar to those in C and C++, with two
exceptions: all integer types are machine independent, and some of the traditional
definitions have been changed to reflect changes in the world since C was introduced. The four integer types have widths of 8, 16, 32, and 64 bits, and are
signed unless prefixed by the unsigned modifier.

but then, sadly, in the sidebar:

quote:

unsigned isn’t implemented yet; it might never be.

gently caress.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

HFX posted:

I often have to work with implementing network based protocols in Java. Java's lack of unsigned type can make this a lot harder then it should be.

The syntactic sugar isn't a huge bonus to me as I often design my code to prevent the need for such checks except in a few areas.

Items I would like Java to add:

  • Proper tail recursion handled by the VM. I'm a huge fan of functional languages.
  • Operator overloading. This can be terrible or great depending on programmer usage. I have certainly seen it abused.
  • True multiple inheritance so I can quit having to add interfaces which simply invoke a member instance which implements the interface. I guess an IDE could do this automatigically for me though so its not a big issue. Does bring about other issue though.
  • Finally, I'd like a method for notification of a garbage collections. This would allow me to cache unneeded objects in certain data structures and release them if the system needs memory.

We might be getting proper tail calls. I believe the JSR-292 defines them (part of the invokedynamic stuff, also known as MLVM)

in fact:
http://wikis.sun.com/display/mlvm/TailCalls

YES.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.
What do you need to know?

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

LilMike posted:

Alternatively, Warblade, check out the command line parameters for javac -source and -target, I think you'd want something like javac -source 1.3 -target 1.3... So it would only accept 1.3 compatible java and output 1.3 compatible bytecode. Bonus: you can specify these as attributes to the javac tag in your any build scripts.

I don't think that would help, since warblade was running into a library issue and not a classload or verifier issue. Eclipse allows you to set up different jvms to build against, I'm on the train right now but I'm pretty sure sun still provides legacy jvms for download.

e: here -> http://java.sun.com/j2se/1.3/download.html

trex eaterofcadrs fucked around with this message at 13:48 on May 1, 2009

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.
Sorry, I was rushed this morning and didn't look at the link too closely :(

Those sons of bitches made it hard to find, but here it is: http://java.sun.com/products/archive/j2se/1.3.1_20/index.html

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.
There's definitely a huge array of software in the Java ecosystem, so you end up with too much choice and it's hard to tell what libraries are best to use.

What are you trying to accomplish? All those technologies have a place (it seems by the names you tossed out you're going to make a webapp) but some (like Jboss and EJB) are overkill for many projects, just like others (Faces...) are not robust enough for enterprise-grade systems.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.
I had to do something similar... what I ended up doing was this:
code:
<%
    StringWriter writer = new StringWriter();
    pageContext.pushBody(writer);
    pageContext.include("generator.jsp");
%>
generator.jsp was the page that I wanted the string content of. You have to wrap it in an include like that or (at least in Tomcat 6.0.20) it will not feed the StringWriter.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

ssergE posted:

Not necessarily a webapp, but mainly server-side apps that use things like queues, topics, persistence, etc.

Would I be correct in thinking that I need to concentrate on either Seam+JBossAS or Spring?

Either of those choices (Seam or Spring) would be good. I personally use Spring a lot and I like it, but maybe I'm just used to it.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

rhag posted:

But, but....why?
Why not go the basic way of reading from a stream and writing into another? A way that works for any stream?

code:

OutputStream out=(whatever you want, FileOutputStream if you please)
InputStream in = (from wherever you got it from. network, file, memory....)

byte[] data=new byte[1024]; //this is how much data we're reading at once
int read=0;
while( (read=in.read(data))>=0)
{
  out.write(data,0,read);
}
out.close();
in.close();
and...its faster. I don't even want to look at your CPU reading byte after byte......
For local file transfer a higher buffer means faster transfer (ideally the HDD is the bottleneck not the CPU). For network...its tricky since the speeds are not anywhere close to HDD speeds.
usually 1k is just about enough.

Classes in the java.nio.channels package are even faster for reading/writing.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

Randomosity posted:

Hibernate question for everyone.

I've got a custom user type in several class. It works fine, the way it's supposed. However, any time I change a model, it does not mark the model as changed (and therefore, does not update the DB), unless another non-custom-type field is changed.

Any ideas on this?

I had this issue during development over a year ago. I just had to either manually modify the database or drop the table and let Hibernate recreate it, I never found a way around it.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

Randomosity posted:

e:removed for brevity

You might have to use Hibernate's collection annotations (@OneToMany I think) for Hibernate to realize it needs to handle List internals. That said, I DID just gently caress up the deepCopy() method on an immutable class for a UserType I implemented just last week (in Grails) and it caused Grails to trigger a db save. However, that class was not a List (Grails domain classes and Lists are a disaster).

Any particular reason you are using a UserType and not another mapped Entity collection? Don't get me wrong, I use them myself, but the DB I work with is solid poo poo. I'd tend to stay away from them if at all possible.

trex eaterofcadrs fucked around with this message at 20:21 on Jul 1, 2009

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

Edmond Dantes posted:

Ok, let's see...
I was handed a little proggie which combs a database, looks for different values (Select distinct), and then replaces them with different correlative numbers. This was done in order to "mask" a database so we lowly offshore code monkeys could not access sensitive information.

They realized this approach sucked, and now they want to use different kinds of "mask data" depending on the original data type.

So numbers (like phone numbers, ip addresses and such) will still be replaced by 1, 2, 3 and so on, but Strings will have to be replaces by, well, letters.

I thought about using randomly generated strings of a fixed length, but they need to be different for every distinct result on the original table, and I think checking every newly generated one to see if it hasn't been already used would be a mess. I was then thinking about an alphanumeric "counter"; is there any way of taking a string (let's say "AAAAAAA" for example's sake), and transform it into "AAAAAAB", "AAAAAAC" and so on and so forth?

Yeah, you can use BigInteger(String val, int radix);

I use this for base-36 (0-9A-Z) conversions.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

useless player posted:

So I've tried decompiling the main .class file and examining the source. The class constructor calls a method with a really weird name, $$$setupUI$$$(), which does not appear in the source file I was given. Searching through every source file for the string 'setupUI' turns up nothing. This really sucks, but I guess the class file is from another source.

Edit: Actually it turns out that the previous programmer worked on the project in an IDE and her computer crashed. I'm just working with the raw source files and that would explain the weirdness about compiling. Does anybody have any experience in a situation like this?

What's the fully qualified package for that class? I googled $$$setupUI$$$ and found a groovy project for the intellij ide here: http://www.jetbrains.net/jira/browse/GRVY-2045

Anything look familiar?

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

dealmaster posted:

Something similar to C#'s decimal primitive would be useful. Tracking down small rounding errors with doubles and floats is a huge pain in the rear end.

That's all BigDecimal is, the only dumb part is the lack of operator support for that and BigInteger (or all subclasses of Number, honestly). JDK7 was slated to bring operator support for that but, alas, it wasn't meant to be :(

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

dealmaster posted:

Yeah it's just too bad there's no primitive that'll do it, but at least they built the functionality into one of their standard library classes. It's just easier for actuaries and non-coders to look at:

code:
decimal x = 100.58;
decimal y = 2.3;
decimal z = x / y;
z += x;
than

code:
BigDecimal x = new BigDecimal(100.58);
BigDecimal y = new BigDecimal(2.3);
BigDecimal z = new BigDecimal( (x.divide(y)).doubleValue() );
z.add(x);

You could always use Groovy. By default fractional numbers are BigDecimals:
code:
def y = 2.3
println y.class
returns

code:
class java.math.BigDecimal
plus it has full operator support for any of java.lang.Number.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.
The jvm needs to perform extra work when unwinding stack frames. From what I understand, it has to rediscover the call path when an exception is thrown, since it doesn't keep the path around during normal calls.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

Anunnaki posted:

My CS teacher's been telling me it's a "hybrid." v:shobon:v

That's somewhat correct, although it's a lazy way of explaining it.

The bytecode is interpreted to machine code on the fly at first, until the hotspot just-in-time compiler identifies code that it should spend time compiling to native machine code. It looks for "hot spots" (hence the name) and it sends those units off for further optimization. At that point it's native code and therefore no longer interpreted.

Adbot
ADBOT LOVES YOU

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

FateFree posted:

How do i generate a random long from 1-7 billion, when there is no range function like there is with integer?

If it doesn't need to be cryptographically secure then you can use the same method they use in Random.nextInt(int n). In the javadoc they go over it:

All n possible int values are produced with (approximately) equal probability. The method nextInt(int n) is implemented by class Random as if by:
code:
 public int nextInt(int n) {
   if (n <= 0)
     throw new IllegalArgumentException("n must be positive");

   if ((n & -n) == n)  // i.e., n is a power of 2
     return (int)((n * (long)next(31)) >> 31);

   int bits, val;
   do {
       bits = next(31);
       val = bits % n;
   } while (bits - val + (n-1) < 0);
   return val;
 }
read the javadoc for caveats.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply