Learn to Code Java!
How easy is it to begin learning Java? I will explain 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? What do you want Java to do for you? What 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? For self-education?
- Get the JDK (Java Development Kit)
- Get a console or command line, either Linux shell or Windows shell.
- Get a text editor JEdit, Atom or Editpad Pro.
- Get a java.exe interpreter and javac.exe compiler.
- Get a google, and with a google get an Oracle Java documentation or tutorial.
- Get a 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 Java but there are a couple of more steps in getting started.
- add JDK bin folder to the system path variable.
- set the classpath variable to ‘.’ current folder.
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 console. Congratulations you are now a Java programmer!
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.
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, 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.
For databases get SQLite or H2, find the appropriate JDBC drivers and get the JDBC Api’s and tutorials. Get an SQL tutorial from the Google.
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 are probably others. 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.
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.
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. So look into how to add classes or archives jar files to the classpath. There are a number of ways to do this.
I hope this is a good starting point for you if it is please let me know by emailing me firstname.lastname@example.org And read my articles at Software Developer Zone, softwaredeveloperzone.com