I am trying to run a simple program on NetBeans in Ubuntu 18.04:
package testing1;
public class Testing1 {
public static void main(String[] args) {
// TODO code application logic here
System.out.println("Zulfi");
}
}
The version details of Netbeans are:
[quote]Product Version: Apache NetBeans IDE 10.0 (Build 20190203-debian-10.0) Java: 11.0.10; OpenJDK 64-Bit Server VM 11.0.10+9-Ubuntu-0ubuntu1.18.04 Runtime: OpenJDK Runtime Environment 11.0.10+9-Ubuntu-0ubuntu1.18.04 System: Linux version 4.15.0-135-generic running on amd64; UTF-8; en_US (nb) User directory: /home/zulfi/.netbeans/10.0 Cache directory: /home/zulfi/.cache/netbeans/10.0[/quote]
I am getting classpath problem,
"Cant access java.lang Unable to find package java.lang in classath
I already have java installed on my system. I installed java before installing Netbeans. I checked the version of java and javac commands:
$ java -version
openjdk version "11.0.10" 2021-01-19 OpenJDK Runtime Environment (build 11.0.10+9-Ubuntu-0ubuntu1.18.04) OpenJDK 64-Bit Server VM (build 11.0.10+9-Ubuntu-0ubuntu1.18.04, mixed mode, sharing) @lc2530hz:~$ javac -version javac 11.0.10
Now I found the location where java is stored: i.e. /usr/lib/jvm It contains:
@lc2530hz:/usr/lib$ ls jvm
default-java java-11-openjdk-amd64
java-8-openjdk-amd64 java-1.11.0-openjdk-amd64 java-1.8.0-openjdk-amd64 openjdk-11
Now the NetBeans product version says:
Java: 11.0.10; OpenJDK 64-Bit Server VM 11.0.10+9-Ubuntu-0ubuntu1.18.04
I checked openjdk-11 folder:
/usr/lib/jvm/openjdk-11$ ls src.zip zulfi@lc2530hz:/usr/lib/jvm/openjdk-11$
I don't remember if I unzipped the above folder
Then I checked /usr/lib/jvm/java-11-openjdk-amd64 folder:
$ ls /usr/lib/jvm/java-11-openjdk-amd64
bin conf docs include jmods legal lib man release
So I decided to use /usr/lib/jvm/java-11-openjdk-amd64 as the path for JAVA_HOME
$ echo $JAVA_HOME /usr/bin/java @lc2530hz:/usr/lib/jvm/java-11-openjdk-amd64$ export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64 @lc2530hz:/usr/lib/jvm/java-11-openjdk-amd64$ echo $JAVA_HOME /usr/lib/jvm/java-11-openjdk-amd64 @lc2530hz:/usr/lib/jvm/java-11-openjdk-amd64$ netbeans
But still I am getting the same error.
I am running Netbeans for the first time on ubuntu 18.04 so I am getting java.lang problem. Netbeans is not able to recognize the "String" class.
Somebody please guide me. Zulfi.
NetBeans worked in Ubuntu at one time, but the current NetBeans apt package is buggy and totally unusable in Ubuntu. The NetBeans IDE shows a gray progress bar that indicates that it seems to be downloading software, but it never finishes downloading all the software and it never works no matter how much software that it downloaded.
I recommend using BlueJ, a simpler Java IDE that works out of the box with no configuration required. To install BlueJ open the terminal and type:
Launch BlueJ IDE, and start a new project named testing1.
Make a new class named Testing1.
Copy/paste your Java code into Testing1. The Java code in your question works fine, so you can copy/paste everything into Testing1 except don't paste the first line that says
package testing1;
because you don't need it in BlueJ.Right-click the Testing1 program icon and select Compile. Testing1 will compile and the Testing1 program icon will change from shaded to unshaded to show that it has been compiled successfully.
Right-click the Testing1 program icon and select void main(String[]args) as shown in the below screenshot. Note that in the screenshot the Testing1 icon is unshaded which means that it has been compiled.
Click the OK button in the lower right corner. A new BlueJ Terminal Window will open up which contains the results of running your Java program.
If this is too complicated for you, Java 11 contains a feature named JShell. Java Shell tool (JShell) is an interactive tool for learning the Java programming language and prototyping Java code. JShell is a Read-Evaluate-Print Loop (REPL), which evaluates declarations, statements, and expressions as they are entered and immediately shows the results. JShell can also run blocks of Java code. The JShell interpreter is run from the terminal by executing the
jshell
command, and it shows you ajshell>
prompt when it is running.By default you get a set of common imports in JDK 11:
You can add your own any time.