Results 1 to 4 of 4

Thread: javac class issue can't run "hello world" JDK 8

  1. #1
    Join Date
    Jul 2018
    Beans
    9

    Question javac class issue can't run "hello world" JDK 8

    I'm in a tough spot trying to learn how to run java in ubuntu while knowing nothing about linux. I'm wrangling with two languages at once.

    So when I'm trying to compile my .java file into class, this shows up. (What does this mean?)
    Code:
    ~/myProject$ javac Hello.java
    Hello.java:5: error: cannot find symbol
                System.out.printIn("Hello World, from Ubuntu");
                          ^
      symbol:   method printIn(String)
      location: variable out of type PrintStream
    1 error
    ...here's another try...
    Code:
    ~/myProject$ javac Hello
    error: Class names, 'Hello', are only accepted if annotation processing is explicitly requested
    1 error
    Here's my java file: Hello.java
    Code:
    public class Hello
    {
            public static void main(String args[])
            {
                System.out.printIn("Hello World, from Ubuntu");
            }
    }
    and finally, when I try to run it...
    Code:
    ~/myProject$ java Hello
    Error: Could not find or load main class Hello
    Caused by: java.lang.ClassNotFoundException: Hello
    I'm fried.

  2. #2
    Join Date
    Aug 2010
    Location
    Lancs, United Kingdom
    Beans
    1,588
    Distro
    Ubuntu Mate 16.04 Xenial Xerus

    Re: javac class issue can't run "hello world" JDK 8

    There is no printIn method. I think you meant println. The error when you try to run it is to be expected; you cannot run something that you have failed to compile.

  3. #3
    Join Date
    Jul 2018
    Beans
    9

    Re: javac class issue can't run "hello world" JDK 8

    What character is that specifically? Is that a #1?
    Code:
    public class Hello
    {
            public static void main(String args[])
            {
                System.out.print1n("Hello World, from Ubuntu");
            }
    }
    Result:
    Code:
    ~/myProject$ javac Hello.java
    Hello.java:5: error: cannot find symbol
                System.out.print1n("Hello World, from Ubuntu");
                          ^
      symbol:   method print1n(String)
      location: variable out of type PrintStream
    1 error
    ...or is that a lowercase l as in "larry"?
    Code:
    public class Hello
    {
            public static void main(String args[])
            {
                System.out.println("Hello World, from Ubuntu");
            }
    }
    Result:
    Code:
    ~/myProject$ javac Hello.java
    Hello.java:1: error: error while writing Hello: /home/doughnuts/myProject/Hello.class
    public class Hello
           ^
    1 error
    At least I didn't do anything in the terminal badly...
    I just want to test my jdk installation to see if it installed properly, before actually learning java. I haven't really ran through the coding of hello world yet so I'm pretty sure something is badly written.

  4. #4
    Join Date
    Aug 2010
    Location
    Lancs, United Kingdom
    Beans
    1,588
    Distro
    Ubuntu Mate 16.04 Xenial Xerus

    Re: javac class issue can't run "hello world" JDK 8

    Quote Originally Posted by insert.memories.here View Post
    ...or is that a lowercase l as in "larry"?
    Yes.
    Code:
    public class Hello
    {
            public static void main(String args[])
            {
                System.out.println("Hello World, from Ubuntu");
            }
    }
    Result:
    Code:
    ~/myProject$ javac Hello.java
    Hello.java:1: error: error while writing Hello: /home/doughnuts/myProject/Hello.class
    public class Hello
           ^
    1 error
    I can't see anything wrong with that. It's perfectly correct java that compiles and runs for me when copied & pasted from above.

    You can get a similar error if file permissions prevent you writing the output:
    Code:
    Hello.java:1: error: error while writing Hello: Hello.class (Permission denied)
    public class Hello
           ^
    1 error
    but then it explicitly says "(Permission denied)". So I don't know why you are getting that output, I'm afraid.

Tags for this Thread

Bookmarks

Posting Permissions

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