Monday, 17 December 2018

JAVA ArrayList Constructors

JAVA ArrayList Constructors


public class ArrayList
extends AbstractList
1.    ArrayList() : Create an empty ArrayList object with default initial capacity 10. Once ArrayList reaches its max capacity then new ArrayList will be created with a new capacity.
new capacity=(current capacity*3/2)+1
i.e (10*3/2)+1=16 
after this new ArrayList is created the previous one will be deleted and it will be treated as garbage.

2.    ArrayList(int initialcapacity) : Constructs an empty ArrayList with the specified initial capacity given by the user.
3.    ArrayList(Collection c) : For every Collection object, we can create an equivalent ArrayList.
    public static void main(String[] args)
            ArrayList al=new ArrayList();
            System.out.println(al);          //[Sashi,Satyajit,20,null]
           System.out.println(al);           //[Sashi,Sasmita,20,null,Nilan]

Thanks & Regards:
Trilochan Tarai
SILAN Technology

Wednesday, 7 November 2018

Difference between JAVA Collection & Collections

Collection is a root level interface of the Java Collection Framework. Most of the classes in Java Collection Framework implements from this interface. List, Set and Queue are main sub interfaces of this interface. JDK doesn’t provide any direct implementations of this interface. But, JDK provides direct implementations of it’s sub interfaces. ArrayList, Vector, HashSet, LinkedHashSet, PriorityQueue are some indirect implementations of Collection interface. Map interface, which is also a part of java collection framework, doesn’t inherit from Collection interface. Collection interface is a member of java.util package.
Collections is an utility class in java.util package. It consists of only static methods which are used to operate on objects of type Collection. For example, it has the method to find the maximum element in a collection, it has the method to sort the collection, it has the method to search for a particular element in a collection. Below is the list of some important methods of Collections class.

Thanks & Regards:
Trilochan Tarai

Thursday, 11 October 2018

JAVA 11 Features

Some JAVA 11 Features

1. Nest-Based Access Control
2. Dynamic Class-File Constants
3. Epsilon: A No-Op Garbage Collector
4. Remove the JAVA EE and CORBA Modules
5. HTTP Client(Standard)
6. Local-Variable Syntax for Lambda Parameters
7. Unicode 10
8. Flight Recorder

Thanks & Regards:
Trilochan Tarai
SILAN Technology &

Tuesday, 21 August 2018

Why JAVA is Object-Oriented ???

Why JAVA is OO(Object-Oriented) ??

A Java Program is nothing but a class or more than one class. Everything we will write inside a class. That concept is Object Oriented.

Another fact is Object Oriented Features are supporting like Class, Object, Data Abstraction & Encapsulation, Inheritance, Polymerphism, Dynamic Binding, Message Passing etc.

Another important point is when a method is invoking by an object then the method definition is executing. This is object oriented concept, JAVA is supporting.

Thanks & Regards:
Trilochan Tarai
JAVA Expert
SILAN Technology &

What is JAVA ???

1. JAVA is a general purpose high level programming language.

2. JAVA is a technology.

3. JAVA is an OOP(Object Oriented Programming) Language.

4. JAVA is a platform.

Note : JAVA is itself  a platform because JAVA having its own JRE(JAVA Run-time Environment).

Thanks & Regards:
Trilochan Tarai
JAVA Expert
SILAN Technology &

Sunday, 12 August 2018

Why can't i use static variable in java constructor?

class Student{
Student() {
static int i = 0;
public static void main(String args[]){
Student s1 = new Student();
Student s2 = new Student();
Student s3 = new Student();

Here, Why can't i use static variable in java constructor?

If you want to declare static variable then declare it outside of the constructor, at class level like this -
public class Student{
private static int i;
You declaration of static occurred at your constructor which is a local variable and local variable can not be static. And that's why you are getting - illegal modifier for parameter i. And finally for initializing static variable you may use a static initialization block (though it's not mandatory) -
public class Student{
private static int i;
static {
i = 5;

Tuesday, 7 August 2018

JAVA 10 exciting Feature : Local Variable Type Inference

JAVA 10 :  Local Variable Type Inference
Like JavaScript, Kotlin, and Scala, now Java 10 introduced var keyword that allows you to declare a local variable without specifying its type. The type will be inferred from context. For example, when you say var name = "Silan", then the compiler will already know the type is String.
The var keyword can only be used for local variables, i.e. variables inside methods or code blocks — you cannot use it for member variable declaration inside the class body.
But like Python, it doesn't make Java a dynamically typed language. Java is still a statically typed language, and once the type is assigned, you cannot change it. For example, var name = "Silan" is ok, but if we will assign name =100; then it is not right.
This is one of the most eye-catching features of Java 10. It reduces the amount of boilerplate code needed to declare local variables in Java.
Overall we can say in a single statement that we can declare variables without specifying the associated type. A declaration such as:
List<String> l=new ArrayList<String>();
Can be written as var l=new ArrayList<String>();

Note: Type Inference is not a new Concept in JAVA but it is a new concept for local variables.