15 Replies - 2384 Views - Last Post: 19 February 2011 - 07:45 PM
#1
Java beginner with no previous programming experience seeking advice
Posted 18 February 2011 - 12:09 AM
I will appreciate any help/advise! Thanks...
Replies To: Java beginner with no previous programming experience seeking advice
#2
Re: Java beginner with no previous programming experience seeking advice
Posted 18 February 2011 - 01:06 AM
I know when you use Netbeans to create a "Java Application" it does automatically created a file/class called package.Main
If you put your HelloWorld class within this file it will generate an error. You have two options, remove the Main class from the project and add a new class called HelloWorld then build, or post the code within the Main however only use the main method, the code would be as follows
class Main {
public static void main(String[] args) {
System.out.println("HelloWorld!");
}
}
#3
Re: Java beginner with no previous programming experience seeking advice
Posted 18 February 2011 - 06:31 AM
#4
Re: Java beginner with no previous programming experience seeking advice
Posted 18 February 2011 - 08:01 AM
#5
Re: Java beginner with no previous programming experience seeking advice
Posted 18 February 2011 - 08:07 AM
#6
Re: Java beginner with no previous programming experience seeking advice
Posted 18 February 2011 - 10:47 AM
FOr what I understood from what DaneAU said, you need to have one file with the name of the class you want, and also, if there would be more than one class in your code you have to create a new class file for that new class of the same name. Am I right?
I gonna try now to fix it!
In he meanwhile you guys can laugh at my code! LOL...
Attached image(s)
#7
Re: Java beginner with no previous programming experience seeking advice
Posted 18 February 2011 - 07:54 PM
You could make a simple fix by changing the class name to class Main in the code you posted and it would compile should there be no errors.
Now within your code you have an error
Public static void main(String[] args)
Should be
public static void main(String[] args)
notice that the public is spelled without a capital letter. This should resolve those errors.
Remove all your code and paste the following in to your file.
package helloWorld;
class Main
{
public static void main(String[] args) {
System.out.println("HelloWorld!");
}
}
As per your comment
Quote
Yes you are right. You can have more than one class in the same file. However for now i suggest creating a new file for each class.
Now just as a suggestion, seem as though you are just starting out it is often a lot easier to use a simple text editor and compile via cmd or terminal using javac to get started. Alternatively use a very simple and friendly IDE such as BlueJ - http://www.bluej.org/
For a beginner Netbeans can be overwhelming and it often leads to confusion with the very things you are discussing in this thread.
Anyway i have attached a project file for BlueJ should you download it and use it.
You can open this project up or create your own. It is very helpful for beginners and i recommend using BlueJ
Attached File(s)
-
DreamInCodeHelp.zip (2.06K)
Number of downloads: 35
This post has been edited by DaneAU: 18 February 2011 - 08:10 PM
#8
Re: Java beginner with no previous programming experience seeking advice
Posted 18 February 2011 - 08:26 PM
#9
Re: Java beginner with no previous programming experience seeking advice
Posted 18 February 2011 - 09:20 PM
#10
Re: Java beginner with no previous programming experience seeking advice
Posted 19 February 2011 - 06:22 PM
DaneAU, I downloaded the file. Do I use the Command Prompt to run it??? How can I see the Output of the code in BlueJ???
Attached image(s)
#11
Re: Java beginner with no previous programming experience seeking advice
Posted 19 February 2011 - 06:27 PM
Noah89, on 19 February 2011 - 08:22 PM, said:
If you are a beginner in Java stay away from package right now. Just do not put a package statement in your code.
You'll learn the concept later on when you will need it. (And that may take a while
#12
Re: Java beginner with no previous programming experience seeking advice
Posted 19 February 2011 - 06:35 PM
and again thanks for all the help and patience!
This post has been edited by Noah89: 19 February 2011 - 06:42 PM
#13
Re: Java beginner with no previous programming experience seeking advice
Posted 19 February 2011 - 06:51 PM
#14
Re: Java beginner with no previous programming experience seeking advice
Posted 19 February 2011 - 07:02 PM
#15
Re: Java beginner with no previous programming experience seeking advice
Posted 19 February 2011 - 07:09 PM
Noah89, on 19 February 2011 - 08:35 PM, said:
You had an error because the package statement was not the first statement in your code not because it was erronous.
Package garanty uniqueless of names in all the Java world.
Usually you reverse the URL of your site which is unique.
So www.pblinc.ca so all my Java package start by
package ca.pblinc
now your package is also a directory structure so if I develop a SecretCode application I will need the folowing directory structure on my disk:
\ca\pblinc\secretcode
all the .java files in that directory will have
package ca.pblinc.secretcode
if I want to split my application and have
\ca\pblinc\secretcode\decode
\ca\pblinc\secretcode\encode
\ca\pblinc\secretcode\gui
all the .java files in \ca\pblinc\secretcode\gui will start by
package ca.pblinc.secretcode.gui
So if in the \ca\pblinc\secretcode\gui directory I have MyPanel.java
it will start by
package ca.pblinc.secretcode.gui
and it will allow the compiler to differentiate it from jour own MyPanel.java which wouldn't have the same package
|
|

New Topic/Question
Reply




MultiQuote








|