Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Having difficulties with Java for the first time...

  1. #1
    Junior Member
    Join Date
    Oct 2022
    Location
    Montana
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Having difficulties with Java for the first time...

    I just recently have started programming with Java (I first learned programming with Visual Basic and Pascal) but I'm having difficulty trying to understand how to make Java work on my systems. I cen't even get a simple "Helloworld" java program to compile in the JRE, even with the #code compiler with Windows 11. I open a DOS prompt but I can't get the executable to run the simple program. Anyone have any advice in what I'm doing wrong?

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Having difficulties with Java for the first time...

    You need a JDK that contains the javac program to compile the .java file to create a .class file.
    Then execute the .class file with the java program.
    For example:
    javac MyCode.java
    java MyCode
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Jun 2022
    Posts
    41
    Thanks
    1
    Thanked 3 Times in 2 Posts

    Default Re: Having difficulties with Java for the first time...

    You can test basic java code in this browser environment

  4. #4
    Junior Member
    Join Date
    Oct 2022
    Location
    Montana
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Having difficulties with Java for the first time...

    Cool site! Still having problems with my code I entered into the website. Here is the snipet of code I'm using...

    /*
    * Hello World
    * The classic first program
    */

    public class main {

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

    I tried a few varitations of this on the website, but no success yet. Any advice?

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Having difficulties with Java for the first time...

    no success yet. Any advice?
    What happened? Can you copy the full text of any error messages and paste it here so we can see?

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  6. #6
    Junior Member
    Join Date
    Oct 2022
    Location
    Montana
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Having difficulties with Java for the first time...

    Ok, here is what it looks like in the browser....

    /*
    * Hello World
    * The classic first program
    */
     
    public class main {
     
    public static void main(String[] args) {
    System.out.println("Hello, world!");
    }
    }
     
    Main.java:6: error: class main is public, should be declared in a file named main.java
    public class main {
           ^
    1 error

    Not sure why its saying the class main is the problem.

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Having difficulties with Java for the first time...

    class main is public, should be declared in a file named main.java
    That message says what the problem is. The code for the class should be in a file named: main.java
    The filename and the public class name need to be the same.

    Note: Java naming conventions say that class names should begin with an uppercase letter.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Dining Philosophers Problem -- I'm having great difficulties
    By nik1996 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: October 25th, 2020, 05:52 AM
  2. [SOLVED] Regular Expression Difficulties...
    By snowguy13 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: July 4th, 2012, 08:31 AM
  3. 1st Java class assignment, and having some difficulties. Little help please.
    By flpanthers1 in forum What's Wrong With My Code?
    Replies: 10
    Last Post: May 27th, 2011, 04:09 AM
  4. Collision Detection difficulties
    By Uritomi in forum What's Wrong With My Code?
    Replies: 3
    Last Post: May 20th, 2011, 10:10 AM
  5. Having Difficulties With a Multi Thread Code... Help?
    By Allicat in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 5th, 2011, 12:35 AM