Being an Oracle Certified Java Programmer


In this post I will explain my experiences in taking up OCJP exam.


The Oracle Certified Java Programmer exam mainly tests the individual's basic understanding and knowledge of the Java Language.It consists of many questions on Object Oriented,Syntax and Structure based questions in multiple choice type and Drag and Drop questions.



                                                              

Inheritance in Java

In the previous posts you have learned about the Object Oriented Programming(OOP) Principles( you can refer them here ).So,one of the brightest theories of OOP is the inheritance,we can use the information by acquiring from one class to another and in this way we can manage our data in a hierarchial order.

Mainly we can use inheritance in Java by using extends and implements keywords extends use mainly normal single inheritance where as implements is used for multiple inheritance which cannot be implemented directly in Java using extends keyword.

So,in Java we have two relationships in Inheritance.They are :
  1. IS-A relationship.
  2. HAS-A relationship.
  • IS-A relationship : We can explain the inheritance actually like,eg: Dog IS-A Animal , BMW IS-A Car.Here we have a simple example.
class Animal{
}

class Dog extends Animal{
}

class Cat extends Animal{
}

public class Kitten extends Cat{
}
         
Now based on above we can come to these conclusions:

  • Animal is the superclass of Dog and Cat.
  • Dog and Cat are subclasses of Animal.
  • Kitten is the subclass of Cat and Animal.
These conclusions can be mentioned in IS-A form as:
  • Dog IS-A Animal.
  • Cat IS-A Animal.
  • Kitten IS-A Cat.
  • So,we can say that Kitten IS-A Animal.
We can explain this with the help of an example program.

public class Kitten extends Cat{
   public static void main(String args[]){

      Animal a = new Animal();
      Cat c = new Cat();
      Kitten k = new Kitten();

      System.out.println(c instanceof Animal);
      System.out.println(k instanceof Cat);
      System.out.println(k instanceof Animal);
   }
}

Here we can see that Kitten class is creating objects for Animal ,  Cat , Kitten classes.We are testing whether Kitten object is an instance of Animal and Cat by using an instanceof operator.We will get the output as:


true
true
true


So,here we covered the inheritance with extends keyword,we will see implements concept in detail in Interface concept.



  • HAS-A relationship : The HAS-A relationship mainly deals with the usage of a certain code used in one class which is extended from an another class.In other words,if a class Vehicle has a subclass class Car and class B has a variable called myBrake which belongs to Brake class,then we can say Car HAS-A Brake.
This can be explained in the below code:
public class Vehicle { }
public class Car extends Vehicle {
      private Brake myBrake;
}


We can also see examples like:

  • class Room { .... }
  • class Bathroom extends Room{ private Tub myTub; }
So in this we can see Room is a superclass,Bathroom is a subclass which has a Tub instance variable so we can say a Room HAS-A Tub.


So,in this way we can explain the inheritance concepts.The main advantages if Inheritance are Code Reusability and ability to support polymorphism.


In the next posts more and more concepts will be covere,Stay Tuned!!


Au Revoir!!

Cloud Computing Explained!


  • What is Cloud Computing?



     Cloud Computing is one of the famous buzz words and the hype in the present day software industry.So, what exactly is Cloud Computing ? Do we need to travel in an aeroplane or sit on top of a mountain with a computer to leverage the services? Does it work when it is raining ? ;) ( I came across a video in YouTube where an IT Commissioner asked this question :D ).The answer is obviously NO.I will try to explain about Cloud Computing in this post without too many technical terms and in an easy understanding way.
                                          

  • Cloud Computing can be described as the modern day Internet Computing and it is mainly enabled by virtualization and we can say it is an adaption of virtual computing ,because everything depends and runs on the Internet!Imagine you have a website and you started promoting it and by god's grace it has clicked and you got some huge amounts of traffic.So,obviously you have to maintain your web-server with increase in your site's popularity.There may be one state where you may fail to maintain your server as  effectively and as consistently compared to the earlier times,which may result in less number of hits for the site,many people may find difficulties in accessing your website and many other problems.One solution is to buy more and more number of servers which involves increased cost and maintenance.
  • Take an other scenario , where your company has a website which attracts seasonal traffic from the public like an examination results portal.There will be huge amounts of traffic when the results are out and to handle that traffic the company must buy more servers but in the rest of the time the site doesn't get too much attention.So , the company need to pay for the server and its maintenance even though there is not much traffic. We just cant throw away the servers once we buy and set them up and running.
  • Cloud Computing provides easy solution for the above problems decreasing the cost of setting up and maintaining the servers , site and application of an end-user/organisation.


source getty images
                                                  
                                                

  • Cloud computing involves sharing of  many computer resources like software,servers etc;which are useful for the software development.These resources are shared between the computers all over the world by using the data centers which will be accessed through Internet and is known as "Cloud".There are many organizations which call themselves as Cloud Service Providers( Google,Amazon,Microsoft,vmware etc) which provide these infrastructure and software in the form as a service through Internet or as we call in this context Cloud.The main idea of Cloud Computing is we outsource our application/web site to the Cloud Providers and use their infrastructure to run our applications.
  • So how can a cloud service provider help solve the above problems for an organization?

    Cloud Computing follows some important capabilities which help solve the above problems:
    1.Elasticity : As the name suggests it means being flexible, when your application needs to serve the traffic which needs 100 servers the cloud can scale up and give access to 100 servers at peak time and if you need only 1 server to just keep the site running without any huge traffic you will get only 1 server. You cant get this kind of flexibility or scalability when you are hosting the application/ web site on your own.

    2.Pay-As-You-GO: So previously you bought 10 servers to maintain the traffic for your website which will last for only 2 months and in the rest of the year you just need 2 servers to maintain the website leaving those additional 8 servers ideal. Cloud computing solves this problem as you can pay for only the number of servers or computing resources you are using i.e. Pay for only 2 servers when your site is getting less traffic and 10 servers at peak time. This is just like paying for a Cab or Electricity , when you want to go somewhere you hire a cab and pay for the ride depending on the distance traveled,and you pay for the electricity as per your usage.

    3. Self Service and Instant Access( ON/OFF): When you want to setup the servers on your own you buy the infrastructure and take some time to get them ready.But in the case of cloud-computing, the cloud providers will give the access to the cloud through a terminal or console which we can access through our computer. You can instantly order the computing power when you are in need and just turn them off like an electric bulb when you are done.

    These are the main reasons why the cloud computing became so huge recently. Hope this makes sense till now. But you may ask what does cloud computing mean to me? How it is helpful ? The answer is, it takes many forms and is helpful depending on what your need is.



  • If you are a Business Professional or System Administrator : Cloud computing is all about outsourcing your application and data to utilize the computing power like infrastructure, hardware, servers etc; You move away from the servers you are paying to maintain the website and access the infrastructure of the cloud provider. This is called Infrastructure as a Service ( IaaS ). You will be billed according to the number of CPU hours and the usage of the website. Majority cloud providers in this domain are Amazon Web Services (which provides many services like Amazon EC2 and S3), Google (Google Compute Engine) , Microsoft (Azure), Red hat  vmWare etc;
  • If you are a Developer or an Architect : You need to develop applications or think of a strategy to migrate the existing in-house applications to scale and to leverage the service of cloud. All you need is a platform(Java, .Net , PHP , Ruby etc). Providing this is called as Platform as a Service ( PaaS ). This service will provide a Platform and a set of development tools knows as SDK to develop or migrate applications to leverage the cloud services and infrastructure. The major provider in this service are Amazon(Amazon Web Services Elastic Beanstalk), Google ( Google App Engine), Microsoft Windows Azure, Heroku, AppHarbour,CloudFoundry etc; If you are a developer these services provide some exciting features. All you need to do is download the SDK from the site, write some code and deploy that to the server.Voila!! You can access your application anywhere in the internet! Its that easy.
  • If you are an End-User : You need a variety of application in your day to day life. But in some situations you may need to worry about many things to access that applications like the application may not run on your hardware, you cant access your application data in another device or at your workplace.So instead of buying the software and installing it on your device, you can purchase a monthly,weekly or yearly subscription of that application and access that application on your web browser without worrying about your hardware. You can use it on your PC when you are at home, on your laptop when you are at your workplace, on your mobile phone or tablet well where ever you may be. This is called providing Software as a Service ( SaaS ). For example, instead of buying Microsoft Office license and installing it on your computer you can just simply use Office Cloud365 service provided by Microsoft by paying monthly subscription as per your usage. One major advantage is you can use the brand new versions of the software with updated features every time unlike the software you bought for some huge money.
                                                               
                                                       
Not only these services there are some new Service Models coming in to the market like Gaming as a Service, Backend as a Service, Network as a Service which I think will fall under one of the above mentioned categories when you think logically. 

One of the major disadvantage and challenges of Cloud Computing is providing security. No one will give  the important customer data of an organisation to a 3rd party cloud provider without knowing how secure will be the data. This is the major challenge which needs to be addressed in case of very large organizations. The other alternative is to set up your own Cloud and be your own Cloud Provider. Here comes the concept of different models of Cloud.
a. Public Cloud - Here you outsource your application to a big cloud service provider who can afford huge amounts of money to buy and maintain servers to run many applications in their data centers.This type of cloud is called Public Cloud.
b. Private Cloud - Here an organization can set up its own infrastructure i.e. its own cloud by setting up virtualized instances of the servers.One more thing is to consulting 3rd party vendors to setup your own network through internet. This may sound similar to Public Cloud IaaS offering but here we get this service under the organizations firewall restrictions.

These concepts are pretty complex and are worth explaining in an other blog post. I hope this post was helpful for people who struggle to understand what Cloud Computing really is!!
                                        

Listen to your MP3 songs on your PC through Java MP3 Player!!

We all listen to songs daily in our PC,majority of them or all of them are mp3 formats.We have different kinds of Media Players in Internet.But,regardless of all those applications if we use a Media Player made with Java,how it will be?


Sounds Intresting right?


Two years ago when I am searching through java websites I came across this intresting application called Java MP3 Player.Even though its not very userfriendly,its a very good application which is developed using basic Swing capabilities. 


                                                  
You can see the source code here :
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package mediaplayer;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
import javazoom.jlgui.basicplayer.*;
/**
 *
 * @author Administrator
 */
class JavaMediaPlayer extends JPanel implements BasicPlayerListener{

    private JProgressBar jpb;
    private JButton play;
    private BasicPlayer player=new BasicPlayer();;
    private String imagePath="images/";
    private static int p=0;
    private static boolean playBoolean=true;

    JavaMediaPlayer(){
        //setLayout(new FlowLayout(FlowLayout.LEFT,3,3));

        setLayout(null);

        player.addBasicPlayerListener(this);

        play=new JButton(new ImageIcon(imagePath+"pause.png"));
        play.setToolTipText("pause");play.setBounds(2,2,20,20);

        play.addActionListener(new ActionListener(){
           public void actionPerformed(ActionEvent ae){
               if(playBoolean){
                   pausePlaying();
                   play.setToolTipText("Play");
                   play.setIcon(new ImageIcon(imagePath+"play.png"));
                   playBoolean=false;
                   return;
               }
               if(playBoolean==false){
                   resumePlaying();
                   play.setToolTipText("Pause");
                   play.setIcon(new ImageIcon(imagePath+"pause.png"));
                   playBoolean=true;
                   return;
               }
           }
        });

        jpb=new JProgressBar();
        jpb.setBorderPainted(true);
        jpb.setBounds(25,2,280,20);

        add(play);
        add(jpb);
    }

    public void startPlaying(String fileName){
        try{
            play.setIcon(new ImageIcon(imagePath+"pause.png"));
            play.setToolTipText("Pause");
            playBoolean=true;
            player.open(new File(fileName));
            player.play();//actually play file
        }
        catch(Exception d){
            System.out.println(d);
        }
    }
    private void pausePlaying(){
        try{
            player.pause();
        }
        catch(Exception e){
            System.out.println(e);
        }
    }
    private void stopPlaying(){
        try{
            player.stop();
            jpb.setValue(0);
        }
        catch(Exception d){
            System.out.println(d);
        }
    }
    private void resumePlaying(){
        try{
            player.resume();
        }
        catch(Exception d){
            System.out.println(d);
        }
    }

    public void opened(Object arg0, Map map) {
        String k=map.get("audio.length.frames").toString();
        jpb.setMaximum(Integer.parseInt(k)-15);
    }

    public void progress(int arg0, long arg1, byte[] arg2, Map map) {
         String s=map.get("mp3.frame").toString();
         int k=(p-(Integer.parseInt(s))*(-1));
        jpb.setValue(k);
    }

    public void stateUpdated(BasicPlayerEvent bpev) {
       if(bpev.getCode()==BasicPlayerEvent.STOPPED){
           // Something here
       }
    }
    public void setController(BasicController arg0) {
       // throw new UnsupportedOperationException("Not supported yet.");
    }
}

This is the JavaMP3Player class.The following code is the Main class.
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package mediaplayer;

import javax.swing.*;

/**
 *
 * @author Tutorial Jinni
 */
class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        JFrame f=new JFrame();
        JavaMediaPlayer jmp=new JavaMediaPlayer();
        f.add(jmp);
        f.setDefaultCloseOperation(3);
        f.setVisible(true);
        f.setSize(330,60);
        f.setTitle("Java Media Player - Tutorial Jinni");
        jmp.startPlaying("Song-location.mp3");
    }
}


You can execute this first by grouping both these classes in a single folder,compiling the Main class and try executing it.This application mainly usef JMF(Java Media Framework) which is used to create Players and several other media related applications.


In this,we used BasicPlayer class and applied some techniques of Swing!


You can download the program full source code here .To execute this full source code you need NetBeans Developer IDE.


We will see more Java Applications in my next posts!!


Hope you liked it!


Stay Tuned!!






                                    

Samsung-Android Galaxy 5


Samsung announced Galaxy Android 5 series phone with more unique qualities than the 3 series.I came across this phone recently and I decided to write a review on what I saw.
       


This Samsung phone powered by Android platform has a unique Samsung Social Hub facility.In this we can get all the contact details and emails from an user's social networking site into a single contact list,making it more easy for young professionals and teenagers to keep in touch with their friends.You can easily share your day to day updates with youfriends all over the social networking sites at once.


It has many more in-built features.They are:

  • This Mobile comes with Android 2.1 OS
  • TFT LCD Display with 2.8'' 240x320 pixels.
  • 2MP camera with LED Flash.
  • Google Mobile Service,Android Market,Touchwiz 3.0.
  • Wi-Fi, Bluetooth 2.1, A-GPS .
I think this phone is a very good option for youngsters and social networking geeks as it comes in affordable range of Rs.10,000 in the market!!








                                             

Java Applications-Local Raja for Hyderabad MMTS Train Timings

Hello again,in the previous posts we saw actually what is java and its features and basics.Now Im going to dive into some other topic which deals with applications of Java.As I said earlier Java can be used every where in our daily world ranging from mobile phones to microwave owens.

                                          

Coming to the actual topic,MMTS railway stations and trains are rapidly gaining popularity these days.Everyone are opting Local Metro Rails rather than buses as they are  far more cheaper and  takes less time to cover the distance across the city of Hyderabad.As I am a frequent user of Local Trains when I am browsing through Internet usually, I stumbled across an AWESOME JAVA APPLICATION called as Local Raja.This application is mainly used for keeping track of the timings of Metro Rails which are very frequent in twin cities.It becomes very cumbersome for a person to memorize all the train timings starting right from 4'o clock in the morning to 10'o clock in the night.

As now a days,we can observe every 90 persons out of 100 are having a Mobile,it became a necessity rather than an accessory.So I think this  simple Java application will be helpful for those who are using LocalTrains frequently

This application comes as two .jar(Java archive) files.These can be uploaded into your mobile using your datacable and you can access them whenever you want!!

You can download this application here .

Hope this application is useful to some of you!!

Stay Tuned for more intresting Java tutorials and Applications.

Au Revoir!!


Variables and Datatypes

Variable and its Scope


There are mainly 2 types of variables in Java.They are: Instance variables and Member Variables(Class variables).


Instance Variables are the variables which are created while instantiating a class.


Class variables are the normal variables which are declared casually inside a class.


Note : The static variables also come under class variables.


Datatypes Explained


In the previous section we came across the various datatypes and its categories.Lets have a deep look at them.



  • Integer Datatypes(int,byte,short,long) are used to store signed integers values.The memory size of the datatypes of byte,short,int,long are 1,2,4,8 respectively.
          Note : A long literal is generally ended with ' L '.Ex: 32L.
  • Floating Point Datatypes(float,double) are used to store the decimal type(fractional type) values.The memory size of the datatypes of float,double are 4,8 bytes respectively.The floating point literals float must end with ' f '.And double literal must take a precission of two places or else there will be a Loss In Precesion Error by compiler.
          Example : 2.8f - float literal.
                         2.85 - double literal.
  • Character Datatype(char) are used to store single Unicode characters.The memory size is 2 bytes.
  • Boolean Datatypes are used to store the values which are either true or false .

Video tutorial:

So,we covered the Language basics till here and from next parts we will go into the more serious parts which are useful in coding.

Stay Tuned for more posts!!

Au Revoir!!