0

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 have attached the image:Java NetBeans program giving error in the String class

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.

1
  • There's nothing wrong with the Java code in this question. The problem here is due to eccentricities of the NetBeans IDE which is a package in the default Ubuntu repositories and is installable by sudo apt install netbeans.
    – karel
    Feb 28, 2021 at 11:33

1 Answer 1

0

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:

sudo snap install bluej
  1. Launch BlueJ IDE, and start a new project named testing1.

  2. Make a new class named Testing1.

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

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

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

    enter image description here

  6. 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 a jshell> prompt when it is running.

By default you get a set of common imports in JDK 11:

jshell> /imports
|    import java.io.*
|    import java.math.*
|    import java.net.*
|    import java.nio.file.*
|    import java.util.*
|    import java.util.concurrent.*
|    import java.util.function.*
|    import java.util.prefs.*
|    import java.util.regex.*
|    import java.util.stream.*

You can add your own any time.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .