Things to remember while learning Java

When you talk about Object Oriented Programming, the best and the most apt example that comes to the mind is Java. Developed by Sun Microsystems, Java leads the way in terms of cross platform programming language and developing application software. The reason Java has gained such a large fan base and unprecedented popularity is because the language deploys a very easy and efficient approach to perform various programming tasks and aid the developers.

 

Its simplicity can sometimes be a distraction and the highly experienced Java developers have always aimed a notch higher and have tried to explore the different possibilities that the language offers. Being a good Java developer is always within touching distance of any computer programming enthusiast, however; it is standing amongst the very bests that matters. 

Below are some tips that might help you grow as a Java developer and gain more knowledge about the language. 

1. Get the basics right

As Java offers so many features and options to the developers, people are sometimes lured into learning too many things in too little time. As a result of this, they get ‘bits and pieces’ knowledge of a few options that Java offers, but their basics hang on a loose thread. Trust me when I say this, Java is one programming language which is easy if you have paid attention to the simple basics, however; it can be frustrating if you get greedy and try to take the shorter route forward.

2. Don’t just read 

Well, if your sole purpose of learning Java is to clear the exam you have the next day, go ahead and mug up all the things that you can and you might just get the passing marks. However; if you are really serious about learning Java and getting better at it, the best way to do it is not by reading, but by implementing. Gain knowledge and then execute what you have learnt, in the form of code. You can never learn Java if you are not willing to get your hands dirty.

3. Understand your code and algorithm

Even if you are writing a simple code having a ‘if else’ statement, as a beginner, start by realizing the code on a piece of paper. The algorithm and the whole compiler process will look so meaningful once you understand the idea behind the code. Even for experts, the best way to solve a complex problem or to formulate an algorithm to solve a Java program is to break the problem into sub-parts and then try to devise a solution for each sub part. When you start getting the solutions right, you will get the confidence to work more.

4. Do not forget to allocate memory 

This tip is particularly useful for those who switch from C, C++ to Java. The memory allocation in Java using the ‘new’ keyword is a necessity as Java is a dynamic programming language. C, C++ does not explicitly have this feature, therefore you must take care while handling array and object declaration in Java. Not using the ‘new’ keyword will show a null pointer exception in the code.

Eg:

1
int array = new int [5];

Note the difference in array declaration in Java and C or C++.

5. Avoid creating useless objects

When you create an object in Java, you use up memory and processor speed from the system. Since object creation is incomplete without allocating memory to it, it is better to keep the object requirements under check and not create unwanted objects in the code.

Eg:

1
2
3
4
5
6
7
8
public class vehicles {
    public List getvehicles(){
        if(null == vehicles){ // this ensures that the object is initialised only when its required
            countries = new ArrayList();
        }
        return vehicles;
    }
}

6. Interface is better than Abstract class

There is no multiple inheritance in Java, and this will be spoon fed to you so many times while learning the language that you will probably never forget it for the rest of your life. However; the tip here in not to remember that there is no multiple inheritance in Java, but the fact that interface will come in handy if you want to implement something like multiple inheritance without using the extends keyword. Remember, in Java, when nothing goes your way, you will always have interface by your side. Abstract class does not always give programmers the liberty of having a variety of methods to work with, however; interface only have abstract methods therefore is does the job of abstract classes and has other advantages as well. 

7. Standard library is a bliss

The biggest advantage that Java has over its predecessors, from a programming point of view, is probably its rich set of standard library methods.  Using Java’s standard library makes the job of a programmer easy, more efficient and gives a well organised flow to the code. Further, operations can be performed easily on the methods specified in the library. 

 

Related blog:

 

Spring boot tutorials