Monday, March 5, 2018

String to Date


String dojStr = "1971-07-15"; 
DateFormat df = new SimpleDateFormat( "yyyy-MM-dd" ); 
Date dojDate = null; 
dojDate = df.parse(dojStr);

VarArgs - Variable Argument

Can be add more method variable without initialize.

return_type  method_name(DataType... variableName){}


class A{
    public static void varArgsMethod(String... value){
       sysout("Hi");
   }
    psvm(){
       A.varArgsMethod("Welcome","Var","args"); //Can add zero or more argument
   }
}

Output - Hi

Rules

  • Only can be one Variable argument in method

             ex - public void run(String... walk, int... time){}; //Compile error


  • Variable Argument must be last

            ex - public void  walk(int x, int... y){}




Tuesday, February 27, 2018

What is different between static nested class and inner class(non-static class)

The main different is that,

Inner class requires - > Instantiation of outer class
static nested class    ->  Not Instantiation. Can directly access it.


Reference by -https://examples.javacodegeeks.com/java-basics/java-static-class-example/

static class  example

Wow Code-01

public class TestMain {

//Static class with static method
 public static class StaticNestedClass{
public static void staticNestedClass(){
System.out.println("StaticNestedClass");
}
}
 //Inner Class
public class InnerClass{
public void innerClass(){
System.out.println("Inner Class");
}
}

public static void main(String args[]){
//This is work because both class and method are static. Then we can directly call method
following bellow way
StaticNestedClass.staticNestedClass();
}

}

WOW CODE - 02

public class Application {
//There is two inner class call InnerClass And GO
public class InnerClass{
          public void innerClass(){
System.out.println("InnerClass");
}
public class GO{
public void go(){
System.out.println("go");
}
}
}

  //There is static class
public static class StaticClass{
public void staticClass(){
System.out.println("StaticClass");
}
}

//There is main method

public static void main(String[] args) {
 
   //If we need to call inner class
Application ap = new Application();

Application.InnerClass innerCls = ap.new InnerClass();
innerCls.innerClass();

//If we need to call inner inner class
Application.InnerClass.GO g = innerCls.new GO();
g.go();

//If we need to call static class
Application.StaticClass st = new StaticClass();
st.staticClass();
   
  //Or
  StaticClass st = new StaticClass();
st.staticClass();
  

}
}



Different between HashMap and HashTable in Java

Hash Table
Hash Table is synchronized;
There cannot be any null key or value


Hash Map

Map<Integer, String> testMap = new HashMap<Integer, String>();
Hash map not synchronized
There can be one null key and any null value
Has

Wednesday, February 21, 2018

Array and array List

https://www.geeksforgeeks.org/array-vs-arraylist-in-java/

SQL

ALIAS QUERY

Table User

ID  |  USER_ID  | USER_NAME | PHONE_NO | ADDRESS

Table Company

ID | COMPANY_NAME | USER_ID


Table alias
SELECT  ur.USER_ID , ur.USER_NAME , cm.COMAPANY_NAME FROM User AS ur , COMPANY as cm;

Column alias
SELECT USER_ID AS id ,USER_NAME AS name from m_agri_harvest .

--------------------------------------------------------------------------------------------------------------------------
UPPER AND LOWER

Select upper(USER_NAME) from User

Select lower(USER_NAME) from User


PRIMARY KEY VS UNIQUE KEY

Primary Key
   












Monday, February 19, 2018

Runtime and Complile time error

Compile time error - Check about the syntax
Run Time error       - Divide by zero like that.


I think of it in terms of errors, and when they can be caught.
Compile time:
string my_value = Console.ReadLine();
int i = my_value;
A string value can't be assigned a variable of type int, so the compiler knows for sure at compile time that this code has a problem
Runtime:
string my_value = Console.ReadLine();
int i = int.Parse(my_value);
Here the outcome depends on what string was returned by ReadLine(). Some values can be parsed to an int, others can't. This can only be determined at run time


Static Key work

The static keyword mainly use for memory management. It is a key word that are used for share the same variable or method of given class.
This is used for constant variable or method that is same for every instance of a class. In java ,if a field is declare static, then exactly a single copy of that  field is created and shared among all instances of that class.


If class has constant variable and method then we don't need to create that constant variable and method with every instance of class. That time we try to create one time that constant variable and method and refer those thing from all instance. starbuser with cripto

WOW
https://examples.javacodegeeks.com/java-basics/java-static-class-example/

Watch also another post.
What is different between static nested class and inner class(non-static class)

How to use Arrays.sort() in java

import java.util.Arrays;

public class ArrayEx {

public static void main(String args[]){

int[] myArray2 = new int[]{23,2,21,4,5};
Arrays.sort(myArray2);
for(int i =0;i<myArray2.length;i++){
System.out.println(myArray2[i]);
}


String[] names = new String[]{"Peter", "Patricia", "Hunter", "Sarah",
       "Gabe", "Gina", "Rob", "John", "Zoey", "Tammy", "Robert",
       "Sean", "Paschal", "Kathy", "Neleh", "Vecepia" };

Arrays.sort(names);

for(int a=0;a<names.length;a++){
System.out.println(names[a]);
}
}

}

Wednesday, November 29, 2017

JSF SpringMVC Hibernate Integration Example Tutoria with maven

According to spring MVC structure, we can create three layers in our project
  1. DAO Layer
  2. Service Layer
  3. Model Layer

This is Project structure

Firstly configure all XML file. It will help to continue your project without errors.

faces-config.xml

</plugins> </build> </project>


Step 03 - Create Controller class(SpringBootController.java)


package com.boraji.tutorial.springboot.controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class SpringBootController{ @RequestMapping("/") public String sayHello() { return "Hello Spring Boot!!"; } }



Tuesday, November 7, 2017

Spring Boot - Hello world example

This sample explains how to create spring boot hello world application

Tools and technologies used for this application are-

  • Spring Boot 1.5.4.RELEASE
  • JavaSE 
  • Maven
  • Eclipse Neon

Here is project Structure





















Step 01 - Create Maven project

File -> New -> Maven Project ->select Create a simple project ->Enter details and finish.

Step 02 - Add dependencies to pom.xml file

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.boraji.tutorial.springboot</groupId> <artifactId>spring-boot-hello-world-example</artifactId> <version>0.0.1-SNAPSHOT</version> <properties> <java.version>1.8</java.version> </properties> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.4.RELEASE</version> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>


Step 03 - Create Controller class(SpringBootController.java)

package com.boraji.tutorial.springboot.controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class SpringBootController{ @RequestMapping("/") public String sayHello() { return "Hello Spring Boot!!"; } }




Step 04 - Create Main Class(MainApplication.java)

package com.boraji.tutorial.springboot; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class MainApplication{ public static void main(String[] args) { SpringApplication.run(MainApplication.class, args); } }



Step 05 - Run Application

Right click on MainApplication.java - > Run As -> Java Application



















Step 06 - Get Output

Now, enter the http://localhost:8080 in browser's address bar and see the output


Monday, October 30, 2017

Garbage collection

Singleton in same package same class,


package com.singletone.test;


class SingletoneBorn{

private static SingletoneBorn instanse = new SingletoneBorn();

private SingletoneBorn(){}

public static SingletoneBorn getInstanse() {
return instanse;
}

public void showDetails(){
System.out.println("This is singletone born world");
}
}

public class SingletoneTest {

public static void main(String args[]){
SingletoneBorn sb = SingletoneBorn.getInstanse();
sb.showDetails();

}


}

Singleton same package different class


Singleton class

package com.singletone.test;

public class SingletoneTest {


private static SingletoneTest instanse = new SingletoneTest();

private SingletoneTest(){}

public static SingletoneTest getInstanse() {
return instanse;
}

public void showDetails(){
System.out.println("This is singletone born world");
}

}

Singleton usage class

package com.singletone.test;

public class TestSingletone {
public static void main(String args[]){

SingletoneTest st = SingletoneTest.getInstanse();
st.showDetails();
}


}

Singleton different package different class


Singleton class

package com.singletone.test;

public class SingletoneTest {


private static SingletoneTest instanse = new SingletoneTest();

private SingletoneTest(){}

public static SingletoneTest getInstanse() {
return instanse;
}

public void showDetails(){
System.out.println("This is singletone born world");
}

}

Singleton usage class

package com.singletone.test2;

import com.singletone.test.SingletoneTest;

public class SingleTest {

public static void main(String args[]){
SingletoneTest st = SingletoneTest.getInstanse();
System.out.println("Singletone method call in nother package");
st.showDetails();
}




}