Posts

Difference Between Count(*) and Count(1) in SQL

Image
There is no difference between Count(*) and Count(1). They are same both in terms of result and performance. Actual syntax of Count() function is as follows. Syntax: As per syntax, you can use either * or an expression as an argument to function. Here 1 is a non-null expression, so it is same as Count(*).  Brief Introduction: 1. Count returns the number of rows returned by the query. Some examples of Count: 1. select count(*) from employees; 2. select count(salary) from employees; 3. select count(distinct manager_id) from employees; References: a. https://docs.oracle.com/cd/B19306_01/server.102/b14200/functions032.htm

Difference Between Union and Union All in SQL

UNION & UNION ALL: 1. UNION , UNION ALL both merge 2 tables or 2 query results into a single temporary table. The 2 tables must have same structure, otherwise sql returns error. 2. The main difference is UNION will remove duplicate records from results, where as UNION ALL will include duplicate records too. 3. The other difference is, UNION ALL is typically better than UNION, since UNION requires Database server to do the additional work of removing any duplicates. So, when it is certain that there will not be any duplicates in the 2 tables or having duplicates is not a problem, use UNION ALL for better performance.

How to configure a JSP file in web.xml?

Image
In java web applications, you can directly access jsp files without any configuration. For example, http://localhost:8080/SimpleWebapp/Index.jsp, in this link we are requesting index.jsp directly without any config. But if you have placed your jsp files inside WEB-INF directory(see in the image - Welcome.jsp), you can't access directly. For this you need to configure the jsp in web.xml. Let's see how to do, 1. In web.xml, define both servlet & servlet-mapping tags. 2. Inside servlet( ) tag, add your jsp location inside the tag. "< jsp-file>/WEB-INF/Welcome.jsp< /jsp-file>" 3. Complete configuration is < servlet> < servlet-name> Welcome< /servlet-name> < jsp-file> /WEB-INF/Welcome.jsp< /jsp-file> < /servlet> < servlet-mapping> < servlet-name> Welcome< /servlet-name> < url-pattern> /Welcome< /url-pattern> < /servlet-mapping> The result is showed ...

In Detail: Strategy Design Pattern In Java

In this post i am going to explain about Strategy Design pattern. First of all,  What is Strategy Design Pattern? Let's see the definition first. The strategy Pattern defines a family of algorithms, encapsulates each one, and makes them interchangeable. Strategy lets the algorithm vary independently from clients that use it. Very hard to understand, right? This is a high level explanation of Strategy design pattern. Don't explain this definition to beginners. Let's see what is Strategy design pattern in detail, with an example. first, it is a behavioral design pattern. To understand this pattern, you should know the below terminology & concepts of Object oriented programming language. 1. Inheritance, 2. Composition, 3. IS-A , HAS-A relationship, 4. Interface driven programming, 5. Polymorphism. Let's start with an example problem. Consider, we have a base class Animal and 2 sub classes Parrot, Cat (Inheritance). package com.speakingcs.design...