Sunday, February 3, 2019

How to convert String.class to Class ?

Class<?> classes = String.class;
System.out.println("Classes.getName() is " + classes.getName());
System.out.println("Classes.getSimpleName() " + classes.getSimpleName());
System.out.println("Classes.toGenericString " + classes.toGenericString());

Answer :
-----------

Classes.getName() is java.lang.String
Classes.getSimpleName() String
Classes.toGenericString public final class java.lang.String



Saturday, February 2, 2019

What does > symbol mean in html ?

<body>
What is this ?: {{>status}}
</body>

Answer :
-----------
> symbol means to open the folder, say if it is inside the template folder then open the template folder and if it is status then it means open the status.html page inside the template folder

Exception in thread "main" java.lang.IllegalStateException

When you have input like this below

ApplicationContext applicationContext = new ClassPathXmlApplicationContext();

you get output like

Exception in thread "main" java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext

Hence you have to define the bean in the ClassPathXmlApplicationContext("SpringBeans.xml");

Thursday, January 31, 2019

list methods example

package com.concretepage;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;

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

LinkedList<String> list = new LinkedList<String>();
list.add("A");
list.add("B");

list.addFirst("D");
list.add(2,"E");
list.addLast("C");
list.add("F");
list.add("G");

System.out.println("Linked List " + list);
System.out.println(list.size());
String returns = list.get(2);
System.out.println(returns);

Collection<String> ref = new ArrayList<String>();
ref.add("H");
ref.add("I");
ref.add("J");
ref.add("K");
ref.add("L");
list.addAll(1,ref);
System.out.println(list);
}
}

Collections.addAll example

package com.concretepage;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

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

List<String> list = new ArrayList();
list.add("A");
list.add("B");
list.add("C");
list.add("D");
list.add("E");
list.add("F");
boolean b = Collections.addAll(list, "1", "2", "3");
System.out.println(b);
System.out.println("arrayList after Operation " + list);

}
}

Collectors.toList() example

package com.concretepage;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Stack;
import java.util.stream.Collector;
import java.util.stream.Collectors;

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

String a[] = new String[] {"A", "B", "C", "D", "E", "F", "G", "H", "B", "C"};
List<String> ref = Arrays.asList(a);
System.out.println(ref);

       // input list with duplicates
        List<Integer> list = new ArrayList<>(
            Arrays.asList(1, 10, 1, 2, 2, 3, 10, 3, 3, 4, 5, 5));
            // Print the Arraylist
        System.out.println("ArrayList with duplicates: "
                           + list);
 
        // Construct a new list from the set constucted from elements
        // of the original list
        List<Object> newList = list.stream().distinct().collect(Collectors.toList());
        // Print the ArrayList with duplicates removed
        System.out.println("ArrayList with duplicates removed: " + newList);
       
        System.out.println();System.out.println();System.out.println();
        Stack<String> reference = new Stack<>();
        reference.push("A");
        reference.push("B");
        reference.push("C");
        reference.push("D");
        reference.push("E");
       
        System.out.println("The elements at the top of stack is 1 " + reference.pop());
        System.out.println("The elements at the top of stack is 2 " + reference.peek());
        System.out.println("The elements at the top of stack is 3 " + reference.peek());
        System.out.println("The elements at the top of stack is 4 " + reference);

}
}

arraylist indexOf, lastIndexOf example

package com.concretepage;

import java.util.ArrayList;

public class TestOneFour {
public static void main(String[] args) {
    ArrayList<Object> ref = new ArrayList<>();
    ref.add(1);ref.add(2);ref.add("Three");ref.add(4);ref.add(5);
    ref.add(6);ref.add("Seven");ref.add("Three");ref.add("Three");ref.add(8);ref.add(9);
    System.out.println(ref.indexOf("Three"));
    System.out.println(ref.lastIndexOf("Three"));
    System.out.println(ref.indexOf("Seven"));
}
}