Skip to main content
gamedev.net
🔒 Locked

I need help with Java

Started by Ryan123 Aug 20, 2011 at 11:09 AM 9 replies 1.4k views
Original Post
Ryan123
Ryan123
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...
Nik02
Nik02
There is a syntax error. You close the function parentheses too soon.

Niko Suni
Ryan123
Ryan123

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

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




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

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

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?
Nik02
Nik02
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
Ryan123
Ryan123

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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.