Results 1 to 5 of 5
  1. #1
    Joza is offline Member
    Join Date
    Jan 2012
    Posts
    4
    Rep Power
    0

    Default The simplest program...the fundamentals for a beginner

    Hi guys! First post..

    So I've been learning Java now for a while using Stanford's free Programming Methodology course. It's great in conjunction with the recommended book, but I feel that a few basics have been missed.

    I want to start from scratch and get the basics right (I've a physics degree, so that's how my head operates!).

    I want to write a simple program that puts a dialog box on the screen saying "Hello!". I have the Eclipse IDE but I could just write this in a text file right?

    From what I've seen so far, it could go like this:

    import java.awt.Dialog;

    public class HelloDialog {

    public static void main(String [] args) {

    Dialog myDialog = new Dialog("Hello!");
    myDialog.show(); // This will make it visible on the screen?
    }
    }


    This is then saved as a file called HelloDialog.java.

    The header public static main(String [] args) I have been told is needed by all programs. I've tried compiling this but it never works.
    What are the fundamental errors I am making here? How does the simplest program like this work from the ground up, without extending a pre-existing class?

    Thanks guys!
    Last edited by Joza; 01-30-2012 at 02:55 PM.

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,816
    Rep Power
    25

    Default Re: The simplest program...the fundamentals for a beginner

    it never works.
    There are so many ways for a program to not work. Which one is your problem? If you'd post a description or the error message that would help.

    One problem I see is that the main method is not correctly coded if you expect the java program to find it and call it when you start execution of your class. If must have a return type of void.

    The tutorial can be helpful:
    http://docs.oracle.com/javase/tutori...ava/index.html

  3. #3
    Joza is offline Member
    Join Date
    Jan 2012
    Posts
    4
    Rep Power
    0

    Default Re: The simplest program...the fundamentals for a beginner

    I forgot about void, I've put it in now, thanks.

    Here is the error message:

    DialogOutput.java:7: cannot find symbol
    symbol : constructor Dialog(java.lang.String)
    location: class java.awt.Dialog
    Dialog myDialog = new Dialog("Welcome!");
    ^
    Note: DialogOutput.java uses or overrides a deprecated API.
    Note: Recompile with -Xlint:deprecation for details.
    1 error

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: The simplest program...the fundamentals for a beginner

    Check the Java API for the Dialog class to see what constructors are allowed. You can't use one that just holds a String parameter.

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,730
    Blog Entries
    7
    Rep Power
    21

    Default Re: The simplest program...the fundamentals for a beginner

    The Dialog class doesn't have a constructor that takes a single String argument. Also, the Dialog class is an old AWT class, nowadays the JDialog class is usedd instead (it's a Swing component). Read the API documentation first before you try to start coding.

    kind regards,

    Jos

    edit: way too late ...
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Triangle program for beginner
    By shawnx715 in forum New To Java
    Replies: 18
    Last Post: 11-15-2011, 01:40 PM
  2. Help with beginner Java program? Boolean?
    By katiebear128 in forum New To Java
    Replies: 20
    Last Post: 09-30-2011, 07:35 PM
  3. JAVA Beginner - Simple Program help
    By Logik22 in forum New To Java
    Replies: 13
    Last Post: 07-15-2011, 03:44 PM
  4. Thread Fundamentals
    By jjjkkk in forum New To Java
    Replies: 4
    Last Post: 07-06-2011, 08:34 PM
  5. Beginner Needs Help w/ Program for School
    By badness in forum New To Java
    Replies: 2
    Last Post: 11-24-2007, 08:51 PM

Posting Permissions

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