|
I think the libraries just use the OS stuff transparently, and there isn't a direct way to do that. I imagine there's about a billion libraries available for it though. Edit: Actually it looks like this might let you access stuff through JNDI, although the one "review" of it I saw didn't seem to rate it highly. This library looks a bit more direct, and is allegedly used by quite a few projects. zootm fucked around with this message at 09:24 on Jul 14, 2008 |
# ? Jul 14, 2008 09:19 |
|
|
# ? May 11, 2024 12:30 |
|
Hello. Not a Java person, but I had an OOP question and would like to know how it's implemented in Java. In C++ I think you can call it private inheritance, but according to Google it may be called composition or delegation in Java? Basically it's something that can be solved by an anonymous function... Let's say I have ProfitModel.run() which looks like this 1) Get people to sign up. 2) ??? 3) Profit! And other classes subclass (maybe?) the ProfitModel and implement step 2. It's like... a driver. AggricultureProfitModel 2) Plant crops. MarketingProfitModel 2) Brainwash masses. What is this pattern called and how do you solve it in Java? Or rather, in proper OOP? Addendum: Also, I forgot to add, this block of code should never be called by itself or be exposed to the public. It only exists as part of the process. That's why I figured a plain old virtual method wouldn't be as classy as something more formal. Triple Tech fucked around with this message at 17:07 on Jul 14, 2008 |
# ? Jul 14, 2008 16:48 |
|
Implement a method StepTwo, make it a no-op in the base class, then override it in the childrencode:
|
# ? Jul 14, 2008 17:02 |
|
Also, I forgot to add, this block of code should never be called by itself or be exposed to the public. It only exists as part of the process. That's why I figured a plain old virtual method wouldn't be as classy as something more formal.
|
# ? Jul 14, 2008 17:07 |
|
You can also make ProfitModel.stepTwo abstract:code:
e: ^ also make the inner methods protected
|
# ? Jul 14, 2008 17:08 |
|
how can I request more heap space for JVM at run-time? Also what would be a way to request more heap memory in JNLP file? I googled some solutions but none of them worked. What I would like to do is run -Xmx500m from inside JNLP but I am not sure how.
|
# ? Jul 14, 2008 17:25 |
|
Triple Tech posted:Also, I forgot to add, this block of code should never be called by itself or be exposed to the public. It only exists as part of the process. That's why I figured a plain old virtual method wouldn't be as classy as something more formal. What sort of metric is "classy," and how are virtual methods informal? A virtual (abstract) method is exactly what you want here, and like 10011 said it'd just be protected if you didn't want callers to access it*. * barring Java's retarded implementation of protected, there, I said it
|
# ? Jul 14, 2008 18:22 |
|
csammis posted:What sort of metric is "classy," and how are virtual methods informal? A virtual (abstract) method is exactly what you want here, and like 10011 said it'd just be protected if you didn't want callers to access it*. Well, I use Perl, nearly all of the time, which has the least classy of OOP implementations. So, when I read "virtual method" in Perl-parlance, I get "public method with a die" because all methods in Perl are public. The concept of privacy is completely a social convention. So, I figure, when I'm learning OOP, I would do my best to learn the proper terminology and concepts, so when I graduate to a less ghetto language, I can continue to use the concepts properly in a local vocubulary.
|
# ? Jul 14, 2008 18:30 |
|
zootm posted:I think the libraries just use the OS stuff transparently, and there isn't a direct way to do that. I imagine there's about a billion libraries available for it though.
|
# ? Jul 14, 2008 18:39 |
|
csammis posted:What sort of metric is "classy," and how are virtual methods informal? A virtual (abstract) method is exactly what you want here, and like 10011 said it'd just be protected if you didn't want callers to access it*. code:
code:
code:
|
# ? Jul 14, 2008 19:27 |
How do I make a copy of a LinkedHashMap? I want to modify products, but keep a copy of what the LinkedHashMap looked like before I modified the products. I thought declaring a new instance of a LHM and passing in the old one would work, but when I modify products, originalProducts is also modified. The clone() method for a LinkedHashMap doesn't seem at all useful, since it doesn't copy keys/values (what is it for?). code:
|
|
# ? Jul 16, 2008 01:11 |
|
It's a shallow copy because there's no way for the implementor to really know what the cloning semantics of your keys and values are. Requiring everything put in the HashMap to implement Cloneable or having one HashMap for Cloneables and one for non-Cloneables would make collections less generally useable. The alternative would be having a clone() method which does a deep copy when its contents implement Cloneable and a shallow copy otherwise would just be inviting trouble. In other words, you're going to have to do it manually.
|
# ? Jul 16, 2008 01:34 |
|
Anyone know how to restore the build.xml file that NetBeans creates? I have a project and somehow mine got messed up and now it won't compile.
|
# ? Jul 18, 2008 00:06 |
|
clayburn posted:Anyone know how to restore the build.xml file that NetBeans creates? I have a project and somehow mine got messed up and now it won't compile.
|
# ? Jul 18, 2008 00:25 |
|
Well I had it working fine, then I started working on another project and since then the other one has been messed up. Now that you say that though I think I may know more what the problem is, so thanks for pointing that out. Is there a way to fix the nbprojects files? I still have all of the source code but those have somehow gotten messed up. clayburn fucked around with this message at 00:32 on Jul 18, 2008 |
# ? Jul 18, 2008 00:29 |
|
I have a stack overflow error due to infinite recursion. here is function which subdivides cube into 8 subcubes based on whether all points are uniform to certain epsilon in the cube or not. Here is the code: code:
Entheogen fucked around with this message at 03:54 on Jul 22, 2008 |
# ? Jul 22, 2008 03:11 |
|
Entheogen posted:weird Ok, I figured it out. if x1=y1=z1=16 and x2=y2=z2=49 for example it runs in infinite loop because 49-16 / 2 = 16 I know how to solve it now. I had overlapping elements anyway which I shouldn't have. EDIT: ok that didn't work either. I guess I will just need a hash array of coordinates i have been to and return if they are already in place. Poor man's memoization I guess. Can anybody suggest a better method? Entheogen fucked around with this message at 04:16 on Jul 22, 2008 |
# ? Jul 22, 2008 04:13 |
|
Entheogen posted:Ok, I figured it out. if x1=y1=z1=16 and x2=y2=z2=49 for example it runs in infinite loop because 49-16 / 2 = 16 Bleh! Oh well, I'll post what I saw anyways in case it helps any. code:
code:
|
# ? Jul 22, 2008 04:17 |
|
this is the new recursive function that is designed to do same thing but actually works.code:
|
# ? Jul 22, 2008 23:34 |
|
I have a Java program that starts three threads. These threads all run infinite (while true) loops that selects a few hundred rows from a MySQL database, do a few things with them and insert them back into the table. This works fine for a while, but the memory usage rises and rises, and after approximately two hours, Java runs out of heap space and crashes. From the Netbeans Profiler's output, it looks like most of the memory is used by int[] arrays that are becoming bigger and bigger as the program runs. I have already commented out all the code that was responsible for the calculations and the inserting back into the table, but the problem still seems to exist. Does anybody here have an idea what might create these arrays and how to get rid of them? I don't use int[] anywhere in my code so it must be some part of Java or a library.
|
# ? Jul 24, 2008 11:24 |
|
Profilers can usually track where allocations happen as well as what was allocated, I'd investigate that. Is it possible that you're keeping one massive transaction open, or just re-using something that's supposed to be discarded? I'd guess it's somewhere in the database connector but I've really no idea I'm afraid.
|
# ? Jul 24, 2008 11:50 |
|
zootm posted:Profilers can usually track where allocations happen as well as what was allocated, I'd investigate that. Is it possible that you're keeping one massive transaction open, or just re-using something that's supposed to be discarded? I'd guess it's somewhere in the database connector but I've really no idea I'm afraid. Thanks to your suggestion I found out that the java.net.IDN conversion class uses pretty large amounts of memory for every single conversion and doesn't free them up afterward. Now I just need to find out how to stop that...
|
# ? Jul 24, 2008 16:59 |
|
Fehler posted:Great, I didn't even know the Profiler could do that! I believe you want to look into finalize() method. You can overload that for your class and it will get called by garbage collector when it frees that object from heap. I don't know how IDN class works, but perhaps it has handle to some native resources and is not designed to free them? This is usually how memory leaks occur in Java. You could perhaps write your own class extending from IDN and then free whatever IDN doesn't?
|
# ? Jul 24, 2008 18:06 |
|
Entheogen posted:I believe you want to look into finalize() method. You can overload that for your class and it will get called by garbage collector when it frees that object from heap. In the case of java.net.IDN the methods are all static and it cannot be overridden or instantiated anyway, so the point is moot, but in general if you think it's a good idea to use a finalizer you're likely to be wrong. They're sadly not very useful. Entheogen posted:I don't know how IDN class works, but perhaps it has handle to some native resources and is not designed to free them? This is usually how memory leaks occur in Java. You could perhaps write your own class extending from IDN and then free whatever IDN doesn't?
|
# ? Jul 24, 2008 20:53 |
|
I am having a problem making my menus appear on top when they 'pop up'. I know this is a problem with mixing heavyweight and lightweight components, and I have been trying to force the menus to be heavyweight but to no avail. I have been trying to set the menus to be heavyweight by calling this method after the menu has been instantiated: [menuname].getPopupComponent().lightWeightPopupEnabled(false); Here is an image showing my problem: http://www.inf.brad.ac.uk/~jpcatter/menus.jpg On the sun forums, it was suggested that I should "not use both swing and awt in the same application". The component that is causing the trouble is mozswing, not an awt component, so they can gently caress themselves . Here is a link to the mozswing homepage for anyone who is interested: http://confluence.concord.org/display/MZSW/Home Edit: Problem solved: I was setting the lightWeightPopupEnabled(false); flag for each separate JMenu, rather than the JMenuBar. Rebus fucked around with this message at 22:21 on Jul 27, 2008 |
# ? Jul 27, 2008 19:00 |
|
How can I determine endianess of a floating point number at run time? That is, I am reading a binary file and I would like to determine whether I should reverse the bits or not. Is this even possible?
|
# ? Aug 1, 2008 02:08 |
|
Entheogen posted:How can I determine endianess of a floating point number at run time? That is, I am reading a binary file and I would like to determine whether I should reverse the bits or not. Is this even possible?
|
# ? Aug 1, 2008 09:23 |
|
Use a flag bit.
|
# ? Aug 1, 2008 11:06 |
|
This isn't java code related but java related. I am trying to create a .jar file to package up 3 classes so it can be run by others without having random class files floating around. The issues is the .jar file says "Could not find the main class. Program will exit." All searches on google point to a manifest problem. However my manifest file is included and correct "Main-Class: GetUserNames" is in there like it should be. My manifest.mf looks like this: code:
I'm packaging the jar using command prompt on windows xp. I type the following code:
|
# ? Aug 1, 2008 20:49 |
|
Did you fully qualify the name? You can't just say GetUserNames if it's actually com.example.GetUserNames, then you need to add that so it knows what package to look in. If it goes above 70 characters (I think this is the right number), then you should truncate the line at that point and continue on the next, leading with a whitespace. Here's an example created by Ant that I built yesterday:code:
|
# ? Aug 1, 2008 23:24 |
|
1337JiveTurkey posted:Did you fully qualify the name? You can't just say GetUserNames if it's actually com.example.GetUserNames, then you need to add that so it knows what package to look in. If it goes above 70 characters (I think this is the right number), then you should truncate the line at that point and continue on the next, leading with a whitespace. Here's an example created by Ant that I built yesterday: That's the name of the class file itself. All it contains is the one class with a main method, is there something I am missing with this whole package thing?
|
# ? Aug 2, 2008 01:56 |
|
The idea with packages is that they mirror your file structure. So you have a folder under your source root called 'com', a folder under that called 'example' and under 'example' you put your source file 'ExampleFactoryStrategy.java'. When you compile, the output would go in an output directory with the same 'com' and 'example' folders. When you want to refer to that class, you've got to call it 'com.example.ExampleFactoryStrategy' for it to be able to distinguish it from potentially many files named that in the JAR. If you look through the JAR files in your JRE, you can see how the folder structure is parallel to that of the packages in the Javadoc. That's how the ClassLoader finds your file: It looks in the JAR for the folder corresponding to your package and then looks for the class file with the right name inside that folder. If you don't have the right files in the right folders in your JAR file, then it won't be able to find it and you'll get that error.
|
# ? Aug 2, 2008 02:10 |
|
I am reading in a binary file full of 4byte floats and it takes about 10 seconds to read in an 8mb file. Is there any way to speed this up? Currently I use DataInputStream and use readFloat() on it to read next float. Here is an example code:
What would be a much faster way of quickly reading in a big binary file full of either floats or doubles into an nio buffer? Thank you in advance.
|
# ? Aug 4, 2008 05:18 |
|
I'm not an NIO master but this seems to work almost instantaneously on my machine:code:
|
# ? Aug 4, 2008 06:39 |
|
Outlaw Programmer posted:cool stuff. Wow, that is awesome. Thank you very much, brother. This also read the file in correct endianess without me having to reverse the bits. Does this always happen? when i do "asFloatBuffer", does it always try to give the correct endianess? There seems to be a bit of magic involved. Entheogen fucked around with this message at 16:15 on Aug 4, 2008 |
# ? Aug 4, 2008 14:30 |
|
What don't I understand here?code:
Netbeans 6 throws a warning that this.xyz is "Accessing static variable". The same code in Netbeans 5 does not mention the warning. (I could just call the parameter "x" and set it by saying xyz = x) but I want to call the variable what it is if possible)
|
# ? Aug 4, 2008 16:01 |
|
mister_gosh posted:What don't I understand here? It's wrong because xyz is static (it "belongs" to the class, not an instance of the class), so it doesn't exist in this. Technically you can reference it with this, but it's not semantically correct so Netbeans 6 promoted it to a warning. A static analysis tool like Findbugs would've flagged it. You can properly reference it with abc.xyz. edit: And also you might be questioning your design when you have instance methods getting and setting a static member variable.
|
# ? Aug 4, 2008 16:11 |
|
Thanks csammis. There was a lot more code hidden, obviously, and I had forgotten why I had made the variable a static class variable. As it turns out, the scope in my code is wrong, this is an instant variable which changes things, so I feel embarrased.
|
# ? Aug 4, 2008 16:57 |
|
Cross Posting This question about JSP and JSF from the web questions megathread.schzim posted:JavaSeverFaces and JavaServerPage Goons to the rescue please k thnx.
|
# ? Aug 4, 2008 21:38 |
|
|
# ? May 11, 2024 12:30 |
|
Entheogen posted:Wow, that is awesome. Thank you very much, brother. According to this site, the JVM will take care of any endian problems for you. I guess you only run into endian problems if your output is being read by a non-Java process (or your file is being generated by a non-Java process).
|
# ? Aug 5, 2008 00:36 |