Wednesday, 18 October 2017

Internal Details of JVM.

What is JVM:-
                          JVM (Java Virtual Machine) is an abstract machine. It is a specification that provides runtime environment in which java bytecode can be executed.


What is does:-
     
 The JVM performs following operation:
  • Loads code
  • Verifies code
  • Executes code
  • Provides runtime environment
JVM provides definitions for the:
  • Memory area
  • Class file format
  • Register set
  • Garbage-collected heap
  • Fatal error reporting etc.
Internal Architecture of JVM:-

   1) Classloader:-
    Classloader is a subsystem of JVM that is used to load class files.

   2) Class(Method) Area:-

    Class(Method) Area stores per-class structures such as the runtime constant pool, 
    field and method data, the code for methods.
   3) Heap

    It is the runtime data area in which objects are allocated.
   4) Stack

    Java Stack stores frames.It holds local variables and partial results, and plays 
    a part in method invocation and return.
    Each thread has a private JVM stack, created at the same time as thread.
    A new frame is created each time a method is invoked. A frame is destroyed when 
    its method invocation completes.

   5) Program Counter Register

    PC (program counter) register. It contains the address of the Java virtual machine 
    instruction currently being executed.

   6) Native Method Stack

    It contains all the native methods used in the application.
   7) Execution Engine
    It contains:
     1) A virtual processor
     2) Interpreter: Read bytecode stream then execute the instructions.
     3) Just-In-Time(JIT) compiler: It is used to improve the performance.JIT compiles 
        parts of the byte code that have similar functionality at the same time, and 
        hence reduces the amount of time needed for compilation.Here the term ?
        compiler? refers to a translator from the instruction set of a Java virtual 
        machine (JVM) to the instruction set of a specific CPU.


Tuesday, 17 October 2017

Variable in java

Variable in java:-
                      Variable is an identifier which holds data or another one variable is an identifier whose       value can be changed at the execution time of program. Variable is an identifier which can be used           to identify input data in a program.
       






Syntax :-
                   Variable_name =value;

Rules to declare a Variable:-

  • Every variable name should start with either alphabets or underscore ( _ ) or dollar ( $ ) symbol.
  • No space are allowed in the variable declarations.
  • Except underscore ( _ ) no special symbol are allowed in the middle of variable declaration
  • Variable name always should exist in the left hand side of assignment operators.
  • Maximum length of variable is 64 characters.
  • No keywords should access variable name.
Note: Actually a variable also can start with ¥,¢, or any other currency sign.
Example:-
class Sum
{
 public static void main(String[] args) 
  { 
   int _a, ¢b, ¥c, $d, result;
   _a=10;
   ¢b=20;
   ¥c=30;
   $d=40;   
   result=_a+¢b+¥c+$d; 
   System.out.println("Sum is :" +result);
  }
}

ListView Example in android

activity.xml file
         <?xml version="1.0" encoding="utf-8"?>
       <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"         
        android:orientation="vertical"         
        android:layout_width="match_parent"        
        android:layout_height="match_parent">

       <ListView          
         android:id="@+id/LVcustomlist"        
         android:layout_width="match_parent"       
         android:layout_height="match_parent">
       </ListView>

     </LinearLayout>

Mainactivity.java file
   
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class MainActivity extends AppCompatActivity {
    // Array of strings...    String[] mobileArray = {"Android","IPhone","WindowsMobile","Blackberry",
            "WebOS","Ubuntu","Windows7","Max OS X"};

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ArrayAdapter adapter = new ArrayAdapter<String>(this,
                R.layout.activity_listview, mobileArray);

        ListView listView = (ListView) findViewById(R.id.LVcustomlist);
        listView.setAdapter(adapter);
    }
}



output on mobile screen look like this..

Monday, 16 October 2017

Table print in java

import java.util.Scanner;
   
 public class Table {
        public static void main(String args[]){
        Scanner scb = new Scanner(System.in);
        int ab = scb.nextInt();
        for(int i=1; i<=10;i++){
            System.out.println(ab +"*"+i+"="+ab*i);
        }
    }
   
}

Friday, 13 October 2017

Array List Example

   ArrayList Some Important Point in java :-
   
       # Java Array-List class can contain duplicate elements.
      # Java Array-List class maintains insertion order Java. 
      # Array-List class is non synchronized.
      # Java Array-List allows random access because array works at the index basis.
      # In Java Array-List class, manipulation is slow because a lot of shifting needs to be occurred           if any element is removed from the array list.


   ArrayList Example....
                         
                       import java.util.*;  
                              
                               class Examplecolection{  

                                 public static void main(String args[]){   

                                  ArrayList<String> list=new ArrayList<String>(); 
                                 
                                  list.add("Raj");   
                                  list.add("Vinay");   
                                  list.add("Rai");   
                                  list.add("Jay");  
                                  
                                  for(String obj:list) 
                                System.out.println(obj); 
                                             }
                                 }  

Collection in java

                                   Collection in java

What is collection?
A Collection represents a group of objects known as its elements. The Collection interface is used to pass around collections of objects where maximum generality is desired.

                                      Hierarchy of collection framework
                                            



Monday, 4 September 2017

Interface in java example

What is interface?

An interface is a reference type in Java. It is similar to class. It is a collection of abstract methods. A class implements an interface, thereby inheriting the abstract methods of the interface. Along with abstract methods, an interface may also contain constants, default methods, static methods, and nested types.


why use interface in java ?

There are mainly three reasons to use interface. They are given below.
  • It is used to achieve abstraction.
  • By interface, we can support the functionality of multiple inheritance.
  • It can be used to achieve loose coupling.

Internal addition by compiler:-

In other words, Interface fields are public, static and final by default, and methods are public and abstract.
interface in java

Data Conversion in java

Data Conversion In java programming we have six data conversion technique they are:. 1 Converting numeric string type data into numeri...