What is the best way to start creating java programs?

Yeah now fix your class path - I assume your using windows,

Woah don't use 1.4. I would first upgrade to either 1.5.0 or 1.6
 
In my variables I have

PATH

C:\J2SDK.1.4.2_13\BIN\

CLASSPATH

C:\; C:\J2SDK1.4.2_13\LIB\

I can't see anything obviously wrong with that? I used the guide from the oracle website.
 
It was the first link on google so I assumed it was the latest version. :p

God, downloading this is slow with bt's traffic shaping. :rolleyes:
 
Last edited:
1.6 has been released, i believe you can now get 1.7 but it may still be pre-beta.

Also, nowadays there is no real need to bother learning java on the command line. Once you have a decent IDE you will never go back to it. For my money Eclipse is the best of the free IDE's, if you use the setup wizard then its pretty straight forward to start using right away. Point it to your java install and it works the rest out for itself.
Just make sure that Eclipse knows the name of the class that contains the main method and you should be good to go.

Also, I would really learn what a class is and the basics of what OO (Object Orientation) is before starting to actaully do any coding.

You don't have to name your file the same as you name your class but it is preffered as that way its easier to navigate through your code.

Good luck with it man, I remember what it was like to learn OO for the first time.
 
Wiggis said:
1.6 has been released, i believe you can now get 1.7 but it may still be pre-beta.

Also, nowadays there is no real need to bother learning java on the command line. Once you have a decent IDE you will never go back to it. For my money Eclipse is the best of the free IDE's, if you use the setup wizard then its pretty straight forward to start using right away. Point it to your java install and it works the rest out for itself.
Just make sure that Eclipse knows the name of the class that contains the main method and you should be good to go.

Also, I would really learn what a class is and the basics of what OO (Object Orientation) is before starting to actaully do any coding.

You don't have to name your file the same as you name your class but it is preffered as that way its easier to navigate through your code.

Good luck with it man, I remember what it was like to learn OO for the first time.

And what happens when you move to a system that doesnt have an IDE?

Its a bugbear of mine that a lot of developers straight out of uni havent got the first clue about developing software in environments such as unix/linux. IDEs can have great productivity features, but when problem solving there's nothing better than having a decent knowledge of whats going on 'under the covers'
 
For the tiniest of programs, using the command prompt is the best idea. Most IDEs are astonishingly full-featured and incredibly complicated to a novice. Using javac also helps you work out exactly where error messages are coming from and reduces the amount of fluff you have to do to get the program working.

In java, the crucial things to remember, when writing a basic program:

Make a file called ProgramName.java

in that file, it should contain:

public class ProgramName
{
public static void main(String[] args)
{}
}

(In particular, the class name MUST be the same as the filename, the class must be public, the "main" method must exist and be public)

Then run:

javac ProgramName.java
java ProgramName

Note that .java is included when running javac, but .class is not when running java.

If this doesn't work, then you need to get environment variables set up. To do this, make sure that the Java JDK (not just JRE) is installed, and find the appropriate "bin" directory. For me this is C:\Program Files\Java\jdk1.6.0\bin, yours may vary depending on the version of java installed.

Then go into control panel > system > advanced > environment variables > add a user variable called PATH with the value being the path you found above.

There is nothing remotely complicated or even counter-intuitive about this - the only problems are:
1) People who expect to be able to write anything anywhere without having worked out the correct syntax or rules beforehand
2) The vast number of useless text books and "learn x language in 21 days" books that concentrate on either a specific IDE or begin by listing details of every variable type (which seems astonishingly common) rather than actually telling you how to write and compile a simple program.
 
Visage said:
And what happens when you move to a system that doesnt have an IDE?
Install one? Eclipse is highly cross platform so unless, again, you're throwing a spanner in the works by talking about embedded development, then I can't see it being a problem.

Also an IDE doesn't really do that much other than organise your files and perform compilation commands for you (I'm sure you know this, just pointing it out for the others, don't flame me). But IDE's do provide very useful inline debugging tools. So you can walk through the code line by line if need be... and insert break points. Some developers prefer to debug in this way other than relying on trace file outputs.

PinkPig said:
For the tiniest of programs, using the command prompt is the best idea. Most IDEs are astonishingly full-featured and incredibly complicated to a novice.
Agreed, if you're still a novice programmer then it may worth avoid IDE's for a couple months. But sooner or later executing compilation batch files will become tiresome and they'll move on over to the dark side ;)
 
Last edited:
I can echo the fact that learnign OO would be a very good first step.

You have used C++ in the past so have a good inkling of the basics of classes etc but C++ is (arguably) not truly OO. It was a concept "tacked" onto C++ when it became popular.

Java on the otherhand is entirely OO. I would suggest you master the concepts of packages, inheritance etc before you get to stuck into coding.

I made the mistake of not doing this, it meant that about 3 years in, although I could code, I was still learning the basics as and when I needed to know them ,as a result of this I was doing some vey silly things in my programs which could have been avoided or certainly done in a better way had my grasp on the fundamentals of OO been superior.

It really wont take too long. I also find using UML class diagrams is a very useful way of planning out a java app before I really get stuck in. Ok its not usually possible to draw up something 100% accurate before you have started but even just having an outline of the apps class structure can be very useful.

EDIT: Also i think this IDE vs command line stuff is a bit moot, come on the guy can program in C++ and is moving onto Java, ok he had a few teethign troubles but after a week or so messing round in an IDE, typing in "javac xxx" isnt going to really tax him(/her) too much. Personally I dont think it matters if people start in an IDE or not, its the coding itself that is important.

Oh, also, from the very start.... make use of the try/catch error handling structure, its one of Java's true strengths an again, my poor initial knowledge led me to not make use of it for far too long....
 
Last edited:
manic_man said:
IOh, also, from the very start.... make use of the try/catch error handling structure, its one of Java's true strengths an again, my poor initial knowledge led me to not make use of it for far too long....
Hell yes, a very good point. Exception handling quite simply rocks and will make your life a lot simpler. C++ does have it but it just isn't as good as the exception handling you get in the managed world of Java or .NET.
 
Visage said:
And what happens when you move to a system that doesnt have an IDE?

Its a bugbear of mine that a lot of developers straight out of uni havent got the first clue about developing software in environments such as unix/linux. IDEs can have great productivity features, but when problem solving there's nothing better than having a decent knowledge of whats going on 'under the covers'

Sure, I just fire up vim for small bits of code... Don't see the point in loading a bloated java ide if your only writing a couple of class files. If your doing a big project something like IntelliJ is great but not all the time. Its well worth learning how to develop on the command line.

manic_man said:
You have used C++ in the past so have a good inkling of the basics of classes etc but C++ is (arguably) not truly OO. It was a concept "tacked" onto C++ when it became popular.

You could argue that Java is not "fully" object orientated as well though if you compare it against something like smalltalk which is fully oo. :p
 
Last edited:
Una said:
Sure, I just fire up vim for small bits of code... Don't see the point in loading a bloated java ide if your only writing a couple of class files. If your doing a big project something like IntelliJ is great but not all the time. Its well worth learning how to develop on the command line.

Its also a good idea to run your code under as many different environments as possible. Even a supposedly WORA language like Java can have some surprising portability issues. ANything one can do to ensure the robustness of ones codebase is a Good Thing.
 
manic_man said:
You have used C++ in the past so have a good inkling of the basics of classes etc but C++ is (arguably) not truly OO. It was a concept "tacked" onto C++ when it became popular.

I dont think C++ has ever really claimed to be true OO. Its merely a language that supports the OO paradigm - its entirely possible to write a C++ program without a single class.
 
I agree its definately woth knowing how the command line works, but in the real world when do you ever write a "small" program that only has a few classes. For uni purposes maybe when doing small assignments yes, but I would still use an IDE for the obvious benefits of file organisation, error handling and debugging. Also a decent IDE like IntelliJ can actually help with your understanding of the language and helps you make less non-compile error mistakes.

Say you have one big class (should never have but hey) that you've written using vi or notepad, its full of errors and warnings, Trawling though the output of the command line can be tedius, time consuming and all together pointless when there are IDE's out there whose sole purpose is to make the developers life easier. Most will actually give you a proper error message and some even offer an automatic fix.

As for devleoping on a platform that has no IDE, we are talking about Java, its platform independent, most IDE's are written in Java and will work on unix, linux, hp, windows and yes even a Mac.

Command line processing is useful knowledge and should be known before you even attemp to write a program, its basics. But for actually developing code i would use an IDE any time, especially when learning the language for the first time.
 
You might be writing a new class for a project, and instead of loading the whole project each time you need to test your new code, it can be easier to test it using the command line, and then once you know it's working it can be integrated with the rest of the project.
 
Is there an easy guide on how to use these ides like netbeans and eclipse?

I've used about 4 different ones and I always get the same 2 errors everytime.

init:
deps-jar:
Compiling 1 source file to C:\Documents and Settings\Ash\JavaApplication1\build\classes
C:\Documents and Settings\Ash\JavaApplication1\src\helloworld\Main.java:3: cannot find symbol
symbol : class string
location: class helloworld
public static void main(string args[])
C:\Documents and Settings\Ash\JavaApplication1\src\helloworld\Main.java:5: package system does not exist
system.out.println("hello world");
2 errors
BUILD FAILED (total time: 2 seconds)
 
That looks to me that you have the wrong dependancies set in the IDE. Somewhere there should be an option to point it at your JDK.

Or hmm, has that error message made all your code lower case.. Java is case sensive you need String[] for a start, likewise System.out.println();
 
Last edited:
Una said:
Or hmm, has that error message made all your code lower case.. Java is case sensive you need String[] for a start, likewise System.out.println();

It compiles. :D However it doesn't run, just stops after it's says "build sucsessful".
 
In most IDE's there is an option to just build the source and an option to compile and run. No idea about netbeans though never really used it.
 
Back
Top Bottom