Results 1 to 5 of 5
- 01-30-2012, 01:16 PM #1
Member
- Join Date
- Jan 2012
- Posts
- 4
- Rep Power
- 0
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 01:55 PM.
- 01-30-2012, 01:27 PM #2
Re: The simplest program...the fundamentals for a beginner
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.it never works.
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
- 01-30-2012, 01:58 PM #3
Member
- Join Date
- Jan 2012
- Posts
- 4
- Rep Power
- 0
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
-
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.
- 01-30-2012, 02:21 PM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
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 ...When people rob a bank they get a penalty; when banks rob people they get a bonus.
Similar Threads
-
Triangle program for beginner
By shawnx715 in forum New To JavaReplies: 18Last Post: 11-15-2011, 12:40 PM -
Help with beginner Java program? Boolean?
By katiebear128 in forum New To JavaReplies: 20Last Post: 09-30-2011, 06:35 PM -
JAVA Beginner - Simple Program help
By Logik22 in forum New To JavaReplies: 13Last Post: 07-15-2011, 02:44 PM -
Thread Fundamentals
By jjjkkk in forum New To JavaReplies: 4Last Post: 07-06-2011, 07:34 PM -
Beginner Needs Help w/ Program for School
By badness in forum New To JavaReplies: 2Last Post: 11-24-2007, 07:51 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks