Thursday, September 27, 2018

Different between Array and ArrayList

      Array                                                                                     ArrayList

01. Define as String names[] = new String[4];                            List<String> names = new                                                                                                                                                   ArrayList<String>();

02. Size is static                                                                           Size is Dynamic

03. Java functionality representer                                                Part of collection class

04. 

Friday, August 17, 2018

How to use enum in java

package com.javasampleapproach.angularjpamysql.controller;

public enum EnumTest {

    CODE01("01"),
    CODE02("02"),
    CODE03("03"),
    CODE04("04"),
    CODE01DESC("Retail Customer"),
    CODE02DESC("Retail Customer"),
    CODE03DESC("Retail Customer"),
    CODE04DESC("Retail Customer");

    private final String description;

    private EnumTest(String description) {
        this.description = description;
    }

    @Override    public String toString() {
        return description;
    }
}


package com.javasampleapproach.angularjpamysql.controller;

public class EnumCaller {
    public static void main(String args[]){
        System.out.println(EnumTest.CODE01);
        System.out.println(EnumTest.CODE01DESC);
    }
}

Output

01
Retail Customer

Thursday, August 16, 2018

SSL - Secure Socket Layer

01. HTTPS - Hypertext Transfer Protocol for Secure
02. SSL      - Secure Socket Layer




02. SSL - Secure Socket Layer

      In this case, they use public and private key theory (Something uses public key cryptography).
      The server has private key and website has a public key.
      A public key is known to your server and available in the public domain. It can be used to encrypt any message. Someone send a message to the server through this website then the website can encrypt the message. The server can decrypt the message using the private key. 

More Info - globalsign.com

Sunday, August 5, 2018

Spring JPA + MySQL + AngularJS example | Spring Boot

https://grokonez.com/spring-framework/spring-mvc/spring-jpa-mysql-angularjs-example-spring-boot#comment-8740

Tuesday, July 17, 2018

Is String Immutable


Immutable simply mean unchangeable or unmodifiable. Once string object is created its data or state can't be changed
Consider bellow example,
class Testimmutablestring{  
  public static void main(String args[]){  
    String s="Future";  
    s.concat(" World");//concat() method appends the string at the end  
    System.out.println(s);//will print Future because strings are immutable objects  
  }  
 }  
Let's get idea considering bellow diagram,
enter image description here
In this diagram, you can see new object created as "Future World". But not change "Future".Because String is immutables, still refer to "Future". If you need to call "Future World",
String s="Future";  
s=s.concat(" World");  
System.out.println(s);//print Future World
Why are string objects immutable in java?
Because Java uses the concept of string literal. Suppose there are 5 reference variables, all refers to one object "Future".If one reference variable changes the value of the object, it will be affected to all the reference variables. That is why string objects are immutable in java.

Friday, July 6, 2018

diiffrent between set and list

https://beginnersbook.com/2014/07/difference-between-list-and-set-in-java/

What is the Cross-Site Request Forgery (CSRF) Attack

Cross-Site Request Forgery (CSRF)

Cross-Site Request Forgery is an attack that forces an end user to execute the unwanted action in the web application which there currently authenticated. (more CSRF)

Must watch
Ex -:http://www.baeldung.com/spring-security-csrf

And
https://stackoverflow.com/questions/5207160/what-is-a-csrf-token-what-is-its-importance-and-how-does-it-work

1
2
3
4
5
<form action="http://bank.com/transfer" method="POST">
    <input type="hidden" name="accountNo" value="5678"/>
    <input type="hidden" name="amount" value="1000"/>
    <input type="submit" value="Show Kittens Pictures"/>
</form>


Tuesday, June 5, 2018

String Basic

String to Int

String myString = "1234";
int foo = Integer.parseInt(myString);
Declare Arry

For primitive types:
int[] myIntArray = new int[3];
int[] myIntArray = {1,2,3};
int[] myIntArray = new int[]{1,2,3};
For classes, for example String, it's the same:
String[] myStringArray = new String[3];
String[] myStringArray = {"a","b","c"};
String[] myStringArray = new String[]{"a","b","c"};
The third way of initializing is useful when you declare the array first and then initialize it. The cast is necessary here.
String[] myStringArray;
myStringArray = new String[]{"a","b","c"};
For-each

for (char ch: "xyz".toCharArray()) {
}
List
List<String> someList = new ArrayList<String>();
Get String character by index

String text = "foo";
char a_char = text.charAt(0);
System.out.println(a_char); // Prints f
Character to String

Character.toString("C")