JVM (Java) and it’s Memory Management

JVM (Java Virtual Machine) is an abstract machine or can say it is a software implementation of a Physical Machine. It is a specification that provides runtime environment in which java bytecode can be executed. JVMs are available for many hardware and software platforms (i.e. JVM is platform dependent). What is JVM It is: A specification: Where working of Java Virtual Machine is specified. But implementation provider is independent to choose the algorithm. Its implementation has been provided by Oracle and other companies. An implementation: Its implementation is known as JRE (Java Runtime Environment). Runtime Instance: Whenever you write java command on the command prompt to run the java class, an instance of JVM is created. What it 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… Read more“JVM (Java) and it’s Memory Management”

Generics in Java

Generics Many algorithms work in a similar way irrespective of the data types on which they are applied on All Stacks work in a similar way irrespective of the type of object they hold Generics help to write algorithms independent of a data type These algorithms can be applied to a variety of data types The data type is parameterized A class, interface or a method that works on a parameterized type is called a generic public class List<T>{ protected T [] list; public List(T [] list){ this.list = list; } public void put(T element, int position){ list[position] = element; } public T get(int position){ return list[position]; } } In above code, T represents a data type. While declaring an object of List, the programmer can decide the actual type for T. List<String> list = new List<String>(new String[5]); list.put(“Hello”, 0); list.put(“Welcome”, 1); list.put(“Ok”, 2); System.out.println(list.get(0)); System.out.println(list.get(1)); System.out.println(list.get(2));   Just like… Read more“Generics in Java”

Collection Framework in Java

The Collection Framework is a set of classes and interfaces Helps in handling groups of objects Standardizes the way in which groups of objects are handled The important interfaces of the Collection Framework are Collection List Queue Set SortedSet All these interfaces are generic interfaces Collection interface declares the methods that any Collection should have Any class that defines a Collection should implement this interface Some of the important methods are add remove contains isEmpty List List interface extends Collection interface List interface declares the behavior of a Collection that stores a sequence of elements Elements can be inserted and accessed by their position Some of the important methods are add (adds to the specified position) get (gets from the specified position) indexOf Set Set interface extends Collection interface Set interface declares the behavior of a Collection that does not allow duplicate elements Does not declare any new method on… Read more“Collection Framework in Java”

Exceptions and Errors in Java

Exception Exception is an exceptional case that can happen in a program An Exception occurs during the execution of a program and disrupts the normal flow of instructions. When there is an exception Normally the program crashes and prints a system generated error message Not acceptable in a mission critical application The programmer can handle the exception, preventing the program from crashing Exception Handler is a set of instructions that handles an exception The Java programming language provides a mechanism to help programs report and handle errors When an error occurs, the program throws an exception The exception object that is thrown contains information about the exception The runtime environment attempts to find the Exception Handler The exception handler attempts to recover from the error If the error is unrecoverable, provide a gentle exit from the program after clean up operations like closing open files etc Helpful in separating the… Read more“Exceptions and Errors in Java”

Difference between Abstract Class and Interface

Abstract Classes Interfaces Can have concrete methods Can have only abstract methods Can have variables Can have only static final (constant) data members Can have private and protected members All  members are public by default Can be extended from one class Can be extended from any number of interfaces A class can extend only one abstract class A class can implement any number of interfaces

Anonymous Inner Class in Java

An inner class is a class defined within another class. An inner class is a non-static nested class. It has access to all of the variables and methods of its outer class. An inner class is fully within the scope of its enclosing class. An anonymous inner class is a class that is not assigned any name. It is important to note that class Inner is known only within the scope of class Outer. The Java compiler generates an error message if any code outside of class Outer attempts to instantiate class Inner. Generally, these are used whenever you need to override the method of a class or an interface. Example- public class AnonymousInnerClassDemo extends Applet { public void init() { addMouseListener(new MouseAdapter(){ public void mousePressed (MouseEvent ev) { showStatus(“Mouse Pressed !!”); } } } In this example init() method calls addMouseListener() method. Its argument is an expression that defines… Read more“Anonymous Inner Class in Java”

Basic Java constructs

Java is a strongly typed language, which means that all variables must first be declared before they can be used. The basic form of variable declaration is “Variable Type followed by variable name”. For example “int myVar;” Doing so tells your program that the variable named “myVar” exists and holds numerical data[ i.e integer value]. A variable’s data type determines the values it may contain, plus the operations that may be performed on it. The data types are of two types. They are primitive data types and reference data types. Primitive Data Types are pre defined by the language and is named by a reserved keyword. Example: int, float etc. Reference Data types are often referred as non-primitive data types. Example: Objects and Arrays They are called as reference data types because they are handled “by reference” – in other words, the address of the object or array is stored in… Read more“Basic Java constructs”

New features of various java releases and their comparison

Java is the choice of many software developers for writing applications. It is a popular platform that provides API and runtime environment for scripting and running enterprise software, including network applications and web-services. Oracle claims that Java is running in 97% of enterprise computers. Each Java programmer must know about these new features. Types of Applications that Run on Java are below, Desktop GUI Applications Mobile Applications Embedded Systems Web Applications Web Servers and Application Servers Enterprise Applications Scientific Applications Below is the consolidated list of important new features added in various java releases.

Installing java SDK and writing first java program

Installing and using Java Install the java SDK from below location and follow the installation instructions, http://www.oracle.com/technetwork/java/javase/downloads/index.html Setting environment variable for Java Environmental variable is a variable that describes the operating environment of the process. Common environment variables describe the home directory, command search path etc. JAVA_HOME JAVA_HOME is a environment variable (in Unix terminologies), or a PATH variable (in Windows terminology) which contains the path of Java installation directory. On window operating system follow the below steps, 1.Right click My Computer and select Properties. 2. On the Advanced tab, select Environment Variables, and then edit JAVA_HOME to point to where the JDK software is located. or run the below from command prompt, Set JAVA_HOME = <jdk-install-dir> example, C:\Program Files\Java\jdk1.6.0_02. On Unix operating system run the below command, export JAVA_HOME=<jdk-install-dir> CLASSPATH Set PATH =%PATH%;%JAVA_HOME%\lib\tools.jar PATH Set PATH =%PATH%;%JAVA_HOME%\bin; Please note, changing the JAVA_HOME will reflect to path and class path… Read more“Installing java SDK and writing first java program”

Core Java Architecture and JVM

In this lesson, we are going to explain the core Java Architecture. Java Java was conceived by a team of engineers in Sun Microsystems in 1991 as a part of a research project, which was led by James Gosling and Patrick Naughton. It was initially called Oak but was renamed as Java in 1995. This is designed to be small, simple, and portable across platforms and operating systems, both at the source and at the binary level, which means that the same Java program can run on any machine. Features of Java Java is an Object Oriented Language. Object-Oriented design is a technique that helps the programmer visualize the program using real-life objects. Java is a Simple Language. The reason is, Certain complex features like operator overloading, multiple inheritance, pointers, explicit memory de allocation are not present in Java language. Using Java we can write Robust Programs. The Two main… Read more“Core Java Architecture and JVM”