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]);
}
}

}