LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Start to run Java Programs in fedora core 6 (https://www.linuxquestions.org/questions/programming-9/start-to-run-java-programs-in-fedora-core-6-a-551504/)

me4linux 05-05-2007 10:30 AM

Start to run Java Programs in fedora core 6
 
Hi everyone

I have installed fedora core 6.
java, javac , javap , javaws commands are available in my system...
i have also installed netbeans 5.5
Cany any one please tell me how to run a jav program..
I have set the environment variable $JAVA_HOME

-----
javac filename.java
java
-----

with these commands can i run any java program [excluding servlets ....]
any java program i mean program with applets

Is netbeans necessary for simple programs and concepts that a beginner of java is suppposed to learn...?

I am a beginner of java ...I have to start it soon in a couple of weeks since i am busy with some work

Does the commands javac and java are enough for me to run java programs

Do I need to install/set any environmental variables ......etc??

Please help me to start using java in fedora core 6

Please post small tutorial on HOW TO RUN JAVA PROGRAMS IN FEDORA [ANY LINUX]
I think it will be useful to newbies ..

THANKS IN ADVANCE

Bye

indienick 05-05-2007 11:02 AM

Netbeans is nothing more than a really good Java IDE.

Running Java applications on Fedora is no different than running Java applications on any Linux, UNIX, or Windows box (I'm not sure how Macs handle Java applications, but I'm pretty sure it's quite similar).

When you type "javac ClassFile.java" at a shell prompt, you're just running the Java compiler, and once it's finished running (assuming there were no errors) you'll be left with a new file called - for the sake of this example - ClassFile.class.

To run ClassFile.class, cd into the directory where ClassFile.class resides, and type "java ClassFile".
(Note: There must be a public static void main(String[] args) funtion in that class for it to be runnable.)

To run applications that have been contained in a *.jar file, simply type:
"java -jar JavaProgram.jar"

:)

EDIT: Also, if you've installed FC6 (Fedora Core 6), more than likely the GNU Java compiler (GCJ-compat)got installed, and Netbeans automatically detected that Java system.

If it turns out that this is the case, I heavily recommend uninstalling the GCJ packages (carefully though, they may take out some other programs as it would be considered a dependency), and go to java.sun.com and download the J2SE SDK (with Netbeans) binary installer, and use that instead; as I believe the GCJ system only provides compatibility for Java 1.4.

PFudd 05-19-2007 12:50 AM

Running Java, outside and inside a browser
 
Here's a short tutorial on Java.

Testing Java at the command line:

Step 1: Here's a test program for a command-line java program:

Code:

class myfirstjavaprog

        public static void main(String args[])
        {
          System.out.println("Hello World!");
        }
}

One thing that annoys me about Java is that the name of file HAS TO MATCH the class name inside the file. So, name this file "myfirstjavaprog.java".

Step 2: Compile the test program:

Code:

javac myfirstjavaprog.java
This will create "myfirstjavaprog.class", if all is ok. If javac is not found at /usr/bin/javac, Java is not installed right. /usr/bin/javac is a symbolic link to /etc/alternatives/javac, which (in my case) is a symlink to /usr/lib/jvm/java-1.6.0-sun/bin/javac, which came out of an rpm file named jdk-1.6.0-fcs.i586.rpm, from Sun.

Step 3: Run the test program:

Code:

java myfirstjavaprog
Voila, a program that says "Hello world!".

Getting applets running in Firefox

Step 1: Get java running.

Step 2: Make the following symlink:
Code:

cd /usr/lib/mozilla/plugins
ln -s /usr/lib/jvm/java-1.6.0-sun-1.6.0/jre/plugin/i386/ns7/libjavaplugin_oji.so .

Step 3: Restart Firefox
Step 4: Test with http://www.java.com/en/download/help/testvm.xml

If you have the dancing "Duke", congratulations. If you have a blank square, you have what I had yesterday. My accidental solution was to download the non-rpm version of java and install that. I think that was what fixed it, but I was trying a lot of stuff, so I can't be sure.

Getting JNLP pages (aka Java Web Start) to work

Step 1: In firefox, click on a JNLP file. When it asks what to do with it, tell it to run javaws. You'll have to browse for it. Mine is at /usr/java/jdk1.6.0/bin/javaws.

Step 2: There is no step 2. It should just work at this point.

Hope that helps!


All times are GMT -5. The time now is 02:54 PM.