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
zootm
Aug 8, 2006

We used to be better friends.
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

Adbot
ADBOT LOVES YOU

Triple Tech
Jul 28, 2006

So what, are you quitting to join Homo Explosion?
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

csammis
Aug 26, 2003

Mental Institution
Implement a method StepTwo, make it a no-op in the base class, then override it in the children

code:
class ProfitModel
{
  public void StepOne() { SignUp(); }
  public void StepTwo() { /* ??? */ }
  public void StepThree() { CalculateProfit(); }
}

class AgricultureProfitModel extends ProfitModel
{
  @Override
  public void StepTwo()
  {
    PlantCrops();
  }
}

...

ProfitModel model = new AgricultureProfitModel();
model.StepOne();
model.StepTwo(); // plants crops
model.StepThree();
In C++ and C# that would be a virtual method.

Triple Tech
Jul 28, 2006

So what, are you quitting to join Homo Explosion?
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.

10011
Jul 22, 2007
You can also make ProfitModel.stepTwo abstract:

code:
public abstract class ProfitModel {
    protected void stepOne() { ... }
    protected abstract void stepTwo();
    protected void stepThree() { ... }
}
//...
Doing this means that ProfitModel can't be directly instantiated, only its subclasses, which might be what you want.

e: ^ also make the inner methods protected

Entheogen
Aug 30, 2004

by Fragmaster
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.

csammis
Aug 26, 2003

Mental Institution

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 :colbert:

Triple Tech
Jul 28, 2006

So what, are you quitting to join Homo Explosion?

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. :)

Fehler
Dec 14, 2004

.

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.

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.
dnsjava looks good, thanks for the links!

zootm
Aug 8, 2006

We used to be better friends.

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*.

* barring Java's retarded implementation of protected, there, I said it :colbert:
People who prefer stuff that's a little different might want to do this through composition:
code:
class ProfitModel implements Runnable
{
  private final Runnable step2;

  public ProfitModel( Runnable step2 )
  {
    this.step2 = step2;
  }

  public void run()
  {
    getPeopleToSignUp();
    step2.run();
    profit();
  }
}
Used with an anonymous Runnable it does what you want, either passing it inline or even doing this through inheritance:
code:
class AgricultureProfitModel extends ProfitModel
{
  public AgricultureProfitModel()
  {
    super( new Runnable() {
      public void run()
      {
        plantCrops();
      }
    } );
  }
}
code:
public ProfitModel getMarketingProfitModel( Masses masses )
{
  return new ProfitModel( new Runnable() {
    public void run()
    {
      masses.brainwash();
    }
  } );
}
Usually for that sort of thing it's advantageous to use an actual class for the given Runnable to make it more testable, but these techniques will hide the functionality more in the way you want I think.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
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:
LinkedHashMap<String, Product> originalProducts = new LinkedHashMap<String, Product>(products);
System.out.println(originalProducts);
products.get("something").name = "new product name";
System.out.println(originalProducts);
//originalProducts reflects the changes to products, not what I want

1337JiveTurkey
Feb 17, 2005

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.

clayburn
Mar 6, 2007

Cammy Cam Juice
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.

zootm
Aug 8, 2006

We used to be better friends.

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.
The project.xml file that NetBeans generates is incredibly small, the main stuff is in the "nbproject" directory. If you create a new project the build.xml you have will be almost exactly what you need (there will probably be references to the project name etc.). What's the issue you're having?

clayburn
Mar 6, 2007

Cammy Cam Juice
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

Entheogen
Aug 30, 2004

by Fragmaster
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:
 private static float _epsilon = 1e-3f;
    private int subdivide_count = 0;
    private void subdivide( int x1, int y1, int z1, int x2, int y2, int z2, TreeSet<Integer>[][] shpace )
    {       
        // base case 
         if( x2-x1 <= 1 || y2-y1 <= 1 || z2-z1 <= 1 ) return;
        
        subdivide_count++;
        // create new Treesets for 2 points if they are null.  
        if( shpace[ y1 ][ x1 ] == null )
        {
            shpace[ y1 ][ x1 ] = new TreeSet<Integer> ();
        }
        if( shpace[ y2 ][ x2 ] == null )
        {
            shpace[ y2 ][ x2 ] = new TreeSet<Integer> ();
        }
        shpace[ y1 ][ x1 ].add( z1 );
        shpace[ y2 ][ x2 ].add( z2 );
        
        

        // check this cube for uniformity.
        float theta = data[ y1 ][ x1 ][ z1 ][ 3 ];
        for( int x = x1; x <= x2; ++x )
        {

            for( int y = y1; y <= y2; ++y )
            {
                for( int z = z1; z <= z2; ++z )
                {
                    if( Math.abs( data[ y ][ x ][ z ][ 3 ] - theta ) > _epsilon )
                    {
                        subdivide( x1, y1, z1, ( x2 - x1 ) / 2, ( y2 - y1 ) / 2, ( z2 - z1 ) / 2, shpace );
                        subdivide( ( x2 - x1 ) / 2, y1, z1, x2, ( y2 - y1 ) / 2, ( z2 - z1 ) / 2, shpace );
                        subdivide( x1, ( y2 - y1 ) / 2, z1, ( x2 - x1 ) / 2, y2, ( z2 - z1 ) / 2, shpace );
                        subdivide( ( x2 - x1 ) / 2, ( y2 - y1 ) / 2, z1, x2, y2, ( z2 - z1 ) / 2, shpace );

                        subdivide( x1, y1, ( z2 - z1 ) / 2, ( x2 - x1 ) / 2, ( y2 - y1 ) / 2, z2, shpace );
                        subdivide( ( x2 - x1 ) / 2, y1, ( z2 - z1 ) / 2, x2, ( y2 - y1 ) / 2, z2, shpace );
                        subdivide( x1, ( y2 - y1 ) / 2, ( z2 - z1 ) / 2, ( x2 - x1 ) / 2, y2, z2, shpace );
                        //subdivide( ( x2 - x1 ) / 2, ( y2 - y1 ) / 2, ( z2 - z1 ) / 2, x2, y2, z2, shpace );

                        return;
                    }
                }
            }
        }
    }
The line that causes infinite recursion is the commented out call to subdivide. The other lines do not cause this. What is going on here. What am I missing?

Entheogen fucked around with this message at 03:54 on Jul 22, 2008

Entheogen
Aug 30, 2004

by Fragmaster

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

Save the whales
Aug 31, 2004

by T. Finn

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 :(

I know how to solve it now. I had overlapping elements anyway which I shouldn't have.

Bleh! Oh well, I'll post what I saw anyways in case it helps any.

code:
public class Main
{
  public static void main(String[] args)
  {
    subdivide(1, 1, 1, 5, 5, 5);
  }
  
  public static void subdivide(int x1, int y1, int z1, int x2, int y2, int z2)
  {
    System.out.println(x1 + ", " + y1 + ", " + x1 + ", " + x2 + ", " + y2 + ", " + z2);
    if (x2-x1 <= 1 || y2-y1 <= 1 || z2-z1 <= 1)  return; 
    subdivide( (x2 - x1) / 2, (y2 - y1) / 2, (z2 - z1) / 2, x2, y2, z2); 
  }
}
produces...

code:
1, 1, 1, 5, 5, 5
2, 2, 2, 5, 5, 5
1, 1, 1, 5, 5, 5
2, 2, 2, 5, 5, 5
1, 1, 1, 5, 5, 5
2, 2, 2, 5, 5, 5
1, 1, 1, 5, 5, 5
2, 2, 2, 5, 5, 5
1, 1, 1, 5, 5, 5
2, 2, 2, 5, 5, 5
1, 1, 1, 5, 5, 5
...etc

Entheogen
Aug 30, 2004

by Fragmaster
this is the new recursive function that is designed to do same thing but actually works.

code:
private void render_subdivide( float x1, float y1, float z1, float length, GL gl )
    {
        

        // base case
        if( length <= 1f + _epsilon )
        {
            render_subdivide_cube( x1, y1, z1, length, gl );
            return;
        }

        // check this cube for uniformity.
        float theta = data[ Math.round( y1 ) ][ Math.round( x1 ) ][ Math.round( z1 ) ][ 3 ];
        for( int x = Math.round( x1 ); x <= x1 + length && x < xDim; ++x )
        {
            for( int y = Math.round( y1 ); y <= y1 + length && y < yDim; ++y )
            {
                for( int z = Math.round( z1 ); z <= z1 + length && z < zDim; ++z )
                {
                    if( Math.abs( data[ y ][ x ][ z ][ 3 ] - theta ) > _epsilon )
                    {
                        float half_length = length / 2f;
                        //System.out.println( "=========== -> " + Integer.toString(  half_length ) );
                        render_subdivide( x1, y1, z1, half_length, gl );
                        render_subdivide( x1 + half_length, y1, z1, half_length, gl );
                        render_subdivide( x1, y1 + half_length, z1, half_length, gl );
                        render_subdivide( x1 + half_length, y1 + half_length, z1, half_length, gl );

                        render_subdivide( x1, y1, z1 + half_length, half_length, gl );
                        render_subdivide( x1 + half_length, y1, z1 + half_length, half_length, gl );
                        render_subdivide( x1, y1 + half_length, z1 + half_length, half_length, gl );
                        render_subdivide( x1 + half_length, y1 + half_length, z1 + half_length, half_length, gl );

                        return;
                    }
                }
            }
        }
       
        render_subdivide_cube( x1, y1, z1, length, gl );
    }
since it is meant to subdivide into cubes, I decided I should pass less variables. Just xyz for top front left coordinate and length. However, I have to keep the dimension of my data set to be power of 2.

Fehler
Dec 14, 2004

.
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.

zootm
Aug 8, 2006

We used to be better friends.
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.

Fehler
Dec 14, 2004

.

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.
Great, I didn't even know the Profiler could do that!

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...

Entheogen
Aug 30, 2004

by Fragmaster

Fehler posted:

Great, I didn't even know the Profiler could do that!

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...

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?

zootm
Aug 8, 2006

We used to be better friends.

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.
The finalizer is never what you want to use. If the memory isn't being freed when the object is no longer referred to, it's got a bug; however much more common is that the object itself is supposed to be dropped but isn't.

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?
It doesn't use native code, it's pure Java. Looking at the source I'm also pretty sure it doesn't have any leaks (which are most commonly caused by hanging references in pure Java code). I think you're looking in the wrong place Fehler.

Rebus
Jan 18, 2006

Meanwhile, somewhere in Grove, work begins on next season's Williams F1 car...


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 :mad:.

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

Entheogen
Aug 30, 2004

by Fragmaster
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?

zootm
Aug 8, 2006

We used to be better friends.

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?
I'm pretty sure it's not possible unless you know what the number should be, but then you wouldn't be trying to read it...

tef
May 30, 2004

-> some l-system crap ->
Use a flag bit.

BronYrAur
Jan 25, 2007
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:
Manifest-Version: 1.0
Created-By: 1.6.0_07 (Sun Microsystems Inc.)
Main-Class: GetUserNames
There are two carriage returns at the end there that don't seem to copy and paste but they are there.

I'm packaging the jar using command prompt on windows xp. I type the following

code:

jar -cvfm GetUserNames.jar manifest.txt *.class
Any ideas?

1337JiveTurkey
Feb 17, 2005

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:
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.7.0
Created-By: 1.4.2_15-b02 (Sun Microsystems Inc.)
Built-By: REDACTED
Main-Class: com.REDACTEDREDACTEDREDACTED.document.NewModelCreateDocume
 ntAction
Class-Path: REDACTED.jar REDACTED.jar REDACTED.jar

BronYrAur
Jan 25, 2007

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:

code:
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.7.0
Created-By: 1.4.2_15-b02 (Sun Microsystems Inc.)
Built-By: REDACTED
Main-Class: com.REDACTEDREDACTEDREDACTED.document.NewModelCreateDocume
 ntAction
Class-Path: REDACTED.jar REDACTED.jar REDACTED.jar

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?

1337JiveTurkey
Feb 17, 2005

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.

Entheogen
Aug 30, 2004

by Fragmaster
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:
public static FloatBuffer readFileIntoBuffer( File file ) throws FileNotFoundException, IOException
    {
        long s = file.length();
        System.out.println( "Volume file size = " + Long.toString( s  ));
        int n = (int) s / 4;
        FloatBuffer ret = BufferUtil.newFloatBuffer( n );
        FileInputStream file_input = new FileInputStream (file);
        DataInputStream data_in    = new DataInputStream (file_input );
        float max = 0;
        System.out.println( "Reading in file data.." );
        long start_time = System.currentTimeMillis();
        try
        {
            for( int i = 0; i < n; ++i )
            {
                float f = Swap.swapFloat( data_in.readFloat() );
                if( f > max ) max = f;
                //System.out.println( f );
                ret.put( f );
                if( i % (n/10) == 0 ) System.out.println( "Read in 10 %" );
            }
        }
        catch( Exception e )
        {
            System.err.println( "Couldn't read file for some reason" );
            e.printStackTrace();
        }
        ret.rewind();
        System.out.println( "Read time took " + Long.toString( System.currentTimeMillis() - start_time ));
the swapFloat method does not seem to be the bottleneck here, as removing it only saves about half a second at best. The culprit seems to be the readFloat() method.

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.

Outlaw Programmer
Jan 1, 2008
Will Code For Food
I'm not an NIO master but this seems to work almost instantaneously on my machine:

code:
    private static FloatBuffer fastRead(File file) throws IOException
    {
        FileChannel in = new FileInputStream(file).getChannel();
        try
        {
            ByteBuffer bytes = ByteBuffer.allocate((int) (file.length()));

            in.read(bytes);
            bytes.rewind();

            return bytes.asFloatBuffer();
        }
        finally
        {
            try { in.close(); } catch (IOException ex) { }
        }
    }

Entheogen
Aug 30, 2004

by Fragmaster

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

mister_gosh
May 24, 2002

What don't I understand here?

code:
public class abc {
  static String xyz;

  public void setXyz(String xyz) {
    this.xyz = xyz; 
  }
  public String getXyz() {
    return xyz;
  }
}
I have this abc class with a getter and setter (and other stuff). The parameter I pass to the setter should become the static variable value, so I'm using this.xyz = xyz. Is this wrong? Am I unclear on something?

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)

csammis
Aug 26, 2003

Mental Institution

mister_gosh posted:

What don't I understand here?

code:
public class abc {
  static String xyz;

  public void setXyz(String xyz) {
    this.xyz = xyz; 
  }
  public String getXyz() {
    return xyz;
  }
}
I have this abc class with a getter and setter (and other stuff). The parameter I pass to the setter should become the static variable value, so I'm using this.xyz = xyz. Is this wrong? Am I unclear on something?

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)

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.

mister_gosh
May 24, 2002

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.

schzim
May 24, 2006
tl;dr
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.

I have a string in a session attribute.

I am working with an off the shelf package which includes some jsf components.
I am using this component and want to set the value of one of the parameters to a string expression using the session variable.

....
<xxx:productView id="something"
color = "red"
filename = "C:/webdir/foo/"${session.getAttribute("fileName")}"
shape = "line"
//other stuff
</xxx:productView>

This does not seem to be able to work in any way that I have tried. I am certainly a JSP/JSF retard. So please educate me.

Adbot
ADBOT LOVES YOU

Outlaw Programmer
Jan 1, 2008
Will Code For Food

Entheogen posted:

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.

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).

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