Monday 4 July 2016

Add elements to an existing Array without creating new Array

Hi, Today I'm going to talk about Arrays class. Because this question is asked by few people in Interviews. As usual Array is indexed collection of  fixed nu number of elements. So, how can we add an element to an existing array? For this we go for Arrays class, which provides some utility methods for arrays. By using this class we can add element to array like below,

int[] intArray={1,2,3};
intArray = addElement(intArray, 4);
......
public int[] addElement(int[] existingArray, int element){
  existingArray= Arrays.copyOf(existingArray, existingArray.length +1);
  existingArray[existingArray.length - 1] = element;
}

Like above, Arrays class provides some other utilities also.

Tuesday 15 December 2015

Creating ANT build file for existing Project in Eclipse

Hi, So many people don't know how to create ANT build file for existing project. It is very simple to do that. Follow below steps,

Step 1:
Right click on project and click on Export option and select Export, one popup will be displayed.
Step 2:
In General, select Ant BuildFiles. Now a popup will be displayed, in that select the project for which you want to create the build file and click on finish.

Friday 18 September 2015

Change Web Application Context root in Eclipse/ MyEclipse

When ever we run our web project, our project name will be the default context root. For Example, if our project name is "Test" then the context root will be

 "http://localhost:8080/Test"

If you want to change this in MyEclipse,

1. Right click on the project and select properties from the list of options.
2. Select MyEclipse from the left side menu.
3. Select ‘Project Facets’ from the submenu, then select web option. 
4. On the right side you can find Web Context-root under Context Root tab having the default root context(ie., Test). Here you can change the context root.

If you want to change this in Eclipse,
1. Right click on the project and select properties from the list of options.
2. Select Web Project Settings from the left side menu.
3. In the right side you can find the Context root, which is showing the default project name as context root. Here you can change the context root.

Sunday 16 November 2014

Building WAR file using MAVEN

Hi, Today I'm going talk about how to build a WAR file using maven. To build a war using maven, follow below steps,
Step 1:
Download maven, and set it in Path like C:\apache-maven-3.1.1\bin; (installed location)

Step 2:
Create a system variable JAVA_HOME and set it with the location where jdk installed, if java installed on Program Files then C:\Progra~1\Java\jdk1.7.0_71;, or on Program Files(x86) then C:\Progra~2\Java\jdk1.7.0_71; (because it won't take spaces in the directory name).

Step 3:
Open command prompt, and go to your web application location,(where you find pom.xml), then run below command,
mvn package

After that go to your web application folder open target folder inside it there you can find the created war file.

Thanks.. 

Difference between CLASSPATH and PATH

So many people are getting confused of Classpath and Path. But it is very simple to understand. A Classpath describes where the required .class files are located. And Path describes where there the required binary executables are located.

For example if we want compile/run any java program we have to set like, C:\Program Files\Java\jdk1.7.0_71\bin in the Path. Because the required executables are available under bin directory.

Wednesday 12 November 2014

Best Connection pooling Technique: HikariCP

We have different connection pooling techniques among them HikariCP performance is well when compared to others. Because of the following,


  • Test connections at getConnection()
  • Closes abandoned Statements at Connection.close()
  • Executes a rollback() when Connections returned to the pool
  • Clears SQL warnings before returning a Connection to a client
  • Resets connection state
  • Traps and examines SQLException objects for disconnection errors

for more information regarding this you can refer here

Tuesday 11 November 2014

A Class can't implement multiple Interfaces

Every one knows that a java class can implement multiple interfaces, but there is a case where it is not possible to implement multiple interfaces. For example take two interfaces TestA and TestB having same method but different return types like,

interface TestA{

void m1();

}


interface TestB{

int m1();

}

Then it is not possible to create a class implementing these two interfaces, because a class can't allow two methods with same signature but different return types.

Thanks..