Results 1 to 16 of 16

Thread: Java On Linux

  1. #1
    Natrix is offline Member
    Join Date
    Mar 2009
    Posts
    40
    Rep Power
    0

    Default Java On Linux

    Well I am sick of Windows and theres two things keeping me from going all Linux on all teh computers I have. These two things are astronomy and Java. Astronomoy really doesn't have much support on Linux (telescope control, DSLR, CCD, CMOS control for cameras etc..) and one thing I want to do when I get to know Java more is to fix that uncompatibility with some custom software just for me.

    Anyways the other thing keeping me on Windows is Java itself. It appears that Java sucks on Linux, at least as far as I got to use it.
    Theres this nice assignment we had and it had like 7 programs in Java manipulating the JFrame. We spinned it around the screen, made it bounce of the screens edges etc. On windows theres actualy no problem with the code I wrote and everything works just fine. But running it on Linux makes the system freeze in a few seconds. The JFrame is only a dot on the screen and it grows over the seconds till its like 1/8th of what its suppose to be. It does move for a while (4 seconds) and then Linux just freezes and I have to do a restart.

    Also the tables give me some sort of errors that don't even exist on Windows. Even when I start BlueJ (yeah thats what we're using) I get some random freaky looking errors in the terminal window even without running any applications, its just there when the program loads the "project".

    Is this common experience with Java in Linux?
    Is it because I have Open JDK installed instead of sun-java6 JDK (altho I think I did install it yesterday but can't remember if it went through because it got stuck at "configuring sun-java6)?
    Is there any step through guidelines to configuring and using Java on Linux?

    The same thing (the freezing thing) happens when I run things in NetBeans or Eclipse.

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    When using Java on Linux machines do make sure you are using Open JDK or Sun's (both should be OK). This is not always as simple as just installing them as the gcj (I think that is what it's called) is often hanging around.

    I have had problems in the past with Eclipse not running (crashing at startup with horrendous errors) because I hadn't realised what was going on.

    [Edit] And another gotcha is that Swing has problems with some of the desktop "eye candy". At any rate, it used to: I've haven't really followed this as I have better things to do with my CPU than have the windows wobble...
    Last edited by pbrockway2; 04-03-2009 at 10:54 AM.

  3. #3
    mcfrog's Avatar
    mcfrog is offline Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    32
    Rep Power
    0

    Default

    I also migrated from a WindowsXP-Machine to Linux. I am using Kubuntu 8.04 which is shipped with gcj. gcj is really too slow especially with Eclipse and a Tomcat Server. Then I installed Sun's Java 6 which is good, but not with Tomcat and lots of ant webuild-reloads, because after a while a PermGenSpaceException ocurrs.

    Now I am using BEA's JRock 6 which has a built-in JIT-compiler, and it really rocks.

    Well I don't feel any speed-up due to the JIT but the PermGenSpaceException is gone. It is freely available, though the webpage is really crumpy. Anways, BEA claims to cover 100% of the Java-Calls from the Sun JRE.

    In terms of eye candy I don't have any answers because I don't use Swing or JFace or similar.
    Cheers / beste Grüße / lepo pozdravje
    8=:(=)D . · ° o O ( Save the Giraffes )

  4. #4
    Natrix is offline Member
    Join Date
    Mar 2009
    Posts
    40
    Rep Power
    0

    Default

    So you would say that Java should work ok on Linux?

    I dont know why but it still seems to me like theres a problem with Java on Linux. When I use Java on windows I get 70% less errors than I do in Linux and some of those errors are as far as I can tell not even code related. I know for sure that Open JDK is installed and BlueJ configured to work with it.

    I cant really switch to wnother IDE because BlueJ is what we use in school and I somehow got used to it.

  5. #5
    mcfrog's Avatar
    mcfrog is offline Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    32
    Rep Power
    0

    Default

    yes, I would sign that one. Java should work on Linux. As it should work on almost every mainstream operation system. Eclipse works perfectly on Linux (except the one or two platform-dependent plugins).

    But that is not interesting. Obviously you mix the question does work java on linux with the next question: Does the migration of my IDE to Linux with all the pitfalls of a new operating system etc work well.

    I cannot tell. If you have better support for BlueJ under Windows I'd suggest to stay there rather than migrating to an OS that you barely know.
    Cheers / beste Grüße / lepo pozdravje
    8=:(=)D . · ° o O ( Save the Giraffes )

  6. #6
    Natrix is offline Member
    Join Date
    Mar 2009
    Posts
    40
    Rep Power
    0

    Default

    But the only way to learn how linux works and how to work on linux is to use linux and without Java on linux the use of linux is close to zero.
    The only good thing on linux left is the OS itself (which doesn't make me a happy Java user) and the use of LaTeX.

    I could switch to Eclipse but it would take away loads of my precious time. :)

    I don't like eclipse making those "error" circles next to everything I write.

  7. #7
    mcfrog's Avatar
    mcfrog is offline Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    32
    Rep Power
    0

    Default

    Hehe :) For me Eclipse works out-of-the-box, even with gcj. But i understand what you mean, because your project structure may be quite different than that used by eclipse (which may be customized).

    Do you mean by "error circles" the compile errors that ocurr when you type your code? You can disable the automatic building and start the build-process manually. ;)

    Nevermind, I work now almost two years with Java under Linux and it still rocks... I took a look at the BlueJ HP. nice, with UML and stuff. Perhaps I take a deeper look in a while.

    But one last thing. You may stay away from Eclipse but leaving that out you may also leave out your own future. currently, beside netbeans, eclise is THE IDE to develop in enterprise environments. Sooner or later you gotta switch to one of them, and then some experince would really come in handy.
    Cheers / beste Grüße / lepo pozdravje
    8=:(=)D . · ° o O ( Save the Giraffes )

  8. #8
    Natrix is offline Member
    Join Date
    Mar 2009
    Posts
    40
    Rep Power
    0

    Default

    I wouldn't mind using eclipse if the build, compile, debug would funciton in a nicer way. In BlueJ you just click twice and voila. I admit that I didn't spend more than 10 minutes in Eclipse but its just so repeling.
    And one major problem with Eclipse is that I only have the 1280 * 800 resolution and it leaves only a tiny space for the code becuae of the freaky Eclipse layout.

    It would probably be better to get to know Eclipse instead of complaining about how sucky it is. I guess I will try and get myself compatible with Eclipse :p.

  9. #9
    Bluefox815 is offline Member
    Join Date
    Feb 2008
    Location
    Oregon, USA
    Posts
    49
    Rep Power
    0

    Default

    Quote Originally Posted by Natrix View Post
    So you would say that Java should work ok on Linux?

    I dont know why but it still seems to me like theres a problem with Java on Linux. When I use Java on windows I get 70% less errors than I do in Linux and some of those errors are as far as I can tell not even code related. I know for sure that Open JDK is installed and BlueJ configured to work with it.

    I cant really switch to wnother IDE because BlueJ is what we use in school and I somehow got used to it.
    I'm using Ubuntu 8.10, and I have actually had problems using the OpenJDK. When OpenJDK ran an animated graphics program I made, I capped the frame/second rate at 20, which is very low for a modern computer. With 20 fps, a graphic moving across the screen should move across the screen smoothly, without speed variation. With the OpenJDK, the graphic would go fast, then slow, then fast again, at random intervals. This problem was fixed when I removed OpenJDK and installed Sun's Java SE 6 JRE. I don't know if you'll get the same results, but it's something you'll probably want to try.

    Another note: I prefer to compile from the command line (programming is a hobby for me, so I don't worry about using an IDE to prepare for an enterprise environment), but if I were to choose an IDE to work with, it would be NetBeans. You might want to look into that, also.

    Eclipse ran slowly for me, and didn't compile correctly, but it was using the OpenJDK when I used it, so that could be why.

  10. #10
    Natrix is offline Member
    Join Date
    Mar 2009
    Posts
    40
    Rep Power
    0

    Default

    The grapchics effect seems similar to what happens to me only my system freezes after some time. I will try completely removing the OpenJDK and Sun JDK's then try to install a completely fresh copy of the Suns everything that has to do with Java, JRE and JDK.

    Eclipse and NetBeans are cool but only when I use them on my dual monitor (22" and 19") PC. On the Linux running laptop I only see something that yells out "crowded!!" :).

  11. #11
    Natrix is offline Member
    Join Date
    Mar 2009
    Posts
    40
    Rep Power
    0

    Default

    I installed Sun's JRE and JDK and it works a lot better vut still not completly.
    When I run the JFrame Bounce program (- which makes the JFrame 300*250 pixels big and moves it across the screen, then bounces it off the edge) I now do get the screen moving an bouncing but it doesnt get the size. The frame is only like 5*10 pixels. As it would never get to the .setSize().

  12. #12
    Bluefox815 is offline Member
    Join Date
    Feb 2008
    Location
    Oregon, USA
    Posts
    49
    Rep Power
    0

    Default

    Can you post the code to that program? Then I can compile and test the program and make sure the problem isn't your code.

  13. #13
    Natrix is offline Member
    Join Date
    Mar 2009
    Posts
    40
    Rep Power
    0

    Default

    Here is the code.
    The code shouldn't be the problem. It works perfect on windows.

    Java Code:
    /**
     * Tule spišite opis razreda Vaja13_Nal_1.
     * 
     * @author Natrix
     * @version 
     */
    
    
    import javax.swing.*;
    import java.awt.*;
    
    class Bounce {
    
    public static void main (String []s) {
        int xs = 200;  //velikost frame-a po x osi (dolzina okencka)
        int ys = 150;  //velikost frame-a po y osi (visina okencka)
        int x = 0;
        int y = 0;
    
        Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
            int w = (int)(dim.getWidth()-xs);
            int h = (int)(dim.getHeight()-ys);
            int Xmin = 0;
            int Ymin = 0;
            int xMove = 1;
            int yMove = 1;
        
        
        System.out.println(w+" "+h);
        
        JFrame frame = new JFrame("Naloga1");
        frame.setVisible(true);
        
         frame.setBounds(x,y,xs,ys);
         frame.setResizable(false);
         frame.setAlwaysOnTop(true);
                  
           if ( x == Xmin ) 
                xMove = xMove *  1;
            if (y == Ymin )
                yMove =yMove * 1;
             while(true) { x = x + xMove; y = y + yMove; 
                     frame.setLocation(x,y);
             for(int i = 0 ; i < 1000000 ; i++);
                if ( x == w || x == Xmin )
                    xMove = xMove * (-1);
                if ( y == h || y == Ymin )
                    yMove = yMove * (-1);
                }          
         }
     }

  14. #14
    Bluefox815 is offline Member
    Join Date
    Feb 2008
    Location
    Oregon, USA
    Posts
    49
    Rep Power
    0

    Default

    This program compiled and ran on my system (Ubuntu 8.10 with GNOME) perfectly, but it used a lot of resources. I suggest adding a call to Thread.sleep(int), so that the program pauses for a while and doesn't use so many resources. You can just place this inside the end of your while loop.

    Java Code:
    try {
      Thread.sleep(1000/20); // in milliseconds, 1000 = 1 second
      //divided by 20 = 20 frames per second
    } catch (InterruptedException ie) {
    }
    Can you post how you installed the JDK (commands/utilities) and what type of Linux you're using?

    EDIT: The reason the window wouldn't resize is because you tried to resize it after you called frame.setVisible(true). You should do all frame initialization before you call frame.setVisible(true). Also, you might want to add this:

    Java Code:
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    This will let you close the window by clicking the close button.
    Last edited by Bluefox815; 04-07-2009 at 03:36 AM.

  15. #15
    Natrix is offline Member
    Join Date
    Mar 2009
    Posts
    40
    Rep Power
    0

    Default

    Thank you for that!
    It does solve the problem of .setBounds() and it doesn't stop after some random time.

    However it does not render the buttons to minimize, close or maximize. I guess its just running too fast. It then blocks everything I want to do (can't hit the stop button in NetBeans) and it just goes over the screen painting everything gray. It soon covers the whole screen.

  16. #16
    Bluefox815 is offline Member
    Join Date
    Feb 2008
    Location
    Oregon, USA
    Posts
    49
    Rep Power
    0

    Default

    You can fix that by inserting the code I posted before.

    Java Code:
    try {
      Thread.sleep(1000/20);
    } catch (InterruptedException ie) {
    }
    Just put it right before the end of your while loop.

Similar Threads

  1. Replies: 6
    Last Post: 04-08-2009, 05:05 AM
  2. java installation on linux
    By raghu9198 in forum New To Java
    Replies: 1
    Last Post: 03-22-2009, 06:37 PM
  3. print in java linux
    By bbq in forum Advanced Java
    Replies: 1
    Last Post: 07-05-2007, 05:24 AM
  4. Linux process from java
    By Ed in forum New To Java
    Replies: 2
    Last Post: 07-04-2007, 06:03 AM
  5. Linux and java
    By Alan in forum Advanced Java
    Replies: 2
    Last Post: 05-31-2007, 03:30 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •