Java programming is easy to learn if you start with the right steps. Java means learning Java concepts, terminologies, processing & execution of your code. I will try to share the best tips for learning Java here which I have learned over the years. I have shared these steps with my Juniors number of times but never I documented these. So, today i am documenting these and sharing with you all, so you can put your energy in the right direction and learn Java fast.
Java is learned with the practice of Java basics including class, objects, packages, modules & control statements. Then followed by IO operations, advanced JVM concepts and build tools. Java debugging and profiling is required in order to verify the code logic. After learning best practices for Java, design patterns and algorithms need to be learned which will be used in code frequently.
There is not a right or wrong way from where you should start Java. I have tried to explain the process in a simple way and in a particular order, which you can follow, to learn java on your own. You can learn java with no programming experience even.
- 1. Setting up Java Environment
- 2. Choosing right IDE
- 3. Understand Java terminology
- 4. Code Practice
- 5. Learn Java basics
- 6. OOPs concepts in Java
- 7. Java advanced concepts
- 8. Java Debugging and Profiling
- 9. Start on Java unit test cases
- 10. Build Tools
- 11. Solid principles and design patterns in Java
- 12. Java coding best practices
- 13. Database basics
- 14. Frontend basic knowledge
- 15. Java web projects
- How much time will it take to learn java?
Following are the best tips to learn Java programming for beginners:
1. Setting up Java Environment
The first step is getting access to a Java environment where you can run your sample code and practice it. You have two choices, either install Java on your machine or use any online free Java compiler. I recommend installing Java, as it will save lots of time and give you more confidence. You can follow these steps to install Java, if already not installed.
Since there are lots of Java Builds and versions available in the market. I don’t want you to spend time comparing those to find the best one. As a beginner, any version is fine. I recommend you to install Java 11 either from Oracle JDK or OpenJDK, it’s more than enough.
2. Choosing right IDE
Next step is to get a good IDE(Integrated Development Environment) tool. A good IDE helps you in coding syntaxes and saves lots of time in basic mistakes like typing wrong keyword name, compilation errors etc. You can choose any IDE, top 3 IDES which mostly are used are Intellij idea, Eclipse and Netbeans. I have been using the Intellij idea and Eclipse for many years. After choosing the IDE, go to their formal website and follow the steps to download/install. Open the IDE and explore the options and get acquaintance with it.
After installation, people generally waste lots of time in customizing the shortcuts, look & feel. Avoid these things to save your time and to be focused, default settings work very well
3. Understand Java terminology
Now it’s time to dive in Java. Start with any Java book or online tutorial, before starting Java coding you need to learn Java terminology. At this point, you don’t need to know the inner details of these. Just get understanding on a high level for the terms Java, JDK, JRE, JIT, Java Compiler, JVM, Memory, threads, Object oriented language, class, bytecode, resources, packages, modules, dependencies, exceptions, Jar, war, main, data types.
4. Code Practice
Next step is to start practicing the code. Write a very basic program and try to run it. Moving forward, whatever you will read in Java, you need to practice at the same time. One mistake, a new beginner often makes is that he edits the same Java class to run another sample of code. Please don’t do this. Everytime, you need to test something, create a new Java class with a specific name or copy an existing one. This way you will have a collection of samples and revise/refer to any sample later if you have any confusion
5. Learn Java basics
Time to start something big. Start with basics first and then proceed further. The order of learning should be class, interface, object, method, data types, access modifiers, conditional statements, loops, static, volatile, collections and threads. There will be lots of related terms with these concepts. In the first go, it’s fine if you didn’t get everything but try to learn maximum. Each concept should be driven by a Java program. If you skip practice, then in 2-3 days you will forget most of reading
6. OOPs concepts in Java
Java language is an object oriented language (OOP). So until you understand OOPs concepts, you can’t leverage the full capacity of that language. Understand different OOPs concepts in Java and try to implement each and every one of these like Encapsulation, Abstraction, Inheritance, Polymorphism, cohesion etc.
7. Java advanced concepts
Before starting Java advanced concepts, I recommend you to revise Java basics once more, this time it will take half of your time, as you already did a lot of work. Start with IO (input/output) operations, file operations, command line read/write, pattern making problems for command line and exception handling. After these, time to shift the gear, Start with foreach loops, iterators, streams, lambda, queues, stacks, locks, logging, JVM & memory architecture, JVM tuning, heap dumps and thread dumps.
8. Java Debugging and Profiling
A developer is not called a developer unless he knows about debugging the code and profiling the code. All IDEs have inbuilt support for debugging and profiling, their shortcut keys can vary but all works in the same way. Java profiling can be done using IDE’s inbuilt profiler or you can add a third party profiler like glowroot or any other.
9. Start on Java unit test cases
It’s time to take one step further ahead. Unit test cases are very necessary, it can tell you that your code is working fine or not. Java has built support for a number of testing frameworks. I recommend using Junit or TestNG, with the combination of Mockito. You need only 1 test framework to understand, that will work fine. Try to understand, writing a test case, running a test case and checking reports of pass/failed test cases. In your IDE, you may need to install additional plugin for test cases from marketplace’s plugin section, which you can easily do by checking IDE documentation.
10. Build Tools
Build tools are required to automate your manual work. You can add/edit custom steps if required. Most famous build tools are Ant, Maven and Gradle. I recommend using Maven or Gradle. These build tools can be configured to download required dependency automatically, creating jar/war, running test cases before creating the final jar etc. In small Java projects, the default configuration is enough, you don’t need to do much, just follow the basic steps from these tool’s documentation and you are ready to go.
11. Solid principles and design patterns in Java
You are moving forward now to becoming a pro level developer. So now, you need to understand the solid principles and start using these in day to day practice. There are more than 25 design patterns, try to understand the most commonly used and implement those in Java. It’s fine, if you are able to understand/implement near to 10, it’s a good start. Keep visiting your design patterns time to time and learn more.
12. Java coding best practices
From a pro level developer, It’s always expected that he knows the best practices and need not hand hold every time. In every project, there are few guidelines and few practices. Guidelines get changed from project to project like naming prefix, categorization etc. But best practices mostly remain the same like managing code, managing packages, reusability of code, PMD rules, method’s cyclomatic complexity, unreachable or dead code etc. You need to create separate layers for dao, services, controllers/servlets and utility class and categorize them according to their behaviour. There is a complete guide on Java code Audit, you can read these to get the insights that someone will review your code on which parameters.
13. Database basics
From a Java developer, basic database knowledge is expected. Although this step is completely optional. But without it, you can never make a Java application which has database integration. I recommend Postgres or MySql for learning purposes. Use Java JDBC drivers and try to insert/ view/ delete/ update records in the database using Java. If you want to be a master in this area, then you can use any ORM tool like Hibernate, iBatis which are implementation for JPA specification. I mostly use Hibernate and write native SQLs as well as HQLs. But it’s fine, if you don’t want to jump into ORM, you can do with basic JDBC drivers for learning purposes.
14. Frontend basic knowledge
15. Java web projects
You should understand the Java web project for it’s various sections like location of static resources, message resources, properties, Java code, unit test code and build files. Understand the concepts of servlets, messages files, properties files, MVC etc. Good choice to learn it quickly, will be using spring boot framework. There are tons of articles on the internet about spring boot. Initially you need to understand Spring boot MVC, Spring boot rest and Spring boot security components. Spring boot is recommended here but not mandatory for this step.
How much time will it take to learn java?
To learn Java in depth, time taken is about 3-4 months, which entirely depends upon your dedication and consistency. In this time, you will be groomed from naive to intermediate level within the first 2 months. Then next month you will be transformed from intermediate level to pro level. Java programming is very vast, you can never say that you learned whole Java. Rather you should aim to learn all the areas which are related to your daily needs in development.
I hope guys, this guide to learn java step by step will help you all. I have tried to keep it simple and logical but nothing comes without hard work. So best of luck to all of you and please feel free to reach me & ask questions if you have any.