Friday, September 28, 2018

Top 4 Books to learn Oracle PL/SQL Programming - Best, Must Read

In last summer, I had to work on a Java project which was using Oracle database at their backend. The project was a mix of Java code with Oracle PL/SQL stored procedures, where Stored procedures were quite big and complex to read. I had not worked on Oracle for a couple of years and almost forget whatever I knew before. So, to revise, update and re-learn and I looked over some of the books and online courses like The Complete Oracle SQL Certification Course which helped me a lot. In my quest to revise and re-learn Oracle SQL, I also find lots of their used books on Oracle PL/SQL which are both interesting to read as well as provides a great wealth of information to any programmer.

Thursday, September 27, 2018

Can a Non Static Method Access a Static Variable/Method in Java?

"Can a non-static method access a static variable or call a static method" is one of the frequently asked questions on static modifier in Java, the answer is, Yes, a non-static method can access a static variable or call a static method in Java. There is no problem with that because of static members i.e. both static variable and static methods belongs to a class and can be called from anywhere, depending upon their access modifier. For example, if a static variable is private then it can only be accessed from the class itself, but you can access a public static variable from anywhere. Similarly, a private static method can be called from a non-static method of the same class but a public static method e.g. main() can be called from anywhere.

Wednesday, September 26, 2018

How to Remove all Unused imports in a Java file - Eclipse Shortcut

How to remove all unused imports in Eclipse
Eclipse IDE gives warning "The import XXX is never used" whenever it detects unused import in a Java source file and shows a yellow underline. Though unused import in Java file does not create any harm, it's unnecessary increase length and size of Java source file and if you have too many unused imports in your Java source file, those yellow underline and Eclipse warning affect readability and working. In my last post on Eclipse, we have seen some Java debugging tips on Eclipse and in this post, we will see Eclipse shortcut to remove all unused imports in Eclipse. There are many options to tackle this problem e.g. you can collapse import section of code in Eclipse or you can altogether remove all unused imports from Java file, and we'll see them in this short tutorial.

How to find Length of String in SQL Server? LEN() Function Example

One of the most common task while writing SQL queries or stored procedure is to find the length of String. Since most of the columns are VARCHAR, you often need to find the length before taking any action. In Java, you can find the length of String by using the length() method but how about SQL Server? How will you find the length of String in Microsoft SQL Server in general and Microsoft SQL Server 2016 in particular? Well, you can use the LEN() function to find the length of a String value in SQL Server, for example, LEN(emp_name) will give you the length of values stored in the column emp_name. This method exists from SQL Server 2008 onwards which means you can use this function in SQL Server 2012, 2014, 2016 and latest version of Microsoft SQL Server i.e. SQL Server 2017.

Tuesday, September 25, 2018

How to Solve UnrecognizedPropertyException: Unrecognized field, not marked as ignorable - JSON Parsing Error using Jackson

While parsing JSON string received from one of our RESTful web services, I was getting this error "Exception in thread "main" com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "person" (class Hello$Person), not marked as ignorable". After some research, I found that this is one of the common error while parsing JSON document using Jackson open source library in Java application. The error messages say that it is not able to find a suitable property name called "person" in our case, let's first take a look at the JSON we are trying to parse, the class we are using to represent the JSON document and the error message itself.

Error Message:
Exception in thread "main" com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "person" (class Hello$Person), not marked as ignorable (4 known properties: , "id", "city", "name", "phone"])

Sunday, September 23, 2018

Top 5 Database design and Modelling Books for Programmers and DBAs of All level

The database design and modeling are one of those topics which rarely gets the attention they deserve, especially at the start of the project, but once things have gone out of hand then everybody talks about that. Comments like - this database are designed poorly, it is not performing well, you cannot add a new column easily etc becomes very common. The most problem with database design is that it is mainly done by application developers e.g. Java or C++ developer who knows SQL but they are not the expert of how to design tables and schema. The Database admins or DBAs know database and SQL better than application programmers but they focus on the admin part of the database rather on application part e.g. designing tables and relations between them, which is left to the application developer.

Saturday, September 22, 2018

JUnit Testing Tips - Constructor is Called Before Executing Test Methods

Even though almost all Java programmers either use JUnit or TestNG for there unit testing need along with some mock object generation libraries e.g. Mockito, but not everyone spends time and effort to learn subtle details of these testing libraries, at least not in proportion of any popular framework like Spring or Hibernate. In this blog post, I am sharing one of such detail, which has puzzled me a couple of years ago. At that time, though I had been using JUnit for a significant time, I wasn't aware that code written inside the constructor of Test class is executed before each test method.  This behavior of JUnit has caused, some of my test to failed and putting hours of investigation in my code, without realizing that this is happening because of JUnit is initializing the object by calling constructor before executing test method annotated with @Test annotation.

Friday, September 21, 2018

When to use intern() method of String in Java?

The String.intern() method can be used to deal with String duplication problem in Java. By carefully using the intern() method you can save a lot of heap memory consumed by duplicate String objects. A String object is said to be duplicate if it contains the same content as another string but occupied different memory location e.g. str1 != str2 but str1.equals(str2) is true. Since String object consumes a large amount of heap memory in average Java application, it makes sense to use the intern() method to reduce duplication and take advantage of String pool feature provided by Java. You can use intern() method to intern a String object and store them into String pool for further reuse.

Wednesday, September 19, 2018

Kotlin vs Java - Which language Android Developers should Learn?

Ever since Google announced Kotlin as the official language for Android development in Google IO 2017, programmers, who want to become an Android Developer are in dilemma. Now the big questions in front of them are whether they should learn Kotlin or Java? The answer to this questions depends upon your profile. If you are a complete beginner who wants to learn Android development then my answer is Java, but if you are Java developer who wants to jump into the lucrative market of Android App development then my answer is Kotlin. I'll discuss why beginner Android programmer should start with Java and why Java developer should learn Kotlin in this article.

Tuesday, September 18, 2018

How to enable HTTP Basic Authentication in Spring Security using Java and XML Config

In the last article, I have shown you how to enable Spring security in Java application and today we'll talk about how to enable Basic HTTP authentication in your Java web application using Spring Security. I'll show you how to do that using both the Java configuration and XML configuration if you are using Spring Security 3.1 or lower version, but before that let's understand what is Http basic authentication and why do you need that? One of the most common ways to authenticate a user in a web application is by using form login i.e. you provide a login page and user will enter his username and password for authentication. This works great for human users but sometimes there are situations where you can't use a login form for authentication.

Saturday, September 15, 2018

Top 5 Java SE 8 Certification Books - Best of Lot Must Read

If you are preparing for Oracle Certified Associate, Java SE 8 Programmer, also known as Java SE 8 Programmer I or OCAJP8 exam and looking for some good resources e.g. books, study notes, and mock exams then you have come to right place. I have been sharing some of the most useful resources for Java 8 certification aspirants ever since the exam was launched. You can find a lot of this exam and essential resources in this blog. To continue that tradition, I am going to share some of the best books to crack the Java SE certification i.e. OCAJP 8 (1Z0-808)  and OCPJP 8 (1Z0-89). Yes, you need to pass two exams to become Java 8 certified professional. The OCAJP is also a prerequisite for OCPJP exam, which is a professional level exam. Alternatively, if you already hold a Java certification e.g. Java SE 6 or before then you can take one of the upgrade exams e.g. 1Z0-810 to become Java SE 8 certified professional.

Thursday, September 13, 2018

Clean Code by Uncle Bob - Book Review - Must read for Software Engineers

Even though, the Clean Code book has been released many years ago and there are lots of good reviews already available, I couldn't resist to write my own experience about this great book. I came across this book many years ago but since then I have read it multiple times and I have recommended it to my readers, students, and fellow developers. It is one of those books which make you feel that why didn't you come across it earlier, I felt the same when I first learned about this book. The Clean Code is all about writing good quality code and how do you judge the quality of code? Well, you won't appreciate good until you have seen bad code and that's what this book do.