Posts

Multi Threading

Image
What is Thread Group ? Based on functionality we can group thread into a single unit ,which is nothing but Thread Group i.e. Thread Group contains group of thread. In addition to Thread ,Thread Group can also contain sub-thread group. The main advantage of maintaining thread in the form thread group is ,we can perform common operation very easily. Code: What is yield() method ? Theoretically, to ‘yield’ means to let go, to give up, to surrender.  The  yield()  method of thread class causes the currently executing thread object to temporarily pause and allow other threads to execute.  Note that  it’s only a hint , though, and not guaranteed to have any effect at all. This method is persent in java.lang.Thread class in java. Syntax   :- public static native void yield()  Some platform wouldn't support for yield() method. The purpose of yield() method causes to pass current executing thread to give the chance for the remaining waiting thread of same...

product management crud test

application.properties server.port=8051 spring.datasource.url=jdbc:h2:file:~/test spring.datasource.driverClassName=org.h2.Driver spring.datasource.username=sa spring.datasource.password= spring.jpa.database-platform=org.hibernate.dialect.H2Dialect # Enabling H2 Console spring.h2.console.enabled=true # Custom H2 Console URL spring.h2.console.path=/h2-console # create database schema from SQL files spring.jpa.hibernate.ddl-auto=create #Turn Statistics on and log SQL stmts spring.jpa.show-sql=true spring.jpa.properties.hibernate.format_sql=true spring.jpa.properties.hibernate.generate_statistics=false #logging.level.org.hibernate.type=trace #logging.level.org.hibernate.stat=debug logging.pattern.console=%d{yyyy-MM-dd HH:mm:ss} - %msg%n H2databaseApplication .java import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.ConfigurableApplicationContext; import co...

Serialization in java

Image
What is Serialization in Java ? The process of of writing state of an object to a file called Serialization. But strictly speaking, It is the process of converting object from java supported from into file file supported form or network supported form or network supported form. By using FileOutputstream or ObjectOutputStream we can achieve serialization. Deserialization :- The process of reading state of an object from from the file is called deserialization . But strictly speaking it is process of converting an object from either file supported form or network supported into java supported form. We can serialize  to be only serializable  object. An Object is said to be serializable if and only if the corresponding class implements Serializable interface. Serializable interface is present in the java.io package. It doesn't contain any method. Its a marker interface. If we try to serialize, non-serialized object  then it will throw NotSerialzableException . Tra...

Hibernate Tutorial

What is hibernate ? Hibernate is an ORM tool used for data transfer, between Java application and database, in the form of object. Hibernate is developed by Gavin King. Why not JDBC ? 1.  Code written in jdbc are database dependent. 2.  Does not have cache support. 3.  Data is not secured. Why Hibernate ? Hibernate provides following features : 1. Auto DDL support 2. Hibernate query language support(Database independent  query) 3. Cache support 4. Primary key generator 5. Validations support 6. Exception Free(There is no compile time exception) 7. ORM support State of objects during CRUD operation If we are doing CRUD operation (e.g. Create, Insert, Update, Delete) then we have to pass object. There are three types of object in Hibernate.               1. Transient object               2. Persistent object               3. Detached object What is Cascade...

Pattern based programs in java

Write a program to print a  right angle triangle using single loop . package com.myconceptonjava.practice; public class PrintRightAngleTriangle {     public static void main(String[] args) {         int j=0;         for(int i=1; i<5 ;){                     if(j<i){                 System.out.printf(++j +" ");                 continue;             }             else {             System.out.println();             j=0;                 i++;       ...

RESTful Web Service Interview Question

1. What REST stands for? Ans:- REST stands for REpresentational State Transfer. 2. What is REST? Ans:-REST is web standards based architecture and uses HTTP Protocol for data communication. It revolves around resource where every component is a resource and a resource is accessed by a common interface using HTTP standard methods. REST was first introduced by Roy Fielding in 2000. In REST architecture, a REST Server simply provides access to resources and REST client accesses and presents the resources. Here each resource is identified by URIs/ global IDs. REST uses various representations to represent a resource like text, JSON and XML. Now a days JSON is the most popular format being used in web services. 3. Name some of the commonly used HTTP methods used in REST based architecture? Ans:- Following well known HTTP methods are commonly used in REST based architecture −     GET − Provides a read only access to a resource.     PUT − Used to create a ...

Core Java Programming Question from Collection

Program to find the frequency string in string array (Passing String from command line arguments) package com.myconceptsonjava.practice; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; public class Test {     public static void main(String[] args) {     Map<String, Integer> m = new HashMap<String, Integer>();     // Initialize frequency table from command line     for (String a : args) {     Integer freq = m.get(a);     m.put(a, (freq == null) ? 1 : freq + 1);     }     System.out.println(m); } } Program to find the frequency string in string array and print them in natural  sorting order (Passing String from command line arguments) package com.myconceptsonjava.practice; import java.util.ArrayList; import java.util.TreeMap; import java.util.List; import java.util.Map; public class Test {  ...