Design Patterns Part II

Builder Pattern: This design takes the step by step approach when building objects. This is done by taking objects with different attributes to build different representations of the same object and the builder is independent of the objects.

For code example you can click here.

Decorator Pattern: This design is used to add functionality to an existing object without changing its functionality. This design pattern uses abstract classes or interfaces and acts as a wrapper to an existing class.

For code example you can click here.

Facade Pattern: Hides the complexities of the system and provides an interface to the client using which the client can access the system.

This pattern involves a single class which provides simplified methods required by client and delegates calls to methods of existing system classes.

For code example you can click here.

Prototype Pattern: Specify the kind of objects to create using a prototypical instance, and creates new objects by copying this prototype. In other word is a pattern that creates duplicate object by implementing a prototype interface, which creates a clone of the current object.


For code example you can click here.

Design Patterns Part I

Observer Pattern: This defines a one to many relationship between objects, such that if one object is modified, its dependent objects are to be notified automatically.

For code example you can click here.

Factory Pattern: Creates an object without exposing the creation logic to the client. This uses a class to handle the creation of an object.

For code example you can click here.

MVC Pattern: MVC(Model View Controller) uses separate application’s concerns. Model represents the object that contains the data. View represents the user interface. Controller is the middleman who handles the interaction between the model and view by updating the view whenever the data changes. The controller keeps the model and view separate.

For code example you can click here.

Adapter Pattern: Works as a bridge between two incompatible interfaces. This involves a single class which is responsible to join functionalities of independent or incompatible interfaces.

For code example you can click here.

SQL Must Know Questions

What are the different types of joins?

 What is the difference between CHAR and VARCHAR2 datatype in SQL?

Char has a fixed length, while Varchar uses variable lengths.

What is ACID property in a database?

ACID stands for Atomicity, Consistency, Isolation, Durability. It is used to ensure that the data transactions are processed reliably in a database system. 

Atomicity: Atomicity means that you guarantee that either all of the transaction succeeds or none of it does.

Consistency: This ensures that you guarantee that all data will be consistent. All data will be valid according to all defined rules.

Isolation: Guarantees that all transactions will occur in isolation. No transaction will be affected by any other transaction.

Durability: Durability means that, once a transaction is committed, it will remain in the system, even if there’s a system crash immediately following the transaction.

What is Normalization?

Normalization is the process of reorganizing data in a database to avoid redundancy of data.

What is Denormalization?

Denormalization is the process of reorganizing data in a database to add redundancy of data.

 What are Constraints?

Constraints are rules used to limit the type of data that can go into a table. A few examples are:

  • NOT NULL
  • CHECK
  • DEFAULT
  • UNIQUE
  • PRIMARY KEY
  • FOREIGN KEY

More Info:

https://database.guide/what-is-acid-in-databases/

https://www.techopedia.com/definition/1221/normalization

https://www.techopedia.com/definition/29168/denormalization

What is the connection Between JRE, JDK, and JVM?

JRE stands for java runtime environment. This is the part of the java development kit that contains a set of tools with the minimum requirement to execute a Java application.

In order for a software program to execute code, it needs a runtime environment to load class files, verify access to memory and retrieve system resources. The JRE specifically contains a Java class loader, which is responsible for loading classes and connecting them to the core Java class libraries.

The JRE acts as a software layer on top of an operating system that enforces uniformity and provides additional Java services, such as automatic memory.

JDK stands for java development kit. Is a software development environment used for developing Java application applets. The JDK includes a variety of tools that perform actions such as compiling source code into bytecode, packaging applications, spinning up Java virtual machines, and managing the runtime environment of Java applications.

JVM stands for java virtual machine. Is a virtual machine that enables a computer to run Java programs as well as programs written in other languages that are also compiled to Java bytecode. It also has the ability to optimize program memory.

For more information:

https://www.javatpoint.com/internal-details-of-jvm

https://www.theserverside.com/definition/Java-Runtime-Environment-JRE

https://www.theserverside.com/definition/Java-virtual-machine-JVM

What are the four principles of OOP?

When trying to remember the four principles of object oriented programming just think of APIE.

A is for Abstraction: Abstraction is a process of hiding the implementation details from the user, only the functionality will be provided to the user. In other words, the user will have the information on what the object does instead of how it does it.

P is for Polymorphism: Polymorphism stands for the phrase “many forms”. This allow for subclasses to define its own behavior of attributes inherited from its parent class. This involves method overloading and overriding.

Notice how the two child classes inherited the method Sum() from their parent class. Both child classes changed the behavior of the method to do something specifically for their class.

I is for Inheritance: Inheritance is the ability of creating a class from an existing class and acquire its parent’s class behavior. This allows classes to be re-usable and modular since you can reuse classes and reduce development time.

Notice how all the different types of vehicles can be generalized to one simple term vehicle. That’s considered the parent class and anything that fall underneath it are just different variations of vehicle which are known as the child classes.

E is for Encapsulation: Encapsulation it describes the idea of bundling data and methods that work on that data within one unit. Encapsulation is also known for data hiding since it allows you to mark variables as private, this means the variables of a class will be hidden from other classes and can be accessed only through the methods of their current class.

In the image you can’t have access to the variables but, you can have access to the methods that use those variables.

You may be wondering Abstraction and Encapsulation sounds like they are the same thing right?

When you think of encapsulation just imagine these two facts:

  • Declare the variables of a class private.
  • Provide public setters and getters methods to modify and view the variables values.

When you think of abstraction just imagine this scenario:

Abstraction refers to the idea of simplifying things enough so that the user just know that something works but doesn’t know the process of the things done in the background.

For example sending a text message, when you type a text and send the message. You don’t know the internal processing about the message delivery.

Abstraction lets you focus on what the object does instead of how it does it.

If you have any questions or want to add something new please write it down in the comment section.

Java Interview Questions

  1. Explain the difference between an interface and a abstract class?

Abstract class: Is a superclass that cannot be instantiated and is used to state or define general characteristics. An object cannot be created from a Java abstract class. The abstract class is declared using the keyword abstract. Subclasses extended from an abstract class have all the abstract class’s attributes.

Interface: is a blueprint of a class. It has static constants and abstract methods. There can only be abstract methods in the Java interface, not method body. The interface is declared using the keyword implements.

Abstract ClassInterface
Can extend another java class and implement multiple java interfaces.Can extend only java interfaces.
Can have a constructorCan’t have a constructor.
Can have both abstract and concrete methods.Can only have abstract methods.
Can have final, non final, static and non static variables.Can only have static and final variables.

For more information on Abstract class and Interface click on the hyperlink.

2) What is Polymorphism?

Polymorphism: is the ability of a method to do different things based on the object that it is acting upon. In other words is a feature that allows us to perform a single action in different ways.

Lets write an example:

class Animal{
   public void sound(){
      System.out.println("Animal is making a sound");   
   }
}
public class Cat extends Animal{
    @Override
    public void sound(){
        System.out.println("Meaow");
    }
    public static void main(String args[]){
    	Cat cat = new Cat();
    	cat.sound();
    }
}

The output of this code will be “Meaow”.

In the class Cat there is the syntax @Override. This tells the compiler that you intend to override the method from the superclass. The word extends is what allows the class Cat to inherit the Animal class methods.

For more information on polymorphism you can click here.

If you have any questions feel free to leave a comment.

Introduce Yourself (Example Post)

This is an example post, originally published as part of Blogging University. Enroll in one of our ten programs, and start your blog right.

You’re going to publish a post today. Don’t worry about how your blog looks. Don’t worry if you haven’t given it a name yet, or you’re feeling overwhelmed. Just click the “New Post” button, and tell us why you’re here.

Why do this?

  • Because it gives new readers context. What are you about? Why should they read your blog?
  • Because it will help you focus you own ideas about your blog and what you’d like to do with it.

The post can be short or long, a personal intro to your life or a bloggy mission statement, a manifesto for the future or a simple outline of your the types of things you hope to publish.

To help you get started, here are a few questions:

  • Why are you blogging publicly, rather than keeping a personal journal?
  • What topics do you think you’ll write about?
  • Who would you love to connect with via your blog?
  • If you blog successfully throughout the next year, what would you hope to have accomplished?

You’re not locked into any of this; one of the wonderful things about blogs is how they constantly evolve as we learn, grow, and interact with one another — but it’s good to know where and why you started, and articulating your goals may just give you a few other post ideas.

Can’t think how to get started? Just write the first thing that pops into your head. Anne Lamott, author of a book on writing we love, says that you need to give yourself permission to write a “crappy first draft”. Anne makes a great point — just start writing, and worry about editing it later.

When you’re ready to publish, give your post three to five tags that describe your blog’s focus — writing, photography, fiction, parenting, food, cars, movies, sports, whatever. These tags will help others who care about your topics find you in the Reader. Make sure one of the tags is “zerotohero,” so other new bloggers can find you, too.

Design a site like this with WordPress.com
Get started