Easy steps and tips to get started learning to code Java
How easy is it to begin learning Java? I will explain the steps needed to get started. What tools are needed? Which tools to avoid at first. Ask yourself a few questions. Why do you want to learn Java? What are your main goals in learning Java and what do you want Java to do for you? Which kinds of problems do you want it to solve? You can use Java to code console apps, desktop apps, web apps, phone/tablet apps etc. Are you learning it because of school or because of work? For hobby or self-education?
Get the following
- JDK (Java Development Kit)
- A console or command line, either Linux shell or Windows shell or Windows Power Shell
- A text editor JEdit, Atom or Editpad Pro.
- java.exe interpreter and javac.exe compiler (installed in the bin folder of your jdk/sdk installation)
- A google, and with a google get an Oracle Java documentation or tutorial.
- HelloWorld.java example.
- Consider getting Ant build tool, though it’s not necessary for learning and I don’t use it for simple things, it’s a good tool to begin to become familiar with. And it’s easy to use at the command line.
This is all you need to begin learning the basics of Java but there are a couple of more steps in getting started.
- add JDK bin folder to the system path variable.
- its c:\dev\java\jdk9\bin folder in my installation
- set the classpath variable to ‘.’ current folder.
- About the path and classpath.
Other tips I have, make a c:\dev\java\work folder to put things in as you learn. If you do not know how to use the console begin to learn simple things. Even learn to make a simple batch file on Windows or shell scripts on Linux. You can use Windows notepad.exe or even the vi editor on Linux if you wish to begin with, no text editor need be installed. I install JDK under c:\dev\java\jdk9 where 9 is the version major version number. so my bin folder is in c:\dev\java\jdk9\bin which is what you need on the path so that you may use the command line tools. Ant will also have to be added to the path environment variable.
So pull up the editor, get the hello world example text and paste it into a blank buffer, save it as HelloWorld.java and then you will see that the editor should highlight the syntax in color for you. If not then you need to search for how to turn on syntax highlighting. It’s not necessary but it is nice. Sorry, no highlighting for Notepad users. Next compile with javac HelloWorld.java, if no errors then run with java HelloWorld. If all went well, then you should see something like “Hello World!” output to the console. Congratulations you are now a Java programmer!
Console Output and Input
The next thing to learn will be more about System.out.println() or other System.out methods. You can also use the Java Scanner class to get input from the command line easily. Sorry, no color at the windows consoles at least. That is without using a 3rd party library such as JCurses.
GUI (Windows or Desktop) apps
But for graphical fun just use java AWT, and Swing API’s. And begin to learn the replacement for those called JavaFX. And you can do this with text editors and command line tools and should. I recommend coding applets for starting GUI and use appletviewer.exe tool to run them. Applets make it easy to get started drawing some graphics and images, using color and playing sound. You can move on after you get little better at GUI coding to Java frames for desktop and Java Web Start apps, which are basically the web replacement for applets.
Database JDBC SQL
For databases get SQLite or H2, find the appropriate JDBC drivers and get the JDBC API and tutorials. Get an SQL tutorial from the Google. Other databases are MySQL, MS Access and there are many more.
IDE (Integrated Development Environment)
IDE’s help with Refactoring, Debugging, Profiling and more.
Finally, if you must, get you an Eclipse IDE and check it out. Or try out IntelliJ Idea or Netbeans, or one called BlueJ. There is a learning curve to using any tools, and using IDE’s do not make learning to program Java easier but can do the opposite. You can get by without an IDE for much by using Jakarta Ant build tool at the command line. You simply create a build.xml file and put it int he folder with your source. Then in that folder simply type ‘ant’ and it reads that file and builds your project, it removes old class files, recompiles all source files building new class files. It can build javadocs with the javadoc.exe tool which is the java documentation from your project and much more. It can even create jar archive files and deploy them to websites.
Open Source and Repositories CVS, SVN, GIT
If you want to help out on opensource projects you will need to get you a GIT or SVN tool installed. CVS was the old tool and may still be used on some projects. There is a learning curve to using these tools so be prepared. Once you pass over a few hurdles its not bad at all. Github is a place where you can store your code and learn how repositories work.
Learn OOP first and fast.
Class, Object, Interface, Abstract Class
You should always just put one class in one source file, it must be declared Public and it must be named the same as the source file. Put other non-public classes in the same source file, it’s just not normally recommended because it can make it harder to find a class in amongst many source files when you go to look for it. Learn about Interfaces and Abstract classes and methods fairly quickly.
Odds and Ends
Public access means a class member can be seen by any other class anywhere, in the same package or others. Private means a member can only be seen by the class that it is a member of, not even sub-classes. You will need to learn about inheritance and polymorphism fairly soon too. If a member has no access modifier then it can be seen by all classes in the same package (folder). BTW ‘.’ is the current folder which is the default package in Java. If you include no package statement then the class is in this default package.
Import in Java simply imports the name so that you do not have to use the full path to the class name such as java.awt.Button. If you import it then all you need to use Is Button. And java.lang.* is automatically imported in all classes. So you do not have to use java.lang.Integer, for example, only Integer and with no import java.lang.*; or import java.lang.Integer; For classes to be available to use in your app all that is needed is that they are found in the classpath. Look into how to add classes or archives jar files to the classpath. There are a number of ways to do this.
- Open Source
Software Developer Zone, Email me
I hope this is a good starting point for you if it is please let me know by emailing me firstname.lastname@example.org Also if you look around there are many ways to connect with me on SDZ. And read my other articles on Software Developer Zone.