Posts

Showing posts from 2017

Design Pattern

design pattern is a general repeatable solution to a commonly occurring problem in software design. Advantage:- They are reusable in multiple projects. They provide the solutions that help to define the system architecture. They provide transparency to the design of an application. They are well-proved and testified solutions since they have been built upon the knowledge and experience of expert software developers. Design patterns don?t guarantee an absolute solution to a problem. They provide clarity to the system architecture and the possibility of building a better system. Creational design patterns:- These design patterns are all about class instantiation. While class-creation patterns use inheritance effectively in the instantiation process, object-creation patterns use delegation effectively to get the job done. Abstract Factory:- Creates an instance of several families of classes Builder:- Separates object construction from its representation Factory Method

SQL

                                                               SQL Short notes:- 1.get Today Records:  TO_CHAR(CREATE_STP, 'MM-DD-YYYY')=TO_CHAR(SYSDATE, 'MM-DD-YYYY') 2.Get UUDID: select sys_guid() from dual; 3.UUID to string : UPPER(REPLACE('5379efd7-cc4b-6fda-e053-2c97f4a10fdb','-')); 1.Second highest salary emp records select * from emp where sal=(select max(sal) from emp where sal<(select max(sal) from emp)) 2.Nth highest salary? 3.HAVING clause :- https://www.techonthenet.com/oracle/having.php SELECT exp1, exp2, ... expression_n, aggregate_function (aggregate_expression) FROM tables [WHERE conditions] GROUP BY expr1, exp2, ... expression_n HAVING having_condition; Ex:- SELECT department, SUM(sales) AS "Total sales" FROM order_details GROUP BY department HAVING SUM(sales) > 25000; 4.Optimize queries based on the query optimization guidelines Follow the SQL best practices to ensure query optimization: 1. Index

For Loop Performance Test

import java.util.ArrayList; import java.util.Calendar; import java.util.List; public class ForLoopPerformanceTest{     private static List<Integer> list = new ArrayList<Integer>();     private static long          startTime;     public static void main(String[] args) {         for (int i = 0; i < 10000000; i++) {             list.add(i);         }         // Java 8 for each         startTime = Calendar.getInstance().getTimeInMillis();         list.forEach(e -> {  });         System.out  .println("Using java 8 for each :: " +         (Calendar.getInstance().getTimeInMillis() - startTime) + " ms");         // Type 1         startTime = Calendar.getInstance().getTimeInMillis();         for (Integer i : list) {      //   }         System.out.println("Using For each loop :: " +        (Calendar.getInstance().getTimeInMillis() - startTime) + " ms");         // Type 2         startTime = Calendar.getInstance().

Spring Boot

Spring Boot: Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can "just run".  We take an opinionated view of the Spring platform and third-party libraries so you can get started with minimum fuss.  Most Spring Boot applications need very little Spring configuration. Features:- Create stand-alone Spring applications Embed Tomcat, Jetty or Undertow directly (no need to deploy WAR files) Provide opinionated 'starter' POMs to simplify your Maven configuration Automatically configure Spring whenever possible Provide production-ready features such as metrics, health checks and externalized configuration Absolutely no code generation and no requirement for XML configuration Advantages of using Spring Boot:- It is very easy to develop Spring Based applications with Java It avoids writing lots of boilerplate Code, Annotations and XML Configuration. It reduces lots

Core Java Notes

Image
About the Java Technology Java technology is both a programming language and a platform. The Java Programming Language The Java programming language is a high-level language that can be characterized by all of the following buzzwords: Simple Object oriented Distributed Multithreaded Dynamic Architecture neutral Portable High performance Robust Secure The Java Platform The Java platform has two components: The  Java Virtual Machine The  Java Application Programming Interface  (API) How Will Java Technology Change My Life? Get started quickly : Write less code :  Write better code :  Develop programs more quickly :  Avoid platform dependencies :  Write once, run anywhere : Distribute software more easily : Object Any entity that has state and behavior is known as an object. Class It is a logical entity. Polymorphism When  one task is performed by different ways Abstraction Hiding internal details and sho

Spring Notes

Bean id vs name: >Only 1 id, but Many names Special characters like #, @, $, *, /, and more are not allowed in the id attribute.  If you add one of these special characters to the id, you get an XmlBeanDefinitionStoreException thrown when the configuration is read by the container Ex: < bean id ="foo" name = "myFoo,kingBean,notBar" class ="com.intertech.Foo"/> >Names Still Must Uniquely Identify when the id of a bean matches the name of another bean, an BeanDefinitionParsingException Ref: https://www.intertech.com/Blog/clarifying-spring-framework-ids-and-names/ Autowiring: ~@Qualifier : https://www.mkyong.com/spring/spring-autowiring-qualifier-example/

Restful

>ignore Json property : @JsonIgnore @JsonIgnore public Integer getSal(){ return sal;}

convert file to string

public static String readFile(String filePath){ BufferedReader br = null; FileReader fr = null; StringBuilder sb = new StringBuilder(); try { fr = new FileReader(filePath); br = new BufferedReader(fr); String sCurrentLine; br = new BufferedReader(new FileReader(filePath)); while ((sCurrentLine = br.readLine()) != null) { sb.append(sCurrentLine); } } catch (IOException e) { e.printStackTrace(); } finally { try { if (br != null) br.close(); if (fr != null) fr.close(); } catch (IOException ex) { ex.printStackTrace(); } } return sb.toString(); }