Difference between Stable and Unstable Sorting Algorithm?

Recently in one on the interview, after some initial questions about sorting algorithms e.g. how do you write QuickSort or difference between QuickSort and MergeSort, the interviewer asked about do you understand the difference between stable and unstable sorting algorithm? This question was new to my reader, so he says, Sorry, never heard about that. The story ended there, and Interviewer moved on to next question but like many of us, my reader went on to find more about unanswered  questions and ultimately he asks me what is the meaning of a stable and unstable sorting algorithm? Some of you might be heard about it and many of you might not know about this distinction, I'll try to answer this question in this article.

Top 5 books to learn Agile and Scrum Methodologies - Best, Must Read

When I started my career, it was all waterfall model. You try, fail, and then with every version you get an improved version of a software. I pretty much used to this model of software development until I was introduced to Agile development methodologies in my next company. I was confused about Agile as some people say its Scrum and Sprint, other ways its XP and Kanban etc. The confusion lasted for a long time because I was afraid of asking questions (afraid of being perceived as dumb and someone who wastes time on meetings) and only getting information in bits and pieces and I wasn't good at searching books at that time. From that experience, I learned that, when you have confusion and want to learn more about a new technology, nothing is better than a book or online training courses to start with.

3 Best Spring Security Online Training Courses for Java Developers

The Spring Security is one of the leading open source, security framework which allows you to implement security in Java based web applications. It provides several security features e.g. authentication, authorization, remember me out-of-the-box, which means you can directly use them without adding code or changing your class. Yes, Spring Security implements security at application level i.e. you can even secure your non-secure resource without modifying them. It is also the leading framework to secure RESTful Web Services. Because of all these, the demand for Java developers with good knowledge of Spring Security is very high. They are also some of the highly paid Java developers. Many Java and Spring developer, particularly those who are involved in enterprise and Java web development are learning Spring Security.

Top 5 Java And Android Game Programming Books for Programmers

Many programmers and game developers  think that Java isn't the best language for game design, but you cannot ignore Java for game development. There is always some popular platform which allowed you to develop and sell games in Java e.g. J2ME in past and Android now. Ever since Android used Java as a programming language, the game development in Java has got a new lifeline and seems to be doing quite well. Even games like Minecraft also doing great on the Java platform. It's true that C++ is still the best language to develop games due to their high-performance and many top game development companies e.g. Sony, Nintendo, and Microsoft XBox they prefer C++ over Java when it comes to developing great games. But with the Introduction of Android and iOS has completely changed the game development industry.

Maven - 10 Things Java developer should know

The Apache Maven is an essential tool for Java developers. It makes their life easy by allowing them to create Java project faster by using a standard directory structure. It also helps them to download project dependency automatically. Not only that, Maven also download transitive dependencies which relieve Java developers from the big headache of keep check of different versions of dependent libraries. For example, if your application is dependent on Spring framework but Spring is dependent on Log4j then you also need to download the correct version of Log4j JAR files for Spring MVC framework, Maven does this automatically for you. Maven also allows you to build projects, upload artifacts to the central or local nexus repository and deploy the release in your various test environments automatically.

Difference between application/x-www-form-urlencoded and multipart/form-data in HTTP/HTML?

Recently in one of the Java web developer interview, one of my readers asked about the difference between x-www-form-url-encoded and multipart/form-data MIME types. In HTTP, there are two ways to send the HTML form data to the server either by using ContentType application/x-www-form-urlencoded or by using multipart/form-data. Even though both can be used to send both text and binary data to the server there is a subtle difference between them. In the case of x-www-form-urlencoded, the whole form data is sent as a long query string.

Jersey Web Service Hello World Example in Java

After Restlet, Jersey is another popular open source framework to create RESTful web services in Java. Jersey conforms JAX-RS specification and actually it is the reference implementation of JAX-RS (JSR 311)(http://jsr311.java.net/nonav/releases/1.1/index.html) specification. In the last article, we have seen the Restlet HelloWorld Example and today we'll see the Jersey HelloWorld Example. Typically, when a developer thinks of creating a RESTful web service using Java, they assume that using a Java EE application server is the only way to create this type of application. However, there are simpler, lightweight alternative methods for creating RESTful applications available using Java SE. This tutorial demonstrates one such alternative using the Grizzly Web server along with the Jersey REST framework. Grizzly's main use case is the web server component for the GlassFish application server.

How to compare two lists of values in Microsoft Excel - Java

If you are working in real world application then you may frequently face scenarios where you have to compare data e.g. you get two lists of values and you want to know which values are common between two lists, which values only exists in the first list and which values only exists in the second list. If the list contains just 5 to 10 values you can do it easily with your eyes but what is fun if a programmer doing the task manually. You should be able to leverage all the tools available to you to do this comparison reliably. One of such ubiquitous and omnipresent tool is Microsoft Excel which is much more powerful then you can think of. It's like your brain, most of us just use 5% of Excel and a good knowledge of Excel's little bit advanced functionality e.g. VLOOKUP can be very helpful while comparing the list of values and reconciling data between different worksheet.

How Spring MVC Framework works? How HTTP Request is processed?

One of the frequently asked Spring MVC Interview questions is about explaining the flow of web request i.e. how an HTTP request is processed from start to end. In other words, explaining the flow of request in Spring MVC. Since many of my readers ask this question time and again, I thought to summarize the flow of request processing in a short article. It all starts with the client, which sends a request to a specific URL. When that request hit the web container e.g. Tomcat it look into web.xml and find the Servlet or Filter which is mapped to that particular URL. It the delegate that Servlet or Filter to process the request. Since Spring MVC is built on top of Servlet, this is also the initial flow of request in any Spring MVC based Java web application.

How to prepare for Spring Framework Certifications?

Ever since Pivotal, the company behind Spring framework made the mandatory Spring training optional (see here), I have received many queries from experienced Java developers who are interested in doing Spring certifications. This move from Pivotal suddenly makes the Spring certification affordable for many experienced Java and Spring developers who were interested in Spring certification earlier but couldn't progress further due to expensive mandatory training. Since many of them are now preparing for Spring certifications e.g Spring Core or Spring via self-study they are increasingly looking for good resources to prepare for the exam. I have received a lot of questions on preparation, books, mock exams, exam structure, passing marks and useful resources.

How to get JAR files of Jackson Libary for JSON Processing

If you are using Jackson to parse a JSON String in Java first time and wondering where can you get the Jackson related JARs, or which JAR files are really need then you have come to the right place. It can be really confusing for a new user to set up or include Jackson library in their Java projects sometimes, especially, if you are not very familiar with the structure of Jackson projects, various JAR files and in particular Maven. Since Jackson is the most popular open source library for processing JSON responses e.g. generating Java objects from JSON received from RESTful Web services or generating JSON String from Plain Old Java Objects (POJO). It is the go-to library for any JSON need because it offers a lot of features without compromising on performance.

What is the cost of Spring Framework Certification and Training in India and USA?

One of the frequently asked question about Spring certifications and training e.g. Spring Core and Spring Web Application Developer Certification is their cost e.g. what is the cost of Spring certification in India? or how much it cost for Spring framework certification in the USA etc. Earlier, Spring certification used to cost around 3000 USD in the USA and other North American countries and around 50,000 INR in India due to mandatory training you needed to take before you can appear in the exam. The cost of the Spring framework training was more than 90% of the total cost of the Spring certification. But gone are those days. Since 10th May 2017, you can take the exam without mandatory training, see here. Due to this reason, the cost of Spring certification has come down heavily and it's just now the cost of the exam voucher which is just 200 USD globally.

2 Books to Prepare for Spring Professional Certifications Exam

Ever since Pivotal has removed the requirement of mandatory training to become a certified Spring developer, many Spring developers have been asking for good resources to prepare for Spring Professional V4.2 Exam and Spring Professional V4.3 Exams e.g. good books, mock exams, study notes etc. to prepare for Spring Core Certifications via self-study. Since, earlier, you cannot give Spring certification exam without attending an online or instructor-led core Spring training, which cost around 3200 USD in the USA and North America and 50K INR in India, many experienced Spring developers refrain from becoming a certified Spring developer. Now that restriction has been lifted and it's not mandatory to take training to take Spring certification, many Java developers who have good working experience in Spring framework are looking to get recognition for their skill.

jQuery Tutorial - How to modify multiple HTML elements in one line

jQuery allows you to modify multiples elements in one go, you can modify attributes, text, or color of multiple HTML elements by executing just one line of jQuery code. In this jQuery tutorial, I will show you how to modify multiple <li> elements in one go. In our example, we have a couple of <li> tag to display sub-headings, now we will change them in one go using jQuery. If you look at our HTML, we have an ordered list <ol> to display top 10 programming languages, each of them is a <li> item. We also have one button, "Click Me", which will when clicked, changes all <li> item's text to "jQuery is the new Boss". Here is the jQuery code, which does that.

Can you take Spring certification without Pivotal Training Course?

Yes, you can take Spring certification without taking mandatory Spring training. Pivotal, the company behind Spring, has announced on 10th May 2017 that "Spring Certification Exams are now available for individual purchase, without enrolling in the course". This is one of the most exciting changes in the Spring certification program since it's launched 10 years back. The cost of Spring certification was the single, biggest obstacle for many experienced Java and Spring developers to get certified for their Spring framework skills. This step from Pivotal is a really positive step and gives a real chance to many experienced developers in cost sensitive countries like India to get certified for their skill. Now, you don't have to enroll for a 50K training if you have good knowledge of Spring certification and exam objectives, just like Java certification, you can buy the Spring certification voucher @ 200 USD and take the exam online or offline at any test center.

Solution of java.lang.OutOfMemoryError: GC overhead limit exceeded

The java.lang.OutOfMemoryError: GC overhead limit exceeded is another type of OutOfMemoryError in Java which comes when JVM spent too much time doing garbage collection without any success.  For example, if almost 98% of CPU for a Java process is busy doing GC and reclaims very less amount of Java heap space around 2%, then JVM throws "java.lang.OutOfMemoryError: GC overhead limit exceeded" error. Though, the definition of 98% CPU time may vary between different Garbage collector and different JVM version.  Unlike java.lang.OutOfMemoryError: Java heap space and java.langOutOfMemory: Permgen space, this is not so frequent and you will rarely encounter this error in your Java application, but this also denotes resource exhaustion.

How to enable Spring Security in Java Web application?

Spring Security is one of the most popular frameworks to implement security in Java web application in a declarative way. It provides several essential security features e.g. LDAP authentication, authorization, role-based access control,  remembers the password, URL protection, concurrent active sessions management etc. In order to enable Spring security in Java Web application, you need to do configure three things, declare a delegating proxy filter in web.xml, add the ContextLoaderListener in web.xml and provide actual security constraints on applicationContext-Security.xml file. Since Spring security uses a chain of filters to implement various security constraints, also known as Spring's "security chain filter", it relies on web container for the initialization of delegating filter proxy.

How to print 1 to 100 without using loop in Java

This is one of the interesting problems  I have seen on coding interviews  for beginners. The program has surprise element by saying that you need to print 1 to 100 without using a loop e.g. for, forEach or enhanced for loop. This brings out some innovative solutions from candidates which tell a lot about their approach, knowledge, and attitude. I remember, asking this question during campus recruitment to at least 5 candidates. The first one took 5 minutes to think and then come up with the brute force way where he just copies pasted 100 System.out.println() and printed number 1 to 100 but when we asked to improve that, he couldn't too that. Unfortunately, he didn't think that recursion can replace an iterative algorithm without using a loop.

Difference between Servlet and JSP?

Servlet and JSP are two of the most popular Java web technologies to generate dynamic content in Java web applications there is some key difference between them. For example, Servlet is designed for Java developers as most of the coding is done in Java, while JSP was designed and developed for web GUI developer e.g. guys who write HTML and JavaScript and that's why you see the coding in JSP is tag based. Even though you can use HTML tags as String inside Servlet and Java code as Scriptlet inside JSP, both are considered as bad practice and should be avoided at all cost because they are very hard to maintain. The different nature of Servlet and JSP also allows frontend and backend developers to work in parallel, JSP work is mostly done by frontend developers while Servlet work is done by backend developers.

Top 10 Free Java Programming Books, EBooks and PDF download

Who doesn't like free stuff? Well, I do like and many Java programmers like me simply love free Java books, eBooks, and PDFs. Fortunately, the Internet is full of free books and eBooks but unfortunately, many of them are of not good quality. Most of the eBooks which are freely available either are sample chapters of popular Java programming books or they are simply old and out-of-date. In my last article, I have shared a lot of such books and the feedback was that most of them, even though they are good in the past, have simply not up to the mark. The search goes on and while browsing the net a couple of days back I hit the Jackpot when I found these free Java books from Oreilly. Unlike most of the books, these free Java books are good, up-to-date and cover latest technologies like Java 8, MicroServices, Docker, Java EE, Functional Programming and Core Java.

Which Java 8 Certification Should you Take? OCAJP8 (1Z0-808) , OCPJP8 (1Z0-809) , or Upgrade(1Z0-810 and 1Z0-813)

There are a lot of confusion among Java programmers and Oracle Java Certification aspirants related to various Java 8 certifications e.g. what are exam codes, which exams they should go for, whether they are eligible for Java SE 8 upgrade exams, and what should they do if they have just passed Java SE 7 Programmer II certification. I will try to answer each of these questions here, but to get it right let's first clear the confusion about various Java SE 8 exams There are four Java 8 certifications available in Oracle's site:

1) Oracle Certified Associate, Java SE 8 Programmer OCAJP8, exam code 1Z0-808
2) Oracle Certified Professional, Java SE 8 Programmer OCPJP8, exam code 1Z0-809
3) Oracle Certified Professional, Java SE 8 Programmer (upgrade), exam code 1Z0-810
4) Upgrade to Java SE 8 OCP ( Java SE 6 and all prior versions) - exam code 1Z0-813

Top 4 Books to Learn Java for Beginners (Newbie)

I receive lots of emails and Facebook chats related to Java, but one of the most common questions which I have mostly asked is, which is the best book to learn Java? I have just started learning Java, Could you please recommend a good core Java book to me? After answering in one word too many of those readers and new Java developers as "Head First Java", I thought to write this blog post, Why? because some of them come back to me and asked me "Can you please recommend a serious Java book, not the comics?" Well, I didn't like that comment, but then I thought it's natural that not everyone will find "Head First Java" as good as I have always found.

Cause of "java.lang.SecurityException: Missing required Permissions manifest attribute in main jar" [Solved]

If you are working Java Web start application using JNLP and suddenly started throwing "java.lang.SecurityException: Missing required Permissions manifest attribute in the main jar", then check whether you have updated the Java or JRE on your machine. From JDK 1.7 update 51, Java has tightened the security further with number of changes e.g.

1) Block all self-signed and unsigned Java application and Applet if you have opted for HIGH security in Java Control Panel, which is also the default one.

2) Require "Permission" attribute for High-security setting

3) Warning users of missing permission attribute for medium security setting.

Difference between Struts ValidatorForm vs ValidatorActionForm - Interview Question

Struts provide two classes ValidatorForm and ValidatorActionForm for validating form fields. Instead of doing basic validation by using the validate() method in Action class, these classes allows you to leverage rich feature of validation framework provided by Jakarta Struts framework. You can do declarative validation by defining rules in XML config files like validation-rule.xml or validations.xml as well. Since Struts is one of the popular Web MVC frameworks, you can also use its validation framework on any Java web application implemented using Struts. Now, coming back to the question, what is the actual difference between ValidatorForm and ValidatorActionForm in Struts? They both look quite similar, right?

Difference between PriorityQueue and TreeSet in Java?

The PriorityQueue and TreeSet collection classes has a lot of similarities e.g. both provide O(log(N)) time complexity for adding, removing, and searching elements, both are non-synchronized and you can get element from both PriorityQueue and TreeSet in sorted order, but there is fundamental difference between them, TreeSet is a Set and doesn't allow a duplicate element, while PriorityQueue is a queue and doesn't have such restriction. It can contain multiple elements with equal values and in that case head of the queue will be arbitrarily chosen from them. Another key difference between TreeSet and PriorityQueue is iteration order, though you can access elements from the head in a sorted order e.g. head always give you lowest or highest priority element depending upon your Comparable or Comparator implementation but iterator returned by PriorityQueue doesn't provide any ordering guarantee.

Difference between Transient, Persistent, and Detached Objects in Hibernate

In Hibernate framework, an entity can be in three states, transient, persistent, and detached. When an object is in transient state, it is commonly refereed as transient object, similarly if it is in persistence and detached state, it is known as persistent and detached object. When an entity is first created using the new operator e.g. new User() and not associated with Hibernate session e.g. you haven't called session.save(user) method then it is known as transient object. At this stage, Hibernate doesn't know anything about this object and the object doesn't have any representation in database e.g. a corresponding row in the User table. Hibernate will not run any SQL query to reflect any changes on this object. You can move this object into persistent state by associating it with an hibernate session e.g. by calling save() or saveOrUpdate() method from an hibernate Session.

Top 5 FREE eBooks to Learn jQuery Online or download PDF

Everybody loves free resources, don't you? Well, I do and that's why I am always in search of good free resources e.g. eBooks and training courses. In the last article, I have shared some of the free JavaScript books and this time I am sharing a couple of good free eBooks to learn jQuery. The jQuery is one of the most important skills in today's internet world. It is the JavaScript library which has changed the face of websites, they are now more interactive and smooth than ever before. The Internet is also not short of free resources and when it comes to learning jQuery, you will find thousands of articles and tens of eBooks, but not all resources are good. Some of them are not up-to-date and many of them contain incorrect information, hence choosing the good resource is vital.

Difference between @Autowired and @Inject annotation in Spring?

What is the difference between @Autowired and @Inject annotation in Spring is one of the frequently asked questions on Spring interviews? Since everybody is now moved or moving to annotation driven, Java configuration in Spring, this question has become even more important for prospective candidates looking for a Java web development job using Spring framework. The @Autowired annotation is used for auto-wiring in Spring framework. The Autowiring is a process on which Spring framework figure out dependencies of a Spring bean, instead of you, a developer, explicitly specifying them in the application context file. You can annotate fields and constructor using @Autowired to tell Spring framework to find dependencies for you.

Difference between CAST, CONVERT, and PARSE function in Microsoft SQL Server

Though all three, CAST, CONVERT and PARSE are used to convert one data type into another in SQL Server, there are some subtle differences between them.The  CAST method accepts just two parameters, expression, and target type, but CONVERT() also takes a third parameter representing the format of conversion, which is supported for some conversions, like between character strings and date time values. For example, CONVERT(DATE, '2/7/2015', 101) converts the character string '2/7/2015' to DATE using DATE format 101, representing United States standard. By using the PARSE function, you can also indicate the culture by using any culture supported by the Microsoft's  dot NET framework. For example, PARSE('7/8/2015' AS DATE USING 'en-US') parse the input literal as a DATE by using a United State English Culture, similar to 101 formatting style.

Difference between repaint and revalidate method in Java Swing

What is the difference between revalidate() and repaint() in Java Swing is one of the popular Swing Interview Questions especially on Investment banks? Though both methods sound similar, there is a subtle difference between them. the revalidate() method instruct LayoutManager to recalculate layout and often called once new components are added or removed from Container. The revalidate() can also trigger to call to the repaint() method to repaint components which have changed i.e. width, height or any other visible property, which can affect layout. On the other hand repaint() method puts a paint request in AWT thread, for repainting of a component on which it has called.

OCAJP 1Z0-808 - Best Books and Mock Exams for Java 8 OCA Certification

From the last couple of months, I have been helping few developers to prepare for Java 8 associate certification with exam code 1Z0-808, also known as OCAJP 8. From my experience, both for preparing for Sun certification and helping other developers to get Java certified, I can say that two keys to be successful in Oracle Java certification are choosing a good study guide and buying one or two top quality mock exam simulators. When I say success, it doesn't just passing the exam but scoring above 90% because passing score 65% is not very difficult to achieve and anybody can pass OCAJP8 by just a couple of month of practice but to score 90% and above is not that easy, you need to prepare and prepare hard. Since just passing OCAJP8 will not make the desired impact, I always suggest my students aim for 100%, so the n worst case then can still score above 90%.

Recursive Binary Search Algorithm in Java - Example Tutorial

The binary search algorithm is one of the most famous search algorithms in computer science. It allows you to search a value in logarithmic time i.e. O(logN), which makes it ideal to search a number in a huge list. For example, in order to search a number in a list of 1 million number will take around 210 comparisons compared to 1 million comparison required by the linear search algorithm. Only thing is that the list must be sorted before you can use binary search algorithm and it must support index-based search. That's why binary search is often implemented using an array because doing a binary search with linked list will not be fast because it doesn't provide index-based access i.e. O(1) access. You have to traverse to that element to read its value in linked list which is O(n), effectively reducing the performance of binary search to a sequential search algorithm.

Top 10 Java books of last 5 Years For Experienced Programmers

If you think you have read all important books on Java and don't have anything new to read then hang on. Java is changing continuously, now Java 9 is on the way, but more importantly, it has already changed a lot in last 5 to 6 years with major releases like Java 8 and some useful features introduced in Java 7. Not only, the language is changing but also the Java virtual machine, Garbage collector, and other tools involved in Java development is changing, hence, it is now a right time to look at some of the newer Java books which are released in last 5 years to learn new features and tools of Java. Since I often receive emails and Facebook messages about some good books to read on Java, I thought to jot down books I have read in last a couple of years.

Can we declare a class Static in Java?

The answer to this question is both Yes and No, depending on whether you are talking about a top level class or a nested class in Java. You cannot make a top level class static in Java, the compiler will not allow it, but you can make a nested class static in Java. A top level class is a class which is not inside another class. It may or may not be public i.e. you can have more than one class in a Java source file and only needs to be public, whose name must be same as the name of the file, rest of the class or interface on that file may or may not be public. On the other hand, a nested class is a class inside a top level class. It is also known as the inner class or member class in Java.

Log4j Tips : Use MDC or Mapped Dignostic Context to distinguish logging per Client or Request

The MDC or Mapped Diagnostic Context is a concept or feature of Log4j logging library which can be used to group related log messages together. For example, by using MDC you can stamp a unique identification String like clientId or orderId on each log message and then by using grep command in Linux, you can extract all log messages for a particular client or order to understand exactly what happened to a particular order. This is especially very useful in multi-threaded, concurrent Java applications where multiple threads are simultaneously processing multiple orders from multiple clients.  In such applications, searching for relevant log messages in a big log file where log messages for multiple orders or clients are overlapping is a big task.

Difference between ArrayList and ArrayList<?> in Java - Raw Type vs Wildcard

One of my readers asked me about the difference between ArrayList vs ArrayList< in Java?>, which was actually asked to him on a recent Java development interview. The key difference between them is that ArrayList is not using generics while ArrayList is a generic ArrayList but they looks very similar. If a method accepts ArrayList or ArrayList<?> as a parameter then it can accept any type of ArrayList e.g. ArrayList of String, Integer, Date, or Object, but if you look closely you will find that one is raw type while other is using an unbounded wildcard. What difference that could make? Well, that makes a significant difference because ArrayList with raw type is not type safe but ArrayList<?> with the unbounded wildcard is type safe.

Difference between Abstraction and Encapsulation in Java - OOP

Both Abstraction and Encapsulation are two of the four basic OOP concepts which allow you to model real-world things into objects so that you can implement them in your program and code. Many beginners get confused between Abstraction and Encapsulation because they both look very similar. If you ask someone what is Abstraction, he will tell that it's an OOP concept which focuses on relevant information by hiding unnecessary detail, and when you ask about Encapsulation, many will tell that it's another OOP concept which hides data from outside world. The definitions are not wrong as both Abstraction and Encapsulation does hide something, but the key difference is on intent.

How to compare two XML files in Java - XMLUnit Example

The XMLUnit library can be used to compare two XML files in Java. Similar to JUnit, XMLUnit can also be used to test XML files for comparison by extending the XMLTestcase class. It is a rich library and provides a detailed comparison of XML files. Btw, comparing XML is completely different than comparing String in Java or comparing object using equals(), as two XML which contains different comment and whitespace can be equals, which is not true for String or character comparison. Also while comparing XML files, it's very important to know exactly which content or part is different and XMLUnit not only shows the content which is different but also XPath of elements which is getting compared.

Top 5 books to Learn Object Oriented Programming - Must Read, Best of Lot

The OOP or Object Oriented Programming is one of the most popular  programming paradigms which helps you to organize code in re the l world system. It's a tool which helps you to write complex software by thinking in terms of objects. Unlike its predecessor procedural programming paradigm which is implemented most notably by C, which solves the problem and complete task by writing code for computers, OOP style of programming allows you to think in terms of real world objects which has both state and behavior. You can view anything as objects and then find their state and behaviors, this will help you to simulate that object in code.

10 Examples of CUT command in UNIX and Linux

The cut command in UNIX is a nice utility program which allows you to cut data from a text file. The Linux cut command allows you to cut data by character, by field or by column. if used correctly along with sed, find, or grep in UNIX, the cut can do lots of reporting stuff. For example, you can extract columns from a comma separated file or a pipe or colon delimited file using cut command. For example, if you are only interested in first two columns you can show them using this command.  In this Linux cut command tutorial we will see different options of cut command, different examples of Linux cut command and some important points about cut in UNIX.

Java Program to Multiply Two Matrices - Matrix Multiplication Example

How to write a Java program to multiply two matrices in Java is a very good programming exercise to get familiar with the two-dimensional array in Java. this example teaches about how to multiply arrays, how to access elements from a multi-dimensional array, how to pass them to a function etc. Since the matrix is a natural representation of multi-dimensional array in Java, they are often used to illustrate real word matrix exercises e.g. the calculating sum of two matrices or calculating the difference of two matrices etc. By the way, before writing the program, let's recap how to multiply two matrices in mathematics first. If you remember, you can only multiply two matrices if, and only if, the number of columns in the first matrix equals the number of rows in the second matrix. That is known as matrix multiplication criterion.

How hostname to IP address Conversion or Name Resolution works in Linux?

One of my favorite Linux Interview questions is about how to convert hostname to IP address in Linux? This questions not just test candidate's basic Linux command skills but also shows his understanding of how name resolution works in UNIX or Linux? Many developers, software engineers, and support professional don't really know how Linux converts an hostname into IP address or what happens when they type http://www.amazon.com in their browser in UNIX? They are not really familiar with how the name amazon.com is resolved to an IP address. Since network application only works with IP address and names are for us humans, who find it easier to remember a name than IP address, it makes sense to understand how this name resolution happens. Sometimes, this question also asks as for how nslookup or host command works, which are two of the popular command to convert hostname to IP address.

JAXB Date Format Example using Annotation | Java Date to XML DateTime String Conversion

One of the common problem while marshaling Java object to XML String using JAXB is the default format of date and time provided by JAXB. When JAXB converts any Date type object or XMLGregorianCalendar to XML String, precisely xsd:dateTime element, it by default prints unformatted date e.g. 2012-05-17T09:20:00-04:30. Since most of the real world, Java application has a requirement to print date in a particular format like dd-MM-yyyy or include date and time in format dd-MM-yyyy HH:mm:ss, it becomes a problem. Thankfully, JAXB is very extensible and provides hooks and adapters to customize marshaling and unmarshaling process. You can define an extension of XmlAdapter to control and customize marshaling and unmarshaling or any Java type depending upon yours need.

10 Examples of Optional in Java 8

Null is bad, it can crash your program. Even it's creator called it a billion dollar mistake hence you should always try to avoid using nulls whenever you can. For example, you should not return a null String when you can return an empty String, similarly never return null collections when you can return an empty collection. I have shared many such tips in my earlier article, 10 tips to avoid NullPointerException and my reader liked that a lot. But, I wrote that article a couple of years ago when Java 8 was not around and there was no Optional, a new way to avoid NullPointerException in Java, but, things has changed now. Java SE 8 style of coding is rapidly becoming the de-facto coding style in many companies and as a Java developer you should also learn and embrace the good things of Java 8 e.g. lambda expression, streams and of course the Optional.

Does making all fields Final makes the class Immutable in Java?

One of the common misconceptions among many Java Programmer is that a class with all final fields automatically becomes Immutable. This is not correct, you can easily break immutability of certain class if the final field it contains is a mutable one, as we'll see in this article. One of the most common examples of this is a java.util.Date fields e.g. birthDay, expirtyDate, or joiningDate sort of fields. You have to be extra cautious to keep your class' immutability intact with mutable fields. The most common mistake in this regard happens when Java programmer return reference of the original object when a client ask e.g. getBirthDay() returns the date object pointed by birthDay field. When you return a reference to a mutable object, you are sharing ownership of that reference with whoever receives it. This can break invariant, such as immutability.

How to Convert Map to JSON to HashMap in Java? Example Tutorial

In the last couple of years, JSON slowly took over XML as preferred format to transfer data from client to server and vice-versa. Because of increasing usage of JSON, Java developers are also getting a good exposure of JSON. If you are writing web services e.g. traditional GET based services, or modern RESTful web service, you also have to provide support for JSON format along with TEXT and XML. Though standard Java API doesn't support encoding and decoding of JSON from Java Object, there are a bunch of good open source JSON libraries available to Java developers. Jackson and GSON are two of the most popular such library to deal with JSON data in Java.   They not only allow you to parse JSON String to Java Object but also to create JSON formatted String from Java object. They also provide utilities to deal with formatting and other day-to-day features you need to deal with JSON formatted data.

5 Books to Learn Scala and Functional Programming - Best of Lot

Scala is one of the relatively new programming languages which encompasses best practices of many programming languages. The biggest strength of Scala is that it provides a nice blend of object-oriented programming and Functional programming. So, you can not only construct elegant class hierarchies for maximum code reuse and extensibility, you can also implement their behavior using higher-order functions. It has a concise syntax with less ceremony which also makes it ideal for scripting but doesn't underestimate its power. Like Java, Scala has also used for mission critical applications by technical giants like Twitter, LinkedIn, and Intel. Let's be honest, learning Scala is not easy, even for experienced Java programmers. When I started learning Scala, the syntax looks quite different to me. Being used to the verbose style of Java, the brevity of Scala looks cryptic to me but once I learned, that brevity is what I liked most.

2 Free Oracle Certified Master Java Enterprise Architect (OCMJEA) 6 Mock Exams - 1Z0-807

The OCMJEA 6 or Oracle Certified Master Java Enterprise Architect Java EE 6 is one of the most respected Java certification. It is also the most toughest Java exam currently available. In order to get this certification, you need to pass not just one but a couple of exams, submit assignments and essays and also have to complete a mandatory training. The Java EE 6 Enterprise Architect Certified Master 1Z0-807 exam is the start of it. Once you pass this exam, you need to complete Java (EE) Enterprise Architect Certified Master Assignment (1Z0-865) and Java (EE) Enterprise Architect Certified Master Essay (1Z0-866) exams. After successfully completing these exams, you need to attend one mandatory training from the list of training programs, only then you will be awarded the Oracle Certified Master certification. Though, it's not necessary to take the training after completing exams, if you like, you can choose a relevant training which can help you to prepare well for OCMJEA 6 certification and take that first before appearing for any exam.

5 Reasons Why Java's old Date and Caledar API was Bad

If you have been programming in Java for a couple of years then you may know that how bad was Java's Date and Calendar API was, I mean the java.util.Date and java.utill.Calendar was badly designed. Though Java has corrected it's mistake by introducing a brand new, shiny Date and Time API, not many Java developers are using it yet. In a bit to motivate you to use new Date and Time API from Java 8, I am going to list down a couple of reasons why Java's Date and Calendar class has been criticized so much in the past.  These points are also important to know from the Interview point of view because as an experienced Java programmer, it is expected from you to know the shortcomings of existing API and how new API solves those problems.

How to format Date in SQL Server and Sybase Example

How to format a date in SQL Server like in the "yyyymmdd" format? Suppose you have a date and time column in Sybase or Microsoft SQL Server,  which is displaying values in "Dec  31, 2011, 12:00 AM" and you want to display it in any particular DATE format like YYYYMMDD or DDMMYYYY, how will you do that? This is also one thing you need to keep in mind when you convert a DATE, TIME, DATETIME column into CHAR or VARCHAR values.

It's easy to format dates using the convert function in Sybase or SQL Server, but it's slightly difficult to remember the cryptic formatting style codes that go with it. For example using style code, 112 is used to format dates in "YYYYMMDD" format e.g. "20170329".

2 Practical Data Structure, Algorithm, and Design Interview Questions from Investment Banks - Java, C++, C#

No doubt that Data structure and algorithms are an integral part of any Programming job interview, including Java, C++ or any other programming language. In fact Data structure and algorithms are quite a favorite one and all top notch companies including Google, Microsoft, Amazon and investment banks like Goldman Sachs, Citigroup, Barclays, Morgan Stanley or J.P. Morgan focus extensively on data structure and algorithms, while hiring both senior and mid-level developers in Java, C++, and C# positions. When I shared some traditional, popular, and more frequently asked questions on Data structure and Algorithms in my earlier article, I received a lot of feedback to share some practical, scenario-based questions on data structure e.g. which kind of data structure will you use in a particular scenario and why.

Difference between Stack and Queue Data Structure in Java

Stack and Queue are two of important data structures in the programming world and have a variety of usage. As opposed to the array and linked list, which are considered as a primary data structure, they are a secondary data structure which can build using an array or linked list. You can use Stack to solve recursive problems and Queue can be used for ordered processing. The difference between Stack and Queue Data structure is also one of the common questions not only in Java interviews but also on C, C++, and other programming job interviews. Well, main difference comes the way these data structures are used, Stack is LIFO (last In First Out) data structure, which means the item which is inserted last is retrieved first, similar to a stack of plates in a dinner party, where every guest pick up the plate from the top of stack.

10 Tools Used by Java Programming Developer in Day to day life

Every trade has their tools, and Java programming is no  exception. In fact, good knowledge of tools and mastery of using them, saves a lot of time in design, development, testing, debugging, and troubleshooting any production issue. In order to become a good developer, you must know right tools for right jobs. A developer without tools and tricks are like a toothless lion, hence it's very important that you devote some time on learning tools required for your day to day job. Many developers think that learning an IDE like Eclipse, NetBeans or IntelliJ is enough, but that's just the start of the process. No doubt that IDEs are the most important tool ever created for programmers but they are not the solution for everything.

How to Reverse a linked list in Java using Recursion and Loops

There are a couple of algorithms exists to reverse a singly linked list in Java e.g. You can use the three-pointers approach or solve this problem using a stack, or simply using recursion without the external stack. As I had pointed out on the earlier post about linked list, that reversing a linked list is one of the most popular data structure interview question, based on linked list, which means, you just can't afford to prepare this one, before going for any programming interview. Despite being so common, It's not easy to solve this problem on the fly. Many Java programmer struggles to reverse a linked list using both iteration and recursion, which makes this question very useful for filtering programmers who can code and who are not so good with coding. Indeed, this is one of the confusing algorithms to understand and it's not easy to grasp, especially if you haven't practiced linked list based questions e.g. finding middle node of linked list in one pass or inserting and removing an element from linked list data structure.

Top 30 Scala and Functional Programming Interview Questions and Answers

Scala is a programming language which aims to provide best of both object-oriented programming and functional programming world. It not only allows you to  construct elegant class hierarchies for maximum code reuse and extensibility but also allows you to implement their behavior using higher-order functions and other functional programming technique. It is touted as one of the languages which can probably take over Java, though it didn't happen especially after Java 8 release which also provides some functional programming tools to Java e.g. lambda expression and stream. Nevertheless, Scala is a good language and created by following best practices from several other programming languages including Java. Scala is an acronym for “Scalable Language”. This means it is designed by keeping scalability in mind. Many companies e.g. Twitter, LinkedIn, and Intel uses it for their mission-critical application.

What is difference between SQL, T-SQL and PL/SQL?

Today, we are going to see another common and interesting SQL interview question, what is the difference between SQL, T-SQL and PL/SQL? It is also one of the most common doubt among SQL beginners. It's common for programmers to think that why there are many types of SQL languages, why not just single SQL across DB? etc. Well, let's first understand the difference between SQL, T-SQL and PL/SQL and then we will understand the need of these dialects. SQL is standard for querying, inserting and modifying data in relational database. It is categorized into DDL and DML and powerful enough to create a database objects e.g. table, view, stored procedure and can perform CRUD operation (SELECT, INSERT, UPDATE, and DELETE) query.

Difference between First and Second Level Cache in Hibernate

If you have used Hibernate in past then you know that one of the strongest points of Hibernate framework is caching, which can drastically improve the performance of Java application's persistence layer if configured and used correctly. Hibernate provides caching at many levels e.g. first level cache at Session level, second level cache at the SessionFactory level, and query cache to cache frequently executed SQL queries. The first level cache minimizes database access for the same object. For example, if you call the get() method to access Employee object with id = 1 from one session, it will go the database and load the object into memory, but it will also cache the object in the first level cache.

How to enclose a list of values into single quotes for SQL query - Use Microsoft Excel

Many times you get a list of values which you want to check in the database to confirm if they exist in your tables or to get more information bout them. For example, you got a list of 100 stocks and you want to check their last day closing prices in the database. The problem arises when values to be searched are Strings e.g. VARCHAR or CHAR because VARCHAR values need to enclosed in the single quotes in most of the database e.g. SQL Server, Oracle or MySQL. If number of values are less than 5 then it make sense to add single quotes around them and separate them by comma manually so that you can use then on IN clause of your SQL query, but if it's more than 5 e.g. 50 or 100 then manually enclosing them into single quotes will take a lot of time and most importantly programmers are not supposed to do such silly stuff manually.

What is Method References in Java 8? An Example

Lambda expression allows you to reduce code compared to anonymous class to pass behaviors to methods, method reference goes one step further. It reduces code written in a lambda expression to make it even more readable and concise. You use lambda expressions to create anonymous methods. Sometimes, however, a lambda expression does nothing but call an existing method. In those cases, it's often clearer to refer to the existing method by name. Method references enable you to do this; they are compact, easy-to-read lambda expressions for methods that already have a name.

Top 5 Advanced SQL Books for Experienced Programmers - Best of lot, Must read

If you an experienced programmer and know how to write SQL queries and database fundamentals but want to take your SQL and database skills to next level then you have a come to the right place. This is the second article about SQL books, In the first part, I have shared some of the best SQL books which are essential to learning SQL queries and fundamentals of database e.g. normalization, indexing, and other design stuff, if you haven't read it yet, I suggest to do it now. You will find some amazing book to start learning SQL. In this article, I am going to share some of the best books to learn advanced SQL programming, which can help you to write better SQL queries and understand how database process those queries.

How to Implement Stack in Java using Array and Generics - Example

The stack is one of the popular data structure which supports LIFO (Last In First OUT) operation. Due to LIFO advantage, you can use stack data structure to convert a recursive algorithm to an iterative one. Stack data structure is very easy to implement using an array or linked list, but you don't have to implement it by your own because Java already provides a Stack implementation in java.util.Stack class. This class is a subclass of the Vector class and you should use it whenever you need Stack for your production code, there is no point inventing the wheel again when the focus is on developing your application. At the same time, as a programmer and coder, you should also know how to implement your own stack by using a basic data structure like an array or linked list.

How to find largest and smallest number from integer array in Java

Today I am going to discuss one of the frequently asked programming interview questions to find the largest and smallest number from an integer array. This question is commonly asked on telephonic interviews and the first round for screening candidates. It's one the same league of other frequently asked coding question e.g. Fibonacci, Palindrome, Prime, and Power of two checks. They are easy but can feel difficult during the interview because of pressure. You can further evaluate candidate's problem-solving skill by asking him to solve the problem by a different way e.g. if he solves the problem using a loop then ask him to do it without the loop. If he knows recursion he can do it, but if he has just mugged the answer, he won't be able to do it.

Why we use Threads in Java?

In one word, we use Threads to make Java application faster by doing multiple things at same time. In technical terms, Thread helps you to achieve parallelism in Java program. Since CPU is very fast and nowadays it even contains multiple cores, just one thread is not able to take advantage of all the cores, which means your costly hardware will remain idle for most of the time. By using multiple threads, you can take full advantage of multiple cores by serving more clients and serving them faster. Since, in today's fast-paced world, response time matters a lot and that's why you have multi-core CPUs, but if your application doesn't make full use of all resources then there is no point adding them, multi-threading is one way to exploiting huge computing power of CPU in Java application.

10 Examples of curl Command in UNIX and Linux

The curl is one of the essential commands to send HTTP requests from UNIX and Linux operating System. curl command is part of the cURL package and it's not just useful to send HTTP request but also allows you to transfer file using FTP and send mail using SMTP. The cURL utility supports many protocols including DICT, FILE, FTP, FTPS, Gopher, HTTP, HTTPS, IMAP, IMAP, LDAPS, LDAP, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMB, SMTP, SMTP, Telnet, and TFTP. It also supports SSL certificates, HTTP POST, HTTP PUT, FTP uploading, HTTP form based upload, proxies, HTTP/2, cookies, user+password authentication (Basic, Plain, Digest, CRAM-MD5, NTLM, Negotiate and Kerberos), file transfer resume, proxy tunneling and more. It's particularly useful if you are working with web services.

Difference between Executor, ExecutorService and Executers class in Java

All three classes Executor, ExecutorService, and Executers are part of Java's Executor framework which provides thread pool facilities to Java applications. Since creation and management of Threads are expensive and operating system also imposes restrictions on how many Threads an application can spawn, it's a good idea is to use a pool of thread to execute tasks in parallel, instead of creating a new thread every time a request come in. This not only improves the response time of application but also prevent resource exhaustion errors like "java.lang.OutOfMemoryError: unable to create new native thread". A thread pool which is created when an application is a startup solves both of these problems. It has ready threads to serve clients when needed and it also has a bound on how many threads to create under load.

String Deduplication of G1 Garbage collector to Save Memory from Duplicate String in Java 8

You might not be aware that Java 8 update 20 has introduced a new feature called "String deduplication" which can be used to save memory from duplicate String object in Java application, which can improve the performance of your Java application and prevent java.lang.OutOfMemoryError if your application makes heavy use of String. If you have profiled a Java application to check which object is taking the bulk of memory, you will often find char[] object at the top of the list, which is nothing but internal character array used by String object. Some of the tools and profilers might show this as java.lang.String[] as well e.g. Java Flight Recorder, but they are essentially pointing to the same problem i.e. a major portion of memory is occupied with String objects.

5 Differences between COALESCE and ISNULL in SQL Server

What is the difference between COALESCE and ISNULL is one of the frequently asked Microsoft SQL Server interview question. Recently, one of my reader asked the same question to me, he got confused between these two because both are used to replace NULL values to default values in SQL Server. I'll try to answer this question here with little bit of insight about when to use ISNULL and COALESCE in SQL Server. Even though both ISNULL and COALESCE is used to provide default values for NULLs there are some key differences between them e.g. ISNULL() is a T-SQL or Microsoft SQL Server specific function or operator, and datatype and length of result depends upon parameter, but COALESCE is a SQL ANSI standard, it can accept more than one parameter and unlike ISNULL, the result doesn't directly depends upon parameter, it is always the type and length of the value returned.

5 Difference between Constructor and Static Factory method in Java- Pros and Cons

The common way to create objects in Java is by using public constructors. A class provides public constructor e.g. java.lang.String so anyone can create an instance of String class to use in their application, but, there is another technique which can be used to create objects in Java and every experienced Java programmer should know about it. A class can provide a public static factory method which can return an instance of the class e.g. HashMap.newInstance(). The factory method is a smart way to create objects in Java and provides several advantages over the traditional approach of creating objects using constructors in Java. It can also improve the quality of code by making the code more readable, less coupled, and improves performance by caching.

Top 5 JavaScript Books to Learn - Best of Lot, Must Read

The JavaScript is the most popular programming language in Web, way ahead of popular ones like Perl, Ruby, and Python. It is also one of the essential skill for any Web developer. It is even true for Java developers. If you have JavaScript in your resume or LinkedIn profile, you will likely receive many Job opportunities. Everybody wants polyglots, programmers who know multiple programming languages because most of the real world projects are developed with multiple technologies, you will always found some component is written in Java, some in C++ then you have JSP, Server, jQuery, JavaScript etc for web pages and so on. In short, it's very important to learn JavaScript in today's competitive world.

10 points about volatile modifier or field in Java

The volatile modifier has always been an interesting and tricky topic to many Java programmers. I still feel that it's one of the most underutilized modifiers in Java, which can do a lot of good if understood and applied correctly, after all, it provides a lock-free way to achieve synchronization in Java. If a field is shared between multiple threads and one of them change its value i.e. one thread reads from the field which is written by other threads, then, by using a volatile modifier, you can synchronize access to this field. The volatile modifier in Java provides visibility and ordering guarantee without any locking. You might know that compiler and JVM can re-order your code due to various reasons e.g. performance improvement which can be a problem in concurrent Java application.

Insertion Sort Algorithm in Java with Example and Explanation

The Insertion sort is another simple sorting algorithm, which can be used to sort any linear data structure like an array or linked list. On simplicity, this is next to bubble sort, and it’s also pretty close to how humans manually sort something (for example, a hand of playing cards). As the name suggest, Insertion sort is based upon insertion of an element in a sorted list. To start, we assume that first element is already sorted. Then we pick the next element and put it in second place, we compare this number with the first element and if they are not in sorted order, we swap them. This gives a new sorted list of 2 elements. Now we pick the third element and put it in the 3rd place and compare it with the 2nd placed number, if they are not in sorted order, we swap them again, if all three elements are still not in sorted order then we again swap the 1st and 2nd element, now we have a sorted list of three numbers.

Difference between Comparison (QuickSort) and Non-Comparison (Counting Sort) based Sorting Algorithms?

For many of you, this might be a surprise that how you can sort or arrange items without comparing with each other, but it's possible. There are some sorting algorithms that perform sorting without comparing the elements rather by making certain assumption about the data they are going to sort. The process is known as non-comparison sorting and algorithms are known as the non-comparison based sorting algorithms. No comparison sorting includes Counting sort which sorts using key value, Radix sort, which examines individual bits of keys, and Bucket Sort which examines bits of keys. These are also known as Liner sorting algorithms because they sort in O(n) time. They make certain assumption about data hence they don't need to go through comparison decision tree.

Top 5 Core Java Books for Beginners - Learn Best of Lot

I have shared a lot of books related to Java and related technologies in the past e.g. Spring, Hibernate, JVM internals and performance tuning, multi-threading and concurrency, design patterns, data structure and algorithms etc, but I haven't shared core Java books for beginners yet. Even though I have mentioned a couple of popular titles every now and then, I really didn't have a good compilation of essential core Java books for beginners. Since Java is one of the most popular programming languages and has very good job prospect it has became a choice of programming language to start learning coding and application development, it makes sense to start well with core Java. This article contains books which will teach you how to code using Java programming language.

Top 6 SQL Query Interview Questions and Answers

The SQL, short form of Structured Query Language is one of the essential skills in today's programming world. No matter whether you are a Java developer, C++ developer or Python developer, you must know how to write SQL queries. Every programming job interview has at least one or two questions which require you to write SQL query for given requirement and many developers struggles there. It's easy to answer theoretical questions like what is the difference between clustered and non-clustered index (see) or what is the difference between correlated and non-correlated subqueries (see), but when it comes time to actually write SQL queries to solve problems, it's not that easy, especially if you haven't done your homework and practice.

Top 5 Websites for Practicing Data structures and Algorithms for Coding Interviews Free

Are you preparing for Coding Interviews? If yes then you might know that there are a number of free online resources to practice important topics for coding Interviews e.g. data structure and algorithms, database and SQL, and others. These websites are equally useful for both, new programmers who are just learning the fundamentals and for experienced ones who are brushing up their coding skills for interviews. I have been sharing useful resources for programming and technical interviews from a long time in this book. In past, I have shared some recommended books for coding interviews and some of the frequently asked programming interview questions from tech companies (see here). But, my readers have been asking about some recommended websites for practicing programming challenges and coding interview questions.

How to Consume JSON from RESTful Web Service and Convert to Java Object - Spring RestTemplate Example

So far, I have not written much about REST and RESTful web service barring some interview questions e.g. REST vs SOAP, which is thankfully very much appreciated by my readers and some general suggestions about best books to learn REST in past, but today I am going to write something about RESTTemplate class from Spring MVC framework. Like its predecessors JdbcTemplate and JmsTemplate, the RestTemplate is another useful utility class which allows you to interact with RESTful web services from a Java application built using Spring framework. It's a feature rich and supports almost all REST methods e.g. GET, POST, HEAD, PUT or DELETE, though we'll only use the GET method in this article to consume a RESTful Web Service and convert the JSON response to Java objects. It's one of the basic but interesting examples, given you will often find scenarios to consume a RESTful web service from Java program.

17 Examples of Calendar and Date in Java

The java.util.Calendar class was added in Java on JDK 1.4 in an attempt to fix some flaws of the java.util.Date class. It did make some task simpler, e.g. create an arbitrary date comes easier using new GregorianCalendar(2016, Calendar.JUNE, 11) constructor, as opposed to Date class where the year starts from 1900 and Month was starting from zero. It didn't solve all the problems e.g. mutability and thread-safety of Date class still remains, but it does make life easier at that time. Now with Java 8 everything related to Date and Time has become super easy and consistent but unfortunately, it will take another 5 to 10 years before older version of Java goes away. Don't believe me, there are still applications running on JDK 1.5 which was released 12 years ago. The bottom line is it's still important to know about Date and Calendar in Java.

Top 10 Java wait, notify, Locking and Synchronization Interview Questions

There has been a lot of articles and books written on how to use wait and notify in Java, how they work, when do you need synchronization, and how to write concurrent code in Java, but, unfortunately, I still see many Java programmer struggles to solve even the classic producer-consumer problem. I know, writing correct concurrent code is challenging and it takes a lot of practice, think through ability and experience to get it right, but at the same time, every Java programmer should be familiar with basics of inter-thread communication, synchronization, locking and understand how all the things work together. They should be able to reason the output of program when the same code is executed by more than one thread, at the same time. They should know that compiler can re-order their code to optimize performance and how they can prevent it.

Top 5 Books to learn REST and RESTful WebServices for Java Programmers

The REST has now become the standard way to develop web services. It's no more SOAP, who used to rule the world in last two decade. The SOAP and XML went very well together in past decade but it seems now REST and JSON have overtaken then and doing even better. Since Java is one of the most popular languages to develop backend services, there is a lot of demand for Java developers who knows web services and can implement and expose existing SOAP-based services into REST style, light-weight web services. This is an excellent opportunity for intermediate and experienced Java developers to learn a more job-oriented skill to keep themselves marketable and many Java developer has already started learning REST and RESTful web services in Java.

Difference between JAX-RS, Restlet, Jersey, RESTEasy, and Apache CXF Frameworks

The JAX-RS is a Java specification request (JSR 311 & JSR 339) which standardize development and deployment of RESTful web services using Java and JEE technologies. It provides API in Java Programming language to create web services according to the REST (Representational State Transfer) architectural pattern. Both Restlet and Jersey are two of the most popular implementation of JAX-RS used for developing RESTful web services in Java ecosystem but there are a couple of other implementation also exist e.g. Apache Wink, Apache CXF, and JBoss RESTEasy. In this article, I'll introduce with these RESTful web services framework in Java world. It's not a very detailed post about strength and weakness of each of the framework but will just give you enough to understand them in detail later.

Where and How to download Spring Framework JAR file (Spring 4.0 or Spring 3.2) without Maven, Gradle

One of the easiest and oldest ways to run a Java program which depends on an external library or framework is to download dependency JAR files, put it on the classpath and then run the program by creating a Main class with the main() method. This is simple but not as easy as you think, there are many challenges down the road e.g. you need to find the right version of JAR files and their dependencies e.g. Spring might have a dependency on other third party libraries like Log4j. So, when the build tool like Maven and Gradle comes, everybody stopped downloading the JAR file manually. All they do is specify the Maven dependency and Maven will download the JAR file of specified version along with their dependencies. This greatly simplified the development and testing of Java application which uses a framework like Spring and Hibernate.

Best Books to Learn Servlet and JSP

Unfortunately, there are not many good books to learn Servlet and JSP for Java web developers. Despite being the most popular Java Web technology, there are very few good books to learn Servlet and JSP. The one book, which everybody will suggest you is the Head First Servlet and JSP, which is indeed one of the best books but it's outdated now. It doesn't cover the latest development in Servlet API, particularly Servlet 3.0 and also not been updated for last 7 to 8 years, but considering others, it is still a good book to learn Servlet and JSP. The main advantage of this book is Head first style which is great for beginners. With lots of repetition, bullet points, fireside chats, Head First book make sure you understand things and not just read them. Since many readers ask me to suggest good books learn Servlet and JSP, I'll share a couple of title in this book, which I think is relevant and help you to learn Servlet and JSP better.

Difference between for loop and Enhanced for loop in Java

Though you can use both for loop and enhanced for loop to iterate over arrays and collections like a list, set, or map. There are some key differences between them. In general, enhanced for loop is much more easy to use and less error prone than for loop, where you need to manage the steps manually. At the same time, for loop is much more powerful because you get the opportunity to control over looping process. All the difference, you will learn in this article, stems from this very fact that traditional for loop gives more control that enhanced for loop but on the other hand enhanced or advanced for loop gives more convenience.

How to prepare for Java Interviews? Topics, Books, and Questions

Java Interviews are a little bit different than traditional programming interviews on tech giants and product based companies like Google, Amazon, Microsoft, or Facebook. First, even though it has questions from Data Structure and Algorithms e.g. String or Array, you can still manage to clear Java interviews if you are not an expert on them. The questions are a little bit easier and more practical than those companies. Another very important thing about Java interviews are questions based upon Java programming language and JDK API. Since Java is also an Object oriented programming language, you will find lots of OOP questions there. Since Java is primarily used as application programming language, the focus is aligned accordingly with questions mostly focusing on API, Java concepts, and design patterns.

How to create LocalDateTime in Java 8 - Example

The LocalDateTime is a new class introduced in Java 8 new Date and Time API. This class is in java.time package and it represents both date and time information without timezone. In this example, you will learn different ways to create an instance of LocalDateTime class in Java 8 e.g. by using the static factory method, or by combining LocalDate and LocalTime instances together, which are subsequently used to denote date without time and time without the date in Java 8. As their name suggests they are local, so they don't contain timezone information.  They are always bound to local timezone i.e. the timezone of the machine on which your Java program is running. The class which contains the date, time and timezone information is known as ZonedDateTime in Java 8.

How to Split String based on delimiter in Java? Example Tutorial

You can use the split() method of String class from JDK to split a String based on a delimiter e.g. splitting a comma separated String on a comma, breaking a pipe delimited String on a pipe or splitting a pipe delimited String on a pipe. It's very similar to earlier examples where you have learned how to split String in Java. The only point which is important to remember is little bit knowledge of regular expression, especially when the delimiter is also a special character in regular expression e.g. pipe (|) or dot (.), as seen in how to split String by dot in Java. In those cases, you need to escape these characters e.g. instead of |, you need to pass \\| to the split method.

Top 10 Excuses Programmers Gives to Avoid Unit Testing

Though everyone loves unit tests and everyone agree with benefits they bring in, when the time comes to write them, you will see a lot of excuses, even from some of the more experienced and senior developers. At the heart of the problem of not writing unit tests or enough unit tests they are two things, first is time pressure i.e. you don't have enough time to complete coding forget about writing unit tests. This problem comes due to erroneous estimation i.e. only estimating time for coding and not including unit testing as part of development. This is also our first excuse, so we'll see it in a short while. The second reason is laziness and ignorance i.e. you don't know to write unit tests but don't put enough effort to learn the tips and tricks.  In this article, I have shared some of the most common excuses given by programmers for not writing unit tests.

How many characters is allowed on VARCHAR(n) columns in SQL Server? How much memory VARCHAR variable takes in disk?

One of the frequently ask SQL questions in any programming interviews is what is the difference between VARCHAR and CHAR data type in SQL? particularly when your project is using Microsoft SQL Server. You might have seen this couple of times, but given its popularity, nowadays people are asking this question differently e.g. they will ask you how much space a column of VARCHAR(2) data type will take? How many characters can it take? How do you minimize the space? Is it better to use a CHAR variable instead of VARCHAR(2) and why? These are some of the really interesting question and more meaningful than classical SQL questions like the difference between char vs varchar data type question.