hello everyone ,,,,i have recently installed a java version "1.4.2" in my terminal and i made it succcessfully but my problem now is how to compile a java sourcecode using the terminal..pls help me about this

anyway,I am using a ubuntu flavor of linux

Your help is very much appreciated....
Thanks in advanced....

Dani AI

Generated

This thread asked the right basic question: compile Java from the Ubuntu terminal. and were correct that you need the JDK compiler and runtime; ’s IDE suggestion is useful if you prefer GUI tools, and ’s later question about packages/classpaths is the common next step — short practical steps and a few pitfalls follow.

Install a JDK (not just a JRE) and verify the tools are on your path. On modern Ubuntu the supported way is to install the distribution JDK package and then confirm the Java tools are available:

sudo apt update
sudo apt install default-jdk

# verify
java -version
javac -version

(Using the package manager ensures you get an OpenJDK build that integrates with Ubuntu’s alternatives system.) (documentation.ubuntu.com)

Source layout and compile/run basics for packages: place a source that declares package com.example; in src/com/example/Example.java, then compile into a separate output tree and run from the classpath. A common workflow is:

# compile into an output directory
javac -d outdir src/com/example/Example.java

# run the main class by its fully qualified name
java -cp outdir com.example.Example

The compiler expects source files arranged to match their package names; use -d to control where .class files go and -cp/-classpath (or the CLASSPATH env var) to tell the launcher where to find classes and jars. (docs.oracle.com)

If multiple JDKs are installed, switch system defaults with the alternatives mechanism and set JAVA_HOME for build tools (Maven/Gradle). If javac is missing, you probably installed only a JRE — install the JDK package instead. The Ubuntu community docs show how to manage alternatives and common environment-variable locations. (help.ubuntu.com)

Troubleshooting tips: ensure package declarations match folder paths, class names match filenames, the main method is public static void main(String[]), and that your classpath includes the directory (or jar) containing compiled classes. IDEs (Geany, NetBeans, Eclipse) automate these steps, but understanding the command-line flow helps when a package/classpath error appears.

Recommended Answers

All 8 Replies

NetBeans (http://www.netbeans.org) is supposed to run on several OS, have you tried that?

NetBeans (http://www.netbeans.org) is supposed to run on several OS, have you tried that?

which is explicitly NOT what he was asking for. I'll not remove this as spam (though it could be considered such) unless you try the same again.

my problem now is how to compile a java sourcecode using the terminal

after installing a JDK in /bin/sh theier should be an executable file called "javac" so you would do in the terminal "javac helloworld.java" and then "java helloworld" to see text output. if its an applet you will have to view it in a web browser. geany is a great simple app for java. one click compiling, but again you must have javac in /bin/sh

and half a year later someone creates an account for the sole purpose of reviving a dead and answered thread...
Excellent start to a posting career, NOT.

Now how can I create and run a package ???????????????/
I created the package and I am able to run it on Windows environment but I have now shifted to Ubuntu Linux, and unable to run on that and of the most unable to set the class path...................plz help me out!!!!!!!!:confused:

When I was experimenting with Ubuntu, I found many answers to my questions about how to setup java on Ubuntu on the Ubuntu forum: http://ubuntuforums.org/index.php

I created the package and I am able to run it on Windows environment but I have now shifted to Ubuntu Linux, and unable to run on that and of the most unable to set the class path...................plz help me out!!!!!!!

I have been using Linux with Java for a few years now, so *maybe* I could help, but you have to first clearly state what the problem is, in a thread of you own .. not a fossilized thread from a decade ago.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.