Saturday, November 11, 2017

Spring JDBC - Connect Spring application to database using JNDI (Mysql)

JNDI now a day is very popular as it provide the underline database connectivity directly to the application which providing any driver and connection string and all , everything has to be defined at application server level only the JNDI name is what matters to the spring application , it basically connect with database only by using the JNDI Name .

So how to connect with database using jndi



In this program we are trying to connect our spring application with Mysql database using Mysql JNDI which we are defining in tomcat server of the application.

Below is the tag we need to add in the tomcat context.xml.

<Resource name="jdbc/springlearning" auth="Container" type="javax.sql.DataSource"
               maxActive="100" maxIdle="30" maxWait="10000"
               username="root" password="root" driverClassName="com.mysql.jdbc.Driver"
               url="jdbc:mysql://localhost:3306/springlearning?useSSL=false"/>


below is the program

The structure of the project will be like below








Hope this will help you in understanding the program

Thanks for the reading
Noeik

Friday, November 10, 2017

Program to remove correspond duplicate character and reverse the string

Reversing the string is quiet simple in java but to remove the duplicate character in string without using and inbuild function or utility we need to do some brain storming.

There are 2 ways we can solve the problem.
1) Using Build in functions and solve the problem (Ex. Use HashSet to Remove Duplicate and Use StringBuilder to reverse the String)

2) To Use the Core logic without using any inbuild functions , here we need to use some thinking.

Below is the problem without using any in build function or utility.


So

Input - aabbcc
Output should be  - abc
Input - abbcaa
Output - abca





The Time Complexity will be - O(n) 

There is a simple way as well where we will only use String Buffer / String Builder and call .reverse() function of it.


If you have any problem in understanding the program , Please leave us a commet , will have to help.


Thanks for reading
Noeik

Tuesday, November 7, 2017

Spring MVC - Program for Implementing Dispatcher Servlet and Web.xml using Java annotation configuration

Spring as we all know is very popular because of its MVC framework. So we have 2 ways to Implement the Spring MVC using dispatcher servlet by Xml or can be configure by Java Annotation.

Below is the Program of Implementing the Java Annotation for Dispatcher Servlet and Web.xml for Spring MVC.



The Project will be Dynamic Web Program (Maven Project) and the structure will be like below

The Program will be like below








Thanks for reading , If you have any issue in program , let us know by leave a comment , Happy to help you

Noeik

Monday, November 6, 2017

Spring JDBC - Program to connect Database using jdbcTemplate

Spring jdbc is very important as all the enterprise level application always use database and Spring JDBC comes in picture when we connect database with java application using spring framework.


Below  program we are using the spring jdbcTemplate along with Java.

The structure of the project would be like below


Database we are using is MYSQL.


Below is the Program




Above is the schema and the query of the schema is as below

CREATE TABLE `Organization` (
  `id` int(11) NOT NULL,
  `slogan` varchar(45) DEFAULT NULL,
  `totalEmployee` int(11) DEFAULT NULL,
  `yearOfIncorporation` int(11) DEFAULT NULL,
  `name` varchar(45) DEFAULT NULL,
  `address` varchar(45) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;


You can download the full program from my git hub CLICK HERE


Hope this will help you in understanding the Coding part . If you face any issue please leave us a comment , Happy to help you :)


Thanks for reading
Noeik



Saturday, November 4, 2017

Program to get all the substring of the string in java

Hey all , this is queit popular interview question to write the program to find all the substring of the string in java

In my earlier post I have talked about Tower of Hanoi problem 
You can also see other Sorting program
Bubble Sort 
Selection Sort
Insertion Sort 

Here is my program

PROGRAM OF INSERTION SORT IN JAVA





The Time Complexity of the Program is - O(nlogn)


Output of the program

n
no
noe
noei
noeik
o
oe
oei
oeik
e
ei
eik
i
ik

k






Program of Random Function baised with 50% for 0 and 1 and 75% for 1 and 25% for 0 in java

Hey guys , Today one of my friend asked me a question regarding the function which will return the baised probability of 75% of 1 I thought lets share the answer with you guys as well

So below is my solution of the problem and my approach.


Approach 

  • First will write one function which will return 50% probability of getting 0 and 1
  • After that will create one function which call 50% function of 2 times.
  • Will return the OR of the the response.


Below is the program 

Thanks for reading
Noeik

Tuesday, October 31, 2017

Spring - Inversion of Control (IOC ) Programming Example with Spring xml

Spring , one of the most popular DI (Dependency Injection) framework used in Enterprise now. There are so many feature of spring because of which it is using so much in market right now but the most important and the core feature is IOC i.e Inversion of Control.

So What is Inversion Of Control (important Point for Interview as well ) - So basically IOC is as words suggest the responsibility of Creating and Maitaining the lifecycle of Object is of Spring Container only , We as Developer don't need to maintain the lifecycle of Object (in spring its called as bean).

So let see the Example of IOC in Spring-

1)Create the Java maven project in eclipse.
2) If you have created simple java project using maven , it will have below structure.
3) As per my Project you can create one package (as in my com.vp.spring)
and see the below code




4) By Watching above program you can see all the Code.

If you want to understand about IOC in depth , Read from Official Documents

Download full Project from here   



If you have any problem , leave me a comment will help you in understand.


Thanks for reading
Noeik

Sunday, September 10, 2017

Apache ActiveMQ "Message Queue" and its implementation using java

Hello Guys , Hope you all are doing good , Today we will learn more about activemq so lets get start.

What is ActiveMQ ?
Apache ActiveMQ ™ is the most popular and powerful open source messaging and Integration Patterns server.

Apache ActiveMQ is fast, supports many Cross Language Clients and Protocols, comes with easy to use Enterprise Integration Patterns and many advanced features while fully supporting JMS 1.1 and J2EE 1.4. Apache ActiveMQ is released under the Apache 2.0 License

It provide message queue which we can use to publish our message and can create subscriber to get the data from message topic

What is the use of Active MQ ?
Active MQ  where "MQ" stands for message queue  is widely used for the distributed systems where we want one system should not wait for the other system to complete it task , so what basically we do , we provide active mq where one (System A) complete it task put the data in message queue and starts working on other task , (System B ) will get the data stored in message queue by System A and will starts its working on that also , there is a Data delivery Guarantee also a key feature.

So lets see the implementation of Active MQ using java

Download the ActiveMQ Server from here : DOWNLOAD NOW

Maven Dependency

<dependency>
    <groupId>org.apache.activemq</groupId>
    <artifactId>activemq-core</artifactId>
    <version>5.7.0</version>
</dependency>

<dependency>
    <groupId>com.thoughtworks.xstream</groupId>
    <artifactId>xstream</artifactId>
    <version>1.4.10</version>
</dependency>

<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpclient</artifactId>
    <version>4.5.3</version>
</dependency>




Consumer Code
Producer Code

Main Class

The Full Source Code you can download from my git respository : DOWNLOAD FULL SOURCE

If you have any issue regarding the program execution , leave me a comment , Will try our best to resolve the program

Thanks for reading
-Noeik


Sunday, July 23, 2017

Program of Linked List Insertion and Deletion Operations in java

Linkedlist as we all know is one of the most important topic of interview especially for coding round.

We will not talk more about the theoretical part of linked list

Program for the insertion and deletion operation of linkedlist.


In my earlier post I have talked about Tower of Hanoi problem 
You can also see other Sorting program
Bubble Sort 
Selection Sort
Insertion Sort 

Main Class File




Hope this will help you in understand the program , Let me knowif you guys facing any problem in understanding this .


Thanks for reading.
-Noeik

Monday, July 3, 2017

Hibernate Mapping - OneToOne Relationship

Hello friend , Knowing one to one relation is very easy to understand for the interview aspirant , but to implement the knowledge into programming is the key which makes one a good programmer.

Today we will learn more about hibernate mapping -One to one

Breif- There are FOUR relationship mapping between object (tables)

  • ONE TO ONE
    • Unidirectional 
    • bidirectional
  • ONE TO MANY
    • Unidirectional 
    • bidirectional
  • MANY TO ONE
    • Unidirectional 
    • bidirectional
  • MANY TO MANY 
    • Unidirectional 
    • bidirectional

One to One mapping- In One to One mapping one object (row of a table ) is associated only with one another object(row of a table)

Ex - A user have only one System Credential.

When we say Uni directional - it means we dont have target to source mapping , we only have source to target mapping.
But in bidirectional we will have source to target to and fro mapping.

In Today's post we will see the ONE TO ONE UNIDIRECTION PROGRAM-

The Project Structure should be like below













SQL Scripts
CREATE TABLE `finances_user` (
  `USER_ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `FIRST_NAME` varchar(45) NOT NULL,
  `LAST_NAME` varchar(45) NOT NULL,
  `BIRTH_DATE` date NOT NULL,
  `EMAIL_ADDRESS` varchar(100) NOT NULL,
  `LAST_UPDATED_BY` varchar(45) NOT NULL,
  `LAST_UPDATED_DATE` datetime NOT NULL,
  `CREATED_BY` varchar(45) NOT NULL,
  `CREATED_DATE` datetime NOT NULL,
  `USER_ADDRESS_LINE_1` varchar(100) DEFAULT NULL,
  `USER_ADDRESS_LINE_2` varchar(100) DEFAULT NULL,
  `CITY` varchar(100) DEFAULT NULL,
  `STATE` varchar(2) DEFAULT NULL,
  `ZIP_CODE` varchar(5) DEFAULT NULL,
  PRIMARY KEY (`USER_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;


CREATE TABLE `credential` (
  `CREDENTIAL_ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `USER_ID` bigint(20) NOT NULL,
  `USERNAME` varchar(50) NOT NULL,
  `PASSWORD` varchar(100) NOT NULL,
  PRIMARY KEY (`CREDENTIAL_ID`),
  UNIQUE KEY `USER_ID_UNIQUE` (`USER_ID`),
  CONSTRAINT `FINANCES_USER_FK` FOREIGN KEY (`USER_ID`) REFERENCES `finances_user` (`USER_ID`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;


DOWNLOAD - SOURCE CODE (if deleted let us know)

Let us know if you dont understand anything in this post .

Thanks for reading 
-Noeik