First Java Program does not work!
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: First Java Program does not work!

Hybrid View

  1. #1
    Join Date
    Jun 2013
    Posts
    1

    First Java Program does not work!

    Hi,

    I am new to Java. I use NetBeans 7.1 IDE on Windows Vista. I try my first Hello World Program:

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */
    package javaapplication1;

    /**
    *
    * @author Bilal Gharib
    */
    public class JavaApplication1 {

    /**on
    * @param args the command line arguments
    */
    public static void main(String[] args) {
    System.out.println("Hello World!");
    }
    }

    When I run the program, nothing happens!
    I also tried to build the jar file; although it was built successfully, yet when I try to run it, again nothing happens.

    I am completely new to Java.

    Thanks to any help.

  2. #2
    Join Date
    Jan 2012
    Posts
    26

    Re: First Java Program does not work!

    I use Ready, but sometimes I use CodeBlocks or NetBeans, it's all the same syntax, I just prefer Ready more cause iv used it for so long now... Anyway:
    Your app is a console app, the annoying thing about those are, that literally heres how your code works:
    It'll run line by line, ok, I got ur package for you, Done... Alright, I know your first class is public, understood. Ok, so now you want me to run your main class, got it. Alright, I will print out your message. Ok, theres nothing else for me to do, I will close now.

    So literally it works, but its a literal 1 second flash, because it runs, sais hello world, theres nothing else for it to do, and it closes
    So you will need to add a "sleep" function, where you want it to wait for the user to close it, so that they can actually have time to read "hello world" before the app just closes.

    I cant remember the actual code right now, but if you watch some of Buckys Java tutorials, im sure its in the eairly ones.
    http://www.youtube.com/user/thenewboston

  3. #3
    Join Date
    Jun 2013
    Location
    New York, USA
    Posts
    21

    Re: First Java Program does not work!

    I personally recommend all new Java coders to use BlueJ. I believe it is better than the eclipse and netbeans because it gives a new coder a virtual environment and requires them to type in all of the code with no assistance from the program. This forces you to remember the code in your head and makes coding a much easier experience when you are being advanced code. It also does it's compiling in the program and when you run the program and it finishes the terminal remains open. Try it, and your program will work 100%. Also, you don't need
    Code:
    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */
    package javaapplication1;
    
    /**
    *
    * @author Bilal Gharib
    */
    public class JavaApplication1 {
    
    /**on 
    * @param args the command line arguments
    */
    In the beginning. It's just extra stuff to look through, all commented out for personal reading. The program uses none of this code, except for the package. But even that you don't have to include.

  4. #4
    Join Date
    May 2005
    Location
    San Antonio Tx
    Posts
    44

    Re: First Java Program does not work!

    make sure the console window is visible on net beans, if you are not getting any errors then most likely is your setup that's wrong

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center