I need help with Java

Started by
9 comments, last by rip-off 12 years, 8 months ago
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...
Advertisement
There is a syntax error. You close the function parentheses too soon.

Niko Suni


There is a syntax error. You close the function parentheses too soon.




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

There is a syntax error. You close the function parentheses too soon.




wait now something else is wrong. Look.
Try to change the package name to something different than the class name.

Niko Suni


Try to change the package name to something different than the class name.


lol i cant cuz the package name is thename of the file. and the public class name has to be the same as thefilename.
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.

Niko Suni


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.


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?
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.

Niko Suni


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.


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...

This topic is closed to new replies.

Advertisement