Friday, November 17, 2017

JUnit Tests Basics and how to do unit testing in java





Junit is one of the most popular unit testing framework for java developer Junit has been important in Test driven Implementation.

Below are the Annotation which are available in Junit 4

@Test Identifies a method as a test method
@Before Executed before each test. It is used to prepare the test environment (e.g read input data , initialize the class)
@After Executed after each test. It is used to cleanup the test environment.It can also save menory by cleaning up expensive memory structures.
@BeforeClass Executed once, before the start of all the tests. Methods marked with this annotation need to be definedas static to work with Junit.
@AfterClass Executed once after all the tests have been finished. Methods annotated with this annotation need to be defined static to work with Junit.
@Ignore Marks that the test should be disabled.
@Test(expected =Exception.class) Fails if the method does throw the named exception.
@Test(timeout =10) Fails if the method takes longer than 100 milliseconds.


Below is the Program where we are using the JUnit testing Basics








Thanks for reading
Noeik

Thursday, November 16, 2017

Java Interview : Heap Sort Implementation using Array

Heap Sort is not that much popular in the sorting mechanism but the heap sort is the one which actually help you in most of the complex problem solution. as it is one of the most efficient sorting algorithm.


Lets see the java program of implementing heap sort using Array.




Time Complexity of the program is O(nlog(n))



I hope this will help you in understand the heap sort , Please let me know if you have any issue or leave us a comment.


Thanks for reading
Noeik


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