Thursday, February 13, 2014

About Security

In this post we will cover more details about Security feature of Java and for this we will be covering 3 concepts which are. Classloaders,Bytecode verifiers and Security manager

Classloader

Classloader is a class files that helps to load all the class files in the memory before JVM can perform some action on these class files. Since we stated that classloader is a class file how is this class file loaded? For this we have a bootstrap loader which is a native classloader and this helps to load the classloader, bootstrap loader is native, platform dependent and it is written in c language

Whenever we execute Java command a native launcher program is triggered and on successful launching of the program bootstrap loader is loaded, which is used to load all the core Java classes which belongs to the package java.

Bootstrap loader also launches another 2 loaders which are Extension loader and Application loader.

Extension loader loads extension classes which belongs to the package javax. next the Application loader loads classes required for the current application. This is how all the class loaders are loaded.

All the 3 classloaders follow the Delegation model.

Simple example to demonstrate this

whenever an application is required to load a class it first triggers a request to the application loader which in turn returns the request to extension loader and extension passes the request to the bootstrap which check if the core java class is required. If required then it grants the request to extension loader and extension loader grants the access in turn to the application loader.

------------------------------------------------------------------------------------------------------------

Bytecode Verifier

Next moving on to bytecode Verifier its task is to verify the bytecode and check if there is any variables that are not intialized. Tip How to view the bytecode of a Java file use the below command
       
javap -c javafilename  

when you execute the above line on command prompt it gives the bytecode version of the Javafile.
------------------------------------------------------------------------------------------------------------

Security manager

Security manager manages granting or blocking access of the file, system properties below is a Simple example to demonstrate this feature


import java.io.FileInputStream;
import java.io.FileNotFoundException;

public class sample {
    public static void main(String[] args)
        throws FileNotFoundException {
        //Is there a SecurityManger registered?
        System.out.println("SecurityManager: " +
            System.getSecurityManager());

        //Checking if we can open a file for reading
        FileInputStream fis = new FileInputStream("k:/sample.txt");
        System.out.println("File successfully opened");

        //Checking if we can access a vm property
        System.out.println(System.getProperty("file.encoding"));
    }
}

 

When you compile and run this program you would find the below results.

       
SecurityManager:null
File successfully opened
cp1252
 
 

Null in the first line means that the security manager is not defined, next line states that the file is open. You can go more advance with this topic by defining the policy file in which you can grant or block access to the file and we will cover this in the future post.

>>>JDK,JVM,JRE
------------------------------------------------------------------------------------------------------------

Wednesday, February 12, 2014

Features of Java

Lets look at the features of Java that makes it different from other programming languages.

1. Simple

2. Platform independent

3. Secured

4. Robust

5. Multithread

5. Distributed

6. Object oriented

7. Portable

8. Dynamic

------------------------------------------------------------------------------------------------------------

Java is Simple when compared syntactically with c++, with some minor changes.

------------------------------------------------------------------------------------------------------------

Java is platform independent, as we have already seen in our previous post about platform now let us find more details about java as a platform.

Java is software platform which has it's own run time environment and API and it run's on top of hardware platform.

Now moving on to the key point of platform independent, when the java code is compiled by the Javac compiler it is converted to the class file and later this class file is converted to bytecode by JVM. Please note that the bytecode that is generated is platform independent, in the sense this bytecode can be executed on any platform for example(windows,Linux, Solaris). This is the reason Java is platform independent.

This make Java unique

------------------------------------------------------------------------------------------------------------

Java is secured because programs are executed inside a virtual machine sandbox, as we know that java as its own run time this make its more secured.

In java there is no concept of pointers which makes it more secure.

Also they are 3 more features that make java secured which are Classloaders,bytecode verifier and security manager and this topics would be discussed in a separate post

------------------------------------------------------------------------------------------------------------

Robust means Strong, what make Java Robust, it lacks in pointers and security problems are avoided, it automatically performs garbage collection, Handling exceptions.

------------------------------------------------------------------------------------------------------------

Java is multithreaded, in the sense it performs multitask by sharing the same memory using threads.

------------------------------------------------------------------------------------------------------------

Java is used to create distributed application that allows to access file from different machine using internet.

---------------------------------------------------------------------------------------------------------

Java use object oriented methodology which make software development easy and maintainable, by following the simple rules like Encapsulation.Polymorphism,Inheritance,Abstraction

---------------------------------------------------------------------------------------------------------

Java is portable as we know that the bytecode is platform independent and thus can be executed on any platform

>>>Security
------------------------------------------------------------------------------------------------------------

Basic overview of Java

Welcome to my blog, this time I have created a blog about Java isnt that interesting? In this blog you find all the basic information, concepts, examples, useful link etc... which will help you to master Java. I have followed a very systematic approach with my posts, anybody who follows my posts on a daily basis would not miss on any of the concepts. So lets get started...
Before diving into the Ocean of Java and getting our hands dirty with coding, lets understands what is java and its purpose.

what is Java and how it came into existence?


Where is Java used?


------------------------------------------------------------------------------------------------------------
Java is a programming language and it is a platform. Definition seems to be very simple lets get deeper into it.
Programming language is used to write a set of instructions and later these instructions are converted to a machine code, once the computers interprets the machine code it execute these instructions and gives us the desired results.
What is a platform. A Platform provides a infrastructure for applications, so that these applications can be built and run. Platform provides a easy mode of designing applications with the existing platforms like Java.

History Of Java?

Java was originally founded by a small team of sun engineers called Green Team in 1991 and James Gosling was one among them. Green Team wanted to develop a language for digital devices such as set-top boxes, televisions etc, at the same time Internet technology also was growing very rapidly so they decided and used JAVA for internet programming.
Before naming this language they had many revision in the names(like OAK) and finally they decided with the name JAVA. Java is a small island in Indonesia which actually produced the first coffee and that's how it was named.
First Version of Java was release in 1995 and it was JDK 1.0, now the current latest version is Java SE 7
------------------------------------------------------------------------------------------------------------

What kind of Applications can be designed using Java?


1. Web Applications

An application that runs on the server side and generates dynamic pages are web application (example-websites).

2. Standalone Applications

These are the desktop application which needs to be installed on your system for functioning (example-media player).

3. Enterprise Applications

Banking application come in this category which require secured connection, load balancing.

4. Mobile Applications

Application that are created for mobile devices.
>>>Features
------------------------------------------------------------------------------------------------------------