OOP: Inheritance

OOP: Inheritance

​This article is the third article in the series of Object Oriented Programming tutorials, explaining the OOP concept - Inheritance. The same problem used in the Encapsulation tutorial is used here to explain Inheritance. The ABC book shop needs a software to maintain its billing procedures and stock management. This book shop sells books, magazines, newsletters and DVDs. In the last tutorial, we have developed a Book class.
public class Book {
    private String title;
    private String author;
    private double price;

    public String getTitle() {
        return this.title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getAuthor() {
        return this.author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    public void setPrice(double price) {
        if (price > 0) {
            this.price = price;
        } else {
            System.out.println("Invalid price");
        }
    }

    public double getPrice() {
        return this.price;
    }

    public void sell(int qty) {
        System.out.println("Total: $" + (qty * price));
    }
}
This time we are going to create a Magazine class with the following attributes and behaviors. Do not forget to use encapsulation when creating the class.
Read More
OOP: Encapsulation

OOP: Encapsulation

​Object Oriented Programming has four major concepts, which are Encapsulation, Inheritance, Abstraction and Polymorphism. This article deals with the first concept Encapsulation. Consider this problem. The ABC book shop needs a software to maintain its billing procedures and stock management. This book shop sells books, magazines, newsletters and DVDs. The first step you need to do is developing a Book class to represent the books with the following attributes and behaviors. Remember that, attributes are represented by instance variables and the behaviors are represented by instance methods.
Read More
Object Oriented Programming

Object Oriented Programming

​Object Oriented Programming (OOP) is a programming paradigm used to develop modern applications. OOP allows developers to map real world problems, exactly in the same manner in your desired object oriented programming language, therefore developers can plan their design without any high level technical interpretation. This tutorial provides an introduction to OOP and upcoming series of tutorials provide a brief explanation on the OOP concepts.

Read More

Relative and Linear Layouts

This article covers the RelativeLayout and LinearLayout which are the basic Android layouts. In the last article Android – Hello, world!, I gave a sample problem to develop. The same screen shot is attached here to explain the needs for layouts.

Android Hello world

Read More

Introduction to Threads

Modern computers have the capability to execute multiple tasks at the same time. Have you ever wondered, how it is achieved in the modern computers only, while older batch processing systems were unable to do so? Early days, processors were able to execute only one process at a time. Programmers fed the problems one after another in a queue to the computer. However, these days we are able to edit a text file while listening a song. In fact still processors can execute a single task at a specific time. Multicore processors have to be considered a set of sub processors; in that case, those sub processors can do one job at a time. Processors are using a technique called time sharing to execute multiple processes at the same time. The basic idea is executing every processes for a limited amount of time only. For example if you are playing a music in VLC player and reading this blog in Firefox, in background your processor is executing the VLC player for few milliseconds and then executing the Firefox for few milliseconds. Not only these two visible applications, all the invisible operating system related processes also running in the same manner. This execution happens cyclic through all the available threads in the system. Humans cannot feel the idle time of processes, because of the high frequency of processors.
Read More

Fork/Join Framework

Java provides a strong multithreading platform to the programmers and time to time it introduces new features. Fork/Join framework is such an enhancement introduced in Java 1.7 to optimize the multicore processors in multithreading environment. You are required to have basic knowledge on Java Threads in order to understand the Fork/Join framework. Since this topic is much related to performance of your application, I have provided the specifications of my computer which is used to run the provided codes. To test the real difference between Fork/Join framework used application and single thread application you need to run the given sample codes in a multicore processor.
  • Processor: Intel(R) Core(TM) i5 CPU 2.53GHz
  • RAM: 6GB of DDR3
  • Operating System: Ubuntu 14.04 x64 bit
  • Java: JDK 1.8 x64 bit
I am using Merge Sort algorithm to explain the Fork/Join framework concepts, which is a Divide and Conquer algorithm. Divide and conquering is a technique of breaking a problem into its sub set of problems until we reach a simplest form of that problem. Then the problem will be solved recursively by solving sub problems first. For example, to sort an array {6, 5, 3, 1, 8, 7, 2, 4} first we divide it into two pieces {6, 5, 3, 1} and {8, 7, 2, 4}. Then divide it further to get four arrays with two elements on each of them. Continue the same process until you get arrays with single elements. Once you get those arrays, start merging by comparing elements from adjacent arrays.
For further details about Merge Sort: Wikipedia.
Read More

Try With Resources

Closing resources is an important best practice in all the languages, but most of the times it is forgotten by developers or implemented inappropriately. This article explains the actual purpose of closing resources and the newly introduced try-with-resources which made the job of developers much easy.

First of all, why do we need to close the connections? Take the FileInputStream/FileOutputStream classes. Once you have completed the file handling operations using these classes, you are required to close the connection. The reason is something related to the behavior of operating systems. Hard disk’s speed is much slower than processor, that’s why RAM is used in computers as an inter-mediator between the hard disk and the processor. For reading or writing purposes if processor directly access a file in the hard disk, the file accessing will take a lot of time and which will slow down the process. To solve this problem, operating system creates a virtual file in the RAM which is much similar to the file in the hard disk (if it is already there). All your read/write operations are performed on that virtual file and once you complete your taks the changes will be update to the actual file.


Read More

Android - Hello, world!

This article explains the way to create a Hello World Android application using Android Studio. Step by step guidance is provided with screenshots and the sample project is available at Git hub.

Start the Android Studio and click on the button “Start a new Android Studio Project”.


Read More

Create Android Virtual Device

Once you have installed the Android Studio, the first step is creating your Android Virtual Device for testing purposes. Android Studio might create a default virtual device with the latest Android version. Creating another virtual device with a lower version of Android (Usually 2.3.3) is helpful if you have a limited RAM size. Additionally, it is always better to test your applications in both latest and lower versions of Android devices. For example if you are using a very high resolution image in your application, it might work on latest version of Android, but it will throw a java.lang.OutOfMemory in lower version of Android. On the other hand accessing Internet within the main thread is allowed in lower version, but it will throw android.os.NetworkOnMainThreadException from Android 3.0 (Honeycomb). Other than the versions of Android, creating Android Virtual Devices with various device types allows you to test the behavior of your application in different devices.

To create an Android 2.3.3 virtual device, you need to install the required SDK tools first. Open your Android Studio and click on the “Configure” button.


Read More

Introduction to Servers

This article mainly focuses the developers who wants to get the Oracle Certified Expert, Java EE 6 Web Component Developer (OCEWCD 6 - 1Z0-899) certification. In this article you will get a brief introduction of web servers, application servers and Servlet containers.

I noticed in my classes; there were some students, even do not know what kind of web development they are going to learn. They thought the OCEWCD is all about HTML, JavaScript and CSS, so this article starts with an introduction to client side applications and server side applications. There are two components in a web application. We call them as server side application and client side application. If you take an application, the fancy stuffs you see in your web browser belong to the client side. The background business logic, database access, session management and even more functional requirements are handled by server side component. Client side developers mostly use HTML, JavaScript, CSS, etc to develop the application. They are the artists and they know the way to attract the users. On the other hand, server side developers use languages like Java, Perl or PHP where the main concern is serving to the client side application and providing the functional requirements. OCEWCD exam is for the server side application developers, even though there are some client side JSP related topics.



Read More

Sublime Text


Sublime Text is a cross-platform text and source code editor, with a Python application programming interface (API). Sublime Text is proprietary software (Sublime 2 has a free version) however it is worth to pay for Sublime Text. Its functionality is extensible with plugins. Most of the extending packages have free-software licenses and are community-built and maintained. The power of plugins and the ability of customization make the editor even more powerful.
Official Link
Read More
Lambda Expression

Lambda Expression

Lets start this article with a familiared Java code which is used to create a new Thread using Runnable interface. Based on the requirements you might prefer either to create a separate class which implements java.lang.Runnable interface or to create an anonymous Runnable object and pass it to the Thread object and start it. In the following code I have chosen the second way and nothing to surprise with this code; it simply runs and prints the id of newly created Thread.
public class ThreadDemo {
    public static void main(String[] args) {
        // Runnable anonymous class
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                System.out.println("ID: " + Thread.currentThread().getId());
            }
        };
        Thread thread = new Thread(runnable);
        thread.start();
    }
}
Read More

Contact Form

Name

Email *

Message *