
Tools all in place for programming: computer, carbs,
caffeine
To program in Java (not JavaScript, a similar but different
language), you need a "compiler", a program to convert Java source
code to bytecode. In the old days, the only option was Sun's Java
Development Kit; but now you have many options, including the GNU
project's
gcj which creates class files
or native
executables, and
jikes, IBM's open source contribution. You also will
need a Java
virtual machine, which is a "machine within a
machine" which understands Java bytecodes and translates them into
machine language on the target processor. There are many available,
but you can never go wrong with the
javac compiler and
java JRE virtual machine included with Sun's
Java standard
edition.
- Visit Sun's J2SE page and download the correct package for
your platform: typically Windows, Linux, or Solaris. Macintosh
users will find they already have the J2SE installed. For maximum
portability, it may be better to get
an older edition; not all your potential users will have the
latest JVM installed. Alternatively, use an open-source or other
third-party compiler such as gcj or jikes, and
compile to a native executable or run it with the Java JRE.
- Learn to use a basic, "clean" editor like Notepad, vi,
or emacs. These don't taint your program source with
formatting information as does, for example, Microsoft Word.
Whatever editor you use, it must have the option to save as "plain
text".
- Learn the basic edit-compile-test cycle:
- Create or edit the program source file(s).
- Compile to .class files.
- Run the program with the java executable, or as an
applet in a browser. If the functionality isn't correct, or you
want to add more features, start again at step 1.
- If you can afford it, buy a good book about Java programming
and carefully read the beginning. With this language, the beginning
is more difficult than later steps.
- Check out sites such as Cksstudios.com, Javacooperation,
Cokeandcode and Sun's website for resources/tutorials.
- Read up and follow a Java tutorial (one of the first recommended tutorials
could be tutorial on collections).
- For specific info on the classes, methods, and variables, visit
Sun's API
- If you face any problems, always try a web search. There are a
lot of good articles about Java on the web.
- Practice makes perfect.
- After you master the basics, try to join the existing open source
project and work together with other people. From the view point of
learning, this is more efficient than to develop something large
and complex by yourself.
- Keep your code organized and add lots of comments for easy
reading, remembering, and updating.
- Unnecessarily long methods (the Java name for subroutines) are
looked down upon since they make your code hard to read and
difficult to update; learn to factor your code into small, precise
modules that do one thing well.
- Don't use "magic numbers" if you can help it. Magic numbers are
numbers and values that are distributed through your code when they
should be defined as a variable, so they can be reused, and
explained in a comment so what they represent can be understood.
This makes code easier to maintain and update.
- Download and install an IDE (Integrated Development
Environment). For example: NetBeans or Eclipse (open source). This will help speed up the
edit-compile-test cycle, at the expense of extra overhead, having
to learn a new tool, and limited functionality. Another option is a
text-based tool such as GNU Make or Apache Ant, which
gives you full control over the process.
- Master JUnit and write automatic tests that check the
consistency of your program. Most serious projects do this.
- Go through the API provided with the SDK. Make a habit of
reading the description of the methods and classes. This will help
you remember the method or class used the next time you need
it.
- Learn technologies in which java is strong: network
communication, database connection, web development and
others.
- After you get some experience, try to get official programmer
certification from Sun Microsystems itself. This is a lot more
serious than any other certification you can get from the third
parties.
[edit]
Warnings
- It is usually not necessary to pay for Java courses that may be
very expensive and offer little value. Unless you want to learn
something specific, it is frequently better just to do more
programming yourself, and learn from other people's open-source
programs.
[edit]
Sources and Citations
Was this article accurate?
Yes
No
Thanks to all authors for creating a page that has been read 18,824 times.