Saturday, 29 December 2018

Inner class is a class defined inside other class and act like a member of the enclosing class. There are two main types of inner classes Static member class Inner class Member class Anonymous class Local class Static member class A static member class behaves much like an ordinary top-level class, except that it can access the static members of the outer.  Outer class can access all inner class fields by referring...

Friday, 21 December 2018

ACID Properties in DBMS? A transaction is a single logical unit of work which accesses and possibly modifies the contents of a database. Transactions access data using read and write operations.In order to maintain consistency in a database, before and after transaction, certain properties are followed. These are called ACID properties. Atomicity By this, we mean that either the entire transaction takes place at once or doesn’t...

filter employees with same salary count greater than five (group by salary) using hibernate criteria? Session session = getCurrentSession(); ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.groupProperty("totalCode")) .add(Projections.groupProperty("activityCode")) ...

Friday, 7 December 2018

public class FirstWordUpperCase { public static void main(String[] args) { System.out.println(changeString("how are you man")); } private static String changeString(String str) { StringBuffer sb = new StringBuffer(); String[] arr = str.split("\\s"); for (int i = 0; i < arr.length; i++) { sb.append(Character.toUpperCase(arr[i].charAt(0))). append(arr[i].substring(1)).append(" "); } return sb.toString(); ...

How to disable caching on back button of the browser? <% response.setHeader(“Cache-Control”,”no-store”); response.setHeader(“Pragma”,”no-cache”); response.setHeader (“Expires”, “0”); //prevents caching at the proxy server %> ...

Wednesday, 5 December 2018

In this kind of association, a foreign key column is created in owner entity. For example, if we make EmployeeEntity owner, then a extra column "ACCOUNT_ID" will be created in Employee table. This column will store the foreign key for Account table. To make such association, refer the Account entity in EmployeeEntity class as follow: @OneToOne @JoinColumn(name="ACCOUNT_ID") private...

One table has a foreign key column that references the primary key of associated table.In Bidirectional relationship, both side navigation is possible. We are discussing an example of Student and University relationship. Many student can enroll at one University. And one University can have many students.  @Entity @Table(name =...

In this scenario, any given employee can be assigned to multiple projects and a project may have multiple employees working for it, leading to a many-to-many association between the two. We have an employee table with employee_id as its primary key and a project table with project_id as its primary key. A join table employee_project is...

Thursday, 29 November 2018

They have a logical index, yes - effectively the number of times you need to iterate, starting from the head, before getting to that node. it can't directly search using index of the object Typically O(1) access by index is performed by using an array lookup, and in the case of a linked list there isn't an array - there's just a chain of nodes. To access a node with index N, you need to start at the head and walk...

Function Interface  Java.util.function has special interface like bleow, it contains generic methods used as type for lambda expression with same type and signature. An interface with exactly one abstract method is called Functional Interface. @FunctionalInterface annotation is added so that we can mark an interface as functional interface.  If  we try to have more than one abstract method, it throws compiler...

Wednesday, 28 November 2018

Angular CLI Useful Commands ng g component my-new-component ng g directive my-new-directive ng g pipe my-new-pipe ng g service my-new-service ng g class my-new-class ng g guard my-new-guard ng g interface my-new-interface ng g enum my-new-enum ng g module my-module Create components. Template, component and js file will be generated with...

To generate new component employee. Go to app root in CLI and run below command ng g c employee/create-employee --spec=false --flat=true ng g c employee/list-employees --spec=false --flat=true component.ts, html and css files will be genarated in employee folder in app and it will add List Employee and Create Employee components...

Tuesday, 27 November 2018

define AngularJS? AngularJS is an open-source JavaScript framework designed for creating dynamic single web page applications with fewer lines of code.  What is Angular 2? Angular is a framework to build large scale and high performance web application while keeping them as easy-to-maintain. Components − The earlier version of Angular had a focus of Controllers but now has changed the focus to having components over...

Friday, 23 November 2018

Need to remove common number 4 from both arrays Input int[] arr1 = { 1, 4, 6, 7, 8 }; int[] arr2 = { 2, 4, 5, 9, 0 }; Output int[] arr1 = { 1, 6, 7, 8 }; int[] arr2 = { 2, 5, 9, 0 }; RemoveCommonElements.java public class RemoveCommonElements { public static void main(String[] args) { RemoveCommonElements app = new RemoveCommonElements(); app.commonRemove(); } private void commonRemove() { int[] arr1 = { 1,...

When Parent throws Generic Exception and Child throws specific exception Compiles and run successfully public class Animal { public void eat() throws Exception { System.out.println("Animal Eating..."); } } public class Cat extends Animal { @Override public void eat() throws FileNotFoundException { System.out.println("Cat Eating ....."); } } public class App { public static void main(String[] args)...

Thursday, 22 November 2018

Java Object class comes with native clone() method that returns the copy of the existing instance. To use java object clone method, we have to implement the marker interface java.lang.Cloneable so that it won’t throw CloneNotSupportedException at runtime. Also Object clone is a protected method, so we will have to override it to use with other classes Student.java public class Student implements Cloneable { private int...

Thursday, 15 November 2018

Structural design patterns are concerned with how classes and objects can be composed, to form larger structures.The structural design patterns simplifies the structure by identifying the relationships.These patterns focus on, how the classes inherit from each other and how they are composed from other classes. Adapter Pattern  An Adapter Pattern says that just "converts the interface of a class into another interface...

Wednesday, 24 October 2018

Declarative Transaction Management Declarative transaction management is the most common Spring implementation as it has the least impact on application code. The XML declarative approach configures the transaction attributes in a Spring bean configuration file. Declarative transaction management in Spring has the advantage of being less invasive.   There is no need for changing application code when using...

An object is chunk of memory , and the reference to the object is way to reach up to that object in the memory Object reference variable contains address of the object which is declared in the heap memory Class Box { double height; double width; double depth; } Box b1; //declare reference ..it will be null b1 = new Box(); //Create an instance assign to reference variable b1 Box b2 = b1; //Only creates reference...

This algorithm uses idea of divide and conquer. Find the element called pivot which divides the array into two halves Left side elements should be smaller than the pivot Right side elements are geater than the pivot Steps Bring the pivot to its appropriate position such that left of the pivot is smaller and right is greater. Quick...

Monday, 22 October 2018

Create shared Semaphore object , lock and unlock in consumer - producer  blocks by limiting thread accessible count to 1 Output will be like produce 1 and consume 1 , produce 2 and consume 2 ... Producer.java public class Producer implements Runnable { private static List LIST; private static Semaphore semaphore; public Producer(List LISTv, Semaphore semaphoreV) { LIST = LISTv; semaphore = semaphoreV; ...

BlockingQueue amazingly simplifies implementation of Producer-Consumer design pattern by providing outofbox support of blocking on put() and take(). No need of manual empty or full check, Blocking Queue handle it internally. Only put and take operation required Output is like one N produce and then consume like FIFO ordedr Producer.java public class Producer implements Runnable { private static BlockingQueue QUEUE; ...

If List is full then our PRODUCER thread waits until CONSUMER thread consume one item and make space in your queue and call notify() method to inform PRODUCER thread. Both wait() and notify() method are called on shared object which is List in our case. Need synchronised block Check for List size manually and wait for consumer and producer threads Since it is synchronised, Needs to wait till N production Needs to wait till...

Saturday, 13 October 2018

LRU Cache (Java) Design and implement a data structure for Least Recently Used (LRU) cache.  The LRU caching scheme is to remove the least recently used frame when the cache is full and a new page is referenced which is not there in cache. Properties are, Fixed Size: Cache needs to have some bounds to limit memory usages. Fast Access:...

Friday, 12 October 2018

What is a Query Plan? A query plan is a set of steps that the database management system executes in order to complete the query.  The reason we have query plans is that the SQL you write may declare your intentions, but it does not tell SQL the exact logic flow to use.  The query optimizer determines that.  The result of that is the query plan The lesson to learn from this when in doubt check the execution...

Java Memory Management, with its built-in garbage collection, is one of the language's finest achievements  It allows developers to create new objects without worrying explicitly about memory allocation and deallocation, because the garbage collector automatically reclaims memory for reuse How Garbage Collection Really Works Many...

Java 8  : How to Sort a List using lambdas? Integer[] arr = { 1, 7, 3, 9, 4, 67, 100, 23, 26, 76, 8 }; List list = Arrays.asList(arr); list.sort((a1, a2) -> a1.compareTo(a2)); System.out.print(list); Is singleton is lazy initialisation? Yes. As in the below code singleton is lazy initialisation. We will not initialise on static instance property. And initialise only on getInstance method, so it will...

It is the first concurrent utility framework in java and used for standardising invocation, scheduling, execution and control of asynchronous tasks in parallel threads. Executor implementation in java uses thread pools which consists of worker threads. The entire management of worker threads is handled by the framework. So the overhead in memory management is much reduced compared to earlier multithreading approaches. The...

A Semaphore is a thread synchronization construct that can be used either to send signals between threads to avoid missed signals, or to guard a critical section like you would with a lock Simple Semaphore implementation: The take() method sends a signal which is stored internally in the Semaphore. The release() method waits for a signal. When received the signal flag is cleared again, and the release() method exited. //...

How Volatile in Java works? The Java volatile keyword cannot be used with method or class and it can only be used with a variable. Java volatile keyword also guarantees visibility and ordering and write to any volatile variable happens before any read into the volatile variable. Example: Singleton Class  public class Singleton{ private static volatile Singleton _instance; //volatile variable public static Singleton...
Page 1 of 101234567...10Next »Last

Search This Blog

Contact us

Name

Email *

Message *