Tampilkan postingan dengan label best practices. Tampilkan semua postingan
Tampilkan postingan dengan label best practices. Tampilkan semua postingan

Kamis, 12 Januari 2017

Writing code is art and same applies to SQL queries. The way you structure your query, the way you write it goes a long way to communicate your intent to the fellow developer. When I see SQL queries on emails from multiple developers, I can see the stark difference in their writing style. Some developers write it so neatly and indent their query properly, which makes it easy to spot the key details e.g. which columns you are extracting from which table and what are conditions. Since in real life projects, SQL queries are hardly one-liner, learning the right way to write SQL query makes a lot of difference when you read it yourself later or you share that query to someone for review or use.
Read more �

Jumat, 06 Januari 2017

Did you ever face a situation where some of your innocuous looking action has cause production issue and that too big time? Well, I hope you have not because it's certainly, not a pleasant experience. One of such innocuous looking action is running SQL queries on production databases. I had that in past very early in my career where I removed some config as duplicates only to find after a week that it stopped publishing messages to one of the downstream. When you work in complex systems which has so many components, millions of lines of code, thousands of configuration and many databases with hundreds of tables, you have to be really careful with anything you do. Often there is on the real way to perform a production-like testing, hence the best bet is to keep your change as much isolated and limited as possible.
Read more �

Sabtu, 31 Desember 2016

Hello all, today is 31st December, the last day of 2016 and this is probably the last post on Javarevisited for this year and I want to make it special. That's why I am going to share you some tips on creating maintainable Java applications which will help you not just in the new year, but also in all the coming years in your software development career. One aspect of development, which is often overlooked by developers is to create applications which are both easy to maintain and support. Since a software spends 90% of its lifetime in maintenance mode, it's very important that your application is easy to configure, support, and maintain. Also, Java application is no different than any other software, you must pay attention to these key properties of writing production quality code, hence this tips also applies to any programming language which is used to create real-world software which is used by real users.
Read more �

Kamis, 26 Mei 2016

If you are an author of an internal, proprietary Java library or an external open source library, or you are one of those lucky developers who ship Java application by yourself then you should follow these best practices while naming your JAR files. These best practices are a result of the practical experience of using hundreds of Java library and application. Following these best practices will help in better management of JAR files. It's part of my other best practices articles e.g. best practices while naming variable, writing comments, overriding methods, muli-threading, JDBC, and best practices while dealing with passwords. If you are interested in learning more best practices, you can always search those articles on this blog.
Read more �

Sabtu, 21 Mei 2016

In this part of Java programming mistakes, we will take a look at another common pattern, where programmers tend to use "==" operator to compare Objects, similar to comparing primitives. Since equality of object can be very different in the physical and logical sense, and in the case of domain objects it's mostly driven by business rules, comparing objects with "==" operator, introduces subtle bugs, which are hard to find. The difference between equals() and == operator, one of the Java classics is also asked to find out if the developer is familiar with this important concept or not. Using == operator only make sense when comparing primitives like int, or final constants like Enum. Though there is more involved in comparing two Enum, which you learn by following that link.
Read more �

Senin, 25 Maret 2013

Exception handling is an important part of writing robust Java application. It�s a non functional requirement for any application, to gracefully handle any erroneous condition like resource not available, invalid input, null input and so on. Java provides several exception handling features, in built in language itself in form of try, catch and finally keyword. Java programming language also allows you to create new exceptions and throw them using throw and throws keyword. In reality, Exception handling is more than knowing syntax. Writing a robust code is an art more than science, and here we will discuss few Java best practices related to Exception handling. These Java best practices are followed even in standard JDK libraries, and several open source code to better deal with Errors and Exceptions. This also comes as handy guide of writing robust code for Java programmers.
Read more �

Senin, 04 Maret 2013

Writing or creating immutable classes in Java is becoming popular day by day, because of concurrency and multithreading advantage provided by immutable objects. Immutable objects offers several benefits over conventional mutable object, especially while creating concurrent Java application. Immutable object not only guarantees safe publication of object�s state, but also can be shared among other threads without any external synchronization. In fact JDK itself contains several immutable classes like String, Integer and other wrapper classes. For those, who doesn�t know what is immutable class or object, Immutable objects are those, whose state can not be changed once created e.g. java.lang.String, once created can not be modified e.g. trim, uppercase, lowercase. All modification in String result in new object, see why String is immutable in Javafor more details. In this Java programming tutorial, we will learn, how to write immutable class in Java or how to make a class immutable. By the way making a class immutable is not difficult on code level, but its the decision to make, which class mutable or immutable which makes difference. I also suggest reading, Java Concurrency in Practice to learn more about concurrency benefit offered by Immutable object.
Read more �

Senin, 07 Januari 2013

You need to be careful while overloading a method in Java, especially after the introduction of autoboxing in Java 5. Poorly overloaded method not only adds confusion among developers who use that but also they are error prone and leaves your program on compiler's mercy to select proper method. One of the best examples of a poorly overloaded method is the remove method of ArrayList. There are two versions of remove, first, one which takes an Object as argument i.e. remove(Object element) and the second one, which takes an index as argument i.e. remove(int index). It worked fine until Java 1.4 where there is clearly a distinction between primitive types and objects type but in Java 1.5, where you can pass an int primitive to a method which accepts an Integer object, creates some nasty problem.
Read more �

Selasa, 04 Desember 2012

public modifier vs getter and setter method in Java
Providing getter and setter method for accessing any field of class in Java may look unnecessary and trivial at first place, simply because you can make field publicand it�s accessible from everywhere in Java program. In fact many programmers do this in there early days but once you start thinking in terms of enterprise application or production code, you will start seeing how much trouble it can create in terms of maintenance. Since as per SDLC process, software spends more time in maintenance than development, it�s worth keeping ease of maintenance as one of goal in development. In reality using getter and setter method in Java is one of the Java coding best practice much like using @Override annotation while overriding method in Java. Main problem with making field public instead of getter and setter is that it violates Encapsulationby exposing internals of a class. Once you exposed internals of class you can not change internal representation or make it better until making change in all client code. Since every code change comes with risk and cost of regression testing is high during maintenance, its not a good idea to make field public in Java. In this Java tutorial we will see some more benefits getter and setter offers over public fields in Java.
Read more �

Sabtu, 03 November 2012

@Override annotation was added in JDK 1.5 and it is used to instruct compiler that method annotated with @Override is an overridden method from super classor interface. Though it may look trivial @Override is particularly useful while overriding methods which accept Object as parameter just like equals, compareToor compare() method of Comparator interface. @Override is one of the three built in annotation provided by Java 1.5, other two are @SuppressWarnings and @Deprecated. Out of these three @Override is most used because of its general nature, while @SuppressWarnings is also used while using Generics, @Deprecated is mostly for API and library. If you have read my article common errors while overriding equals method than you have see that one of the mistake Java programmer makes it, write equals method with non object argument type as shown in below example:

Read more �

Selasa, 28 Agustus 2012

Java JDBC Best practices
JDBC Best Practices are some coding practices which Java programmer should follow while writing JDBC code. As discussed in how to connect to Oracle database from Java, JDBC API is used to connect and interact with a Database management System. We have touched some of the JDBC best practices in our last article 4 JDBC Performance tips, On which we have discussed simple tips to improve performance of Java application with database. By using JDBC you can execute DDL, DML and Stored Procedures. JDBC Best practices is probably most significant set of coding practices in Java because it significantly affect performance of Java application. I have seen substantial performance gain by simply following common JDBC best practices like running queries with auto commit mode disable. One of the query which we used in our example of JDBC Batch update was taking almost 30 second to finish with auto commit mode enabled but it just took under one second with auto commit mode disable and using explicit commit. This JDBC tutorial is collection of such practices which help you to write better JDBC code and in most cases result in improved performance.
Read more �