Home » Blog » Learn to code Java now!

Share This Post

Java / Main Slider

Learn to code Java now!

Learn to code Java now!

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

Initial Setup

This is all you need to begin learning the basics of Java but there are a couple of more steps in getting started.

Tips

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.

HelloWorld.java

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.

Phone/Tablet, Websites

A developer can code GUI apps with text editors and you should. Except for phone/tablet apps because they are a bit more complex you will need to install the Android Development Kit and Studio. If you want to learn web development then download Tomcat web server and run it. With Tomcat learn Servlets and very basic Java Server Pages. Learn Java Server Faces and Facelets, Spring and Hibernate. And don’t expect to learn all of that in a day. I’d say a year of constant hard work maybe to become familiar.  You will also need to learn HTML 5, CSS 3 and at least some Javascript would be nice. Download Mozilla Firefox Developer Edition. Chrome comes with developer tools built in by default.  Opera also comes with developer tools.  And you will need several browsers for testing and development and testing. Then pick one probably Firefox for main development browser. Other browsers are Opera, Safari, Edge, Chrome.  There is no more Safari for windows.

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.

Testing Assertions

The Java language comes with some very simple testing functionality. But you may want to look into testing frameworks such as JUnit for Java. There is one for javascript as well. You can write your own test without that, these are called drivers.  You simply make a class that sole purpose is to create an object and call its methods to test it out.

Learn OOP first and fast.

Class, Object, Interface, Abstract Class

First things first. Learn Objects first. In Java, everything is an Object. The quicker you learn Java OOP the better. And let me warn you that Javascript OOP is similar but different and somewhat confusing compared to Java OOP.  Just begin some basic class definitions with constructors, methods, and fields. Make everything public ( a bad habit you will break later) and don’t use static class members, to begin with.  Later you will learn about inner classes, local classes, and anonymous classes. Anonymous inner classes are more practical and useful. Though you are better off just making outer classes for now.

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.

Resources

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 admin@softwaredeveloperzone.com Also if you look around there are many ways to connect with me on SDZ. And read my other articles on Software Developer Zone.

 

Share This Post

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>