Java this keyword.

this: is called as reference variable because it always refer an current object.

Eg:
Is this valid ?
public class MleClass{
int value=10;
 void show(){
 System.out.println(value);
 }

 public static void main(){
  MleClass obj =new MleClass();
  ob.show();
 }
}

Obj is local variable i.e we can't access that variable outside main method.

In above code snippet value is a instance variable.

So we must need  an object or object or object reference to access value;

Then still valid the above snippet ?

Java execution priority

Whenever JVM loads the class, it will execute in specific order.

  1. Class variable.
  2. Static blocks
  3. public static void main(String args[])

In the above order JVM execute the program.
First it will looks for Class variables.|

static int value =90;
static String helloString ="Hello";

Then static blocksThis blocks will execute top to bottom.

static{
 System.out.println("Static block-1");
}
static{
 System.out.println("Static block-2");
}

Finally, main method will execute.

So far so good!
Then can we execute java program with out main method?

Types of java variables

Java variables are very straightforward, just they are variables.

Yes, just they are variable but we have to understand when the memory allocated and how can we access those.

I have seen some people who can write the code without knowing all this.

Seriously!, is that possible ?

Rules for Java source file.

#Rule-1

A source file can have only one public class.
              Why? - If we give public for multiple classes in single java file , It is ambiguous for JVM.
           It is ambiguous ?
      Then what exactly JVM doing with Public class ?

    Do you know what are the Interface hidden rules ?

    Interface:
    Just simple definition  is collection of public static final variable and public abstract  methods.

    Let me write one example:

    interface A{
     int a= 10;
     void show();
     }
    

    Is this example telling you what exactly I give  in the definition ?

    Do you know what is method hiding ?

    Method hiding is possible with static method.

    Let's see example:

    class A{
     static void show(){
       System.out.println("From A class");
       }
      }
      public class B extends A{
      static void show(){
       System.out.println("From B class");
       }
       public static void main(String []args){
            A a =new HelloWorld();
            B b =new B();
            a.show(); // A class show method will call
            b.show(); // B class show method will call
          }
     }
    
    

    Important rules for Overriding

    What is overriding ?
    Just simple definition is "Two or more methods with the same name and same parameter list then it said to be Method overriding" .
    Eg-1:

    class A{
      void show(){
       System.out.println("Overridden method");
       }
      }
      public class B extends A{
      void show(){
       System.out.println("Overriding method");
       }
      }
    

    [Java]How can we check java class profile ?

    Yes, we can quickly check Java Class profile with our terminal.
    On daily basis development it is easy to check class profile like what are the methods and constructors are declared/implemented inside a class.

    Let's check:

    Open your terminal(ctrl+alt+t) if it is Ubuntu machine.

    [Java] If we print the object reference what will be the output ?


    Initially, when I'm trying to learn JAVA concepts quiet confusing for me.
    If I print MyClass object reference it will print the hashcode with prefix "@".

          - Yes, It's fair enough!. 


                 MyClass objectRef  = new MyClass(); 
                           System.out.println(objectRef); 

    Output: @[hashcode]

    But when I print the String or Collection object reference it's printing the string content and collection Object elements respectively.
       - Isn't it confusing ?

    [wordpress]How to install plugins and themes in local wordpress solution?

    Installing the wordpress in local machine and hosting on webserver is quiet easy right?
     - Yes, we have so many tools in the Internet.

    Then why you need this post?



    Sometimes we do mistakes while installing the plugins and no idea what/where  we did wrong.


    This is my experience while installing the wordpress plugins and themes in Ubuntu 16.04.

    [Java]What is the Object and Object reference ?


    • In Java, all objects are accessed by reference, and you never have direct access to the object itself.
    • Reference :- is a variable that has a name and can be used to access the contents of an object, A reference can be assigned to another reference passed to a method, or returned from a method.

      default value of object reference is  "null";


                   MyClass object ; 
    • Object:- is an entity that's exists in memory allocated by the Java run time environment, An object sits on the heap memory when we create an object like

    Can we call static members of class directly ?


       - Yes if it is same Class member.

    If Class has static/class member(Static member also known as class members) we can access in following ways:

    1. Directly
           If your trying to access static member with in same class you can call it off with out any reference.

    2. With Class name
         If static member is not present in same class  We must access with with Class name
    3. With Object or Object reference

    [JAVA] How "System.out.println()" works?

    Here your going to understand how SOP() works.  
    For understanding this we need to recall few basics of Java:

    • dot (.) operator in Java: In Java . (dot operator) is used only to call methods or variables. So we can say out is either method or variable.
    • Methods in Java : we know methods always have parenthesis ‘( )’ after method name, So out cannot be a method in Java. So out its a variable and println() is a method.
    • Class name in Java: Class name should start with Capital letter ideally in Java, So System is a class.
    Now with basic knowledge of Java we know :

    • System is a Class
    • out is a Variable
    • println() is a method
    Lets get more in details:
    out variable: static or instance?