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 & java8s.com
trilochan@silantechnology.com
9439202111

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 & java8s.com
9439202111

Sunday 12 August 2018

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

Example:
class Student{
Student() {
static int i = 0;
System.out.println(i++); 
}
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?

Ans:
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.