Posts

Design Patterns -- part 2

Criticism about Design Patterns: Failed to provide clear criteria for when to use what pattern, and explain the criteria for the rules or choices (such as cost/benefit analysis of find & change costs or something from  Category Metrics ). Focused mostly on  Systems Software , mostly ignoring database and  Crud Screen -centric applications. Usage of Design Patterns: Design patterns have two usages in Software development lifecycle: 1.      Providing common platform for developers using standard terminologies and are specific to particular scenario. For example, a prototype design pattern will be creating a prototype design which creates clone of actual object to be used in the program. 2.      Learning these design patters helps inexperienced developers to learn software development in a fast and easy way. These design patterns are being used from longer period of time and provide best solution to maximum of the problems in programming.

Design Patterns -- part 1

Design patterns are the best practices used by Developers while working on project. These give design level solutions for recurring problems that software engineers come across often. This helps developers to tackle these problems and design a solution well using patterns. These patterns help other developers so that they do not need to waste time in those problems which were faced by those developers.  What is   Gang Of Four (GOF)? There is a band called Gang Of Four (band) but here we will not be talking about band. We will talk about the authors of Gang of Four design patterns. In 1994, four authors Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides published a book titled Design Patterns - Elements of Reusable Object-Oriented Software Source:  Wikipedia Patterns are formalized  best practices  that the programmer can use to solve common problems when designing an application or system. Object-oriented  design patterns typically show relationships and  interactions

Error vs Exception in java

Image
Error vs Exception An Error "indicates serious problems that a reasonable application should not try to catch." while An Exception "indicates conditions that a reasonable application might want to catch." Error and Exception both are extending Throwable but usually Error is thrown by JVM in a scenario which is fatal and it is not possible for the application to recover from that error. For instance OutOfMemoryError . Even application can raise an Error but its just not a good practice. Application should use checked exceptions for recoverable conditions and runtime exceptions for programming errors.Error is something that most of the time you cannot handle it but exception was meant to give you an opportunity to do something with it. like try something else or write to the log. Exception is generally divided into two categories e.g. checked and unchecked Exceptions. 1.     Checked Exception has special place in Java programming langu

Tight vs Loose Coupling

Tight vs Loose Coupling In object oriented design, the amount of coupling refers to how much the design of one class depends on the design of another class. In other words, how often do changes in class A force related changes in class B? Tight coupling means the two classes often change together, loose coupling means they are mostly independent. In general, loose coupling is recommended because it's easier to test and maintain. Tight coupling Think of your skin. It's stuck to your body. It fits like a glove. But what if you wanted to change your skin colour from say white to black? Can you imagine just how painful it would be to peel off your skin, dye it, and then to paste it back on etc? Changing your skin is difficult because it is tightly coupled to your body. You just can't make changes easily. You would have to fundamentally redesign a human being in order to make this possible. Key Point #1 In other words, if you want to change the skin, you would also

How Method Overloading Helping in Java - Part 9

I'm sharing my experience with you as these are the questions which have been asked to me while interviewing on java profile. Where have u observed method overloading helped us in java? Where have you seen in java default classes using method overloading? We need method overloading because if we have multiple arguments for add method and we have to create multiple methods in that case we will be confused which method to call to perform specific addition. Example: class   PrintOverloading1 {      public   void  show( char  c)     {           System . out .println(c);     }      public   void  show( char  c,  int  number)      {           System . out .println(c +  " " + number);     }    public   void  show( char  c,  String s )      {           System . out .println(c +  " " + s);     } } class   demo1 {     public   static   void  main( String  args[])    {         PrintOverloading1 obj  =  new   PrintOv

Access Modifiers in java

Access Modifiers in Java Access to classes is controlled using Access Modifiers aka ( Access Specifiers, Visibility Specifiers ) in java. These are used to regulate access to classes, fields and methods in java. Using access modifiers you can control the access of variables, methods with in a class. Java provides number of access modifiers to control the access for class as well as the fields, methods and constructors in your classes. We have 4 types of access modifiers in java which are explained below:- Default: Visible to the package, the default. No modifiers are needed, no keyword is required. Private: Visible to the class only. Public: Visible to the world. Protected: Visible to the package and all subclasses. Default: We do not have any default specifier in Java. It provides Default specifier which is used where no access modifier is present. Using this you can access class, methods or fields which belongs to same package, but not from outside

Important Java Interview Questions - Part 7

I'm sharing my experience with you as these are the questions which have been asked to me while interviewing on java profile. Where have u used abstraction and encapsulation in your project? We use encapsulation everywhere in java like when we create a class in java we are using encapsulation. Abstraction we use when we create abstract class or interface using abstraction in java. " Encapsulation  is to hide the variables or something inside a class, preventing unauthorized parties to use. So the public methods like getter and setter access it and the other classes call these methods for accessing" Using Encapsulation we achieve  “Data Hiding, Information Hiding”  in java. Encapsulation binds data (attributes and methods) and the code in the form of a class. Encapsulation is the technique of making the fields in a class private and providing access to the fields via public methods. Encapsulation provides “ access control ” through which we can control