Sign in to follow this  
Ryan123

I need help with Java

Recommended Posts

Ryan123    100
Hey everyone, im Ryan, im new here. im 15 years old and well im trying to learn how to program with Java. Right now, i am trying to make a box that says Welcome to Java! In my book, it says:

Problem:
Write a program that displays text in a message dialog box.

Solution:
The following code gives the solution to the problem:




/* WelcomeInMessageDialogBox.java:
* This application program displays Welcome to Java!
* in a message dialog box.*/
import javax.swing.JOptionPane;
public class WelcomeInMessageDialogBox {
public static void main(String[] args) {
//Display Welcome to Java! in a message dialog box
JOptionPane.showMessageDialog(null, "Welcome to Java!") ,
"Example 1.2 Output", JOptionPane.INFORMATION_MESSAGE);

//Exit the program
System.exit(0);
}
}




Im using netbeans for this, and on the lines JOptionPane.showMessageDialog(null, "Welcome to Java!") , and "Example 1.2 Output", JOptionPane.INFORMATION_MESSAGE);
there is an exclamation point next to both of them. I tried to run the program and to see if the dialog box will appear, but it doesn't work. I don't know what I'm doing wrong. Here's a screenshot of what i am doing currently. im attacting thefile...

Share this post


Link to post
Share on other sites
Ryan123    100
[quote name='Nik02' timestamp='1313839150' post='4851552']
There is a syntax error. You close the function parentheses too soon.


[/quote]

Ohhhh wowwww i just noticed. THANK YOU so much i was so fustrated lol thanks i really appreciate it :)

Share this post


Link to post
Share on other sites
Ryan123    100
[quote name='Nik02' timestamp='1313839150' post='4851552']
There is a syntax error. You close the function parentheses too soon.


[/quote]

wait now something else is wrong. Look.

Share this post


Link to post
Share on other sites
Ryan123    100
[quote name='Nik02' timestamp='1313841068' post='4851560']
Try to change the package name to something different than the class name.
[/quote]

lol i cant cuz the package name is thename of the file. and the public class name has to be the same as thefilename.

Share this post


Link to post
Share on other sites
Nik02    4348
The packages correspond to the physical directories that the class loader searches at runtime. If I remember correctly, the package names must match the physical deployment directory structure; also, Java is case-sensitive about the physical paths (even though the OS platform you're running the program in would not be).

Your physical package directory uses all lower-case, but in your code file you declare the package name in mixed case. Modify the code file's package declaration to match the physical package name. It is a common practice to use all lower-case in package names.

Share this post


Link to post
Share on other sites
Ryan123    100
[quote name='Nik02' timestamp='1313841853' post='4851567']
The packages correspond to the physical directories that the class loader searches at runtime. If I remember correctly, the package names must match the physical deployment directory structure; also, Java is case-sensitive about the physical paths (even though the OS platform you're running the program in would not be).

Your physical package directory uses all lower-case, but in your code file you declare the package name in mixed case. Modify the code file's package declaration to match the physical package name. It is a common practice to use all lower-case in package names.
[/quote]

ohhhhhh thank you man it worked! So the package name ALWAYS has to be lowercase?
And by the way, how long did it take you to learnhow to program?

Share this post


Link to post
Share on other sites
Nik02    4348
The package name doesn't technically have to be lowercase, but it has to match the physical directory of the package accurately and case-sensitively. It is merely a good practice to keep package names in lowercase, so that the naming scheme can easily be distinguished from class names (and a few other reasons).

I've been programming for over 21 years now. I mainly use C++ and C# at work, but I can also handle a lot of other languages (like Java) somewhat comfortably. I started with monolithic style programming in BASIC variants, so it took a couple of years for me to grasp the object oriented and functional paradigms.

Share this post


Link to post
Share on other sites
Ryan123    100
[quote name='Nik02' timestamp='1313843049' post='4851576']
The package name doesn't technically have to be lowercase, but it has to match the physical directory of the package accurately and case-sensitively. It is merely a good practice to keep package names in lowercase, so that the naming scheme can easily be distinguished from class names (and a few other reasons).

I've been programming for over 21 years now. I mainly use C++ and C# at work, but I can also handle a lot of other languages (like Java) somewhat comfortably. I started with monolithic style programming in BASIC variants, so it took a couple of years for me to grasp the object oriented and functional paradigms.
[/quote]

ohhh, is C++ hard? I heard that to make video games, you need C++... Can i do them in Java? I thought Java and C++ wasthe same thing? Imconfused...

Share this post


Link to post
Share on other sites
rip-off    10979
C++ is a difficult, unforgiving language. You do not need to use C++ to make fun games. You can write fun games in Java. Java and C++ are not the same thing, but they both get the same things done, more or less.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this