Posts

Showing posts from March, 2015

Difference between Comparable and Comparator?

Comparable A comparable object is capable of comparing itself with another object. The class itself must implements the java.lang.Comparable interface in order to be able to compare its instances. Comparator A comparator object is capable of comparing two different objects. The class is not comparing its instances, but some other class’s instances. This comparator class must implement the java.util.Comparator interface. Comparator provides a way for you to provide custom comparison logic for types that you have no control over. Comparable allows you to specify how objects that you are implementing get compared. Obviously, if you don't have control over a class (or you want to provide multiple ways to compare objects that you do have control over) then use Comparator. Otherwise you can use Comparable. Other Sources: http://www.digizol.com/2008/07/java-sorting-comparator-vs-comparable.html http://www.programcreek.com/2011/12/examples-to-demonstrate-comparable-vs-

What are Interfaces and When to use Interfaces?

Interfaces: A good place to look at Java Interfaces would be the collections framework. java.util.List //interface java.util.ArrayList //Concrete class java.util.LinkedList //Concrete class So you can write code like this: List l = new ArrayList(); l.add(..) //do something else. If in future you want to change the implementation with say LinkedList or you own AwesomeList which implements List interface, all you have to do is change the very first line to: List l = new MyAwesomeList(); or List l = new LinkedList(); The rest of the code would follow through. More Examples: Use interfaces to define an application programming contract (blueprint, interface) which "3rd-party" vendors have to fully adhere and implement. This way the endusers can just code against the API contract and easily switch of the concrete implementation "under the hoods" without changing the code. The JDBC API is an excellent example. It exist of almost only interfaces

What is Docker? Why it is popular?

Image
Docker, a new container technology, is hotter than hot because it makes it possible to get far more apps running on the same old servers and it also makes it very easy to package and ship programs. Here's what you need to know about it. All the noise is happening because companies are adopting Docker at a remarkable rate. At OSCon in July, I ran into numerous businesses that were already moving their server applications from virtual machines (VM) to containers. Indeed, James Turnbull, Docker's VP of services and support, told me at the conference that three of the largest banks that had been using Docker in beta were moving it into production. That's a heck of a confident move for any 1.0 technology, but it's almost unheard of in the safety-first financial world. At the same time, Docker, an open-source technology, isn't just the darling of Linux powers such as Red Hat and Canonical. Proprietary software companies such as  Microsoft have also embraced D

Document Type Definition (DTD)

As should you know by now, XML by itself only serves to deliver data. You must provide other files to format and validate the XML code. This is where the DTD and schema come into play. The advancement of technology has provided many ways to validate XML. The DTD is just one. Document Type Definitions provide rules the computer can follow when processing the code. The DTD and schema are the precursors to XSL. Although still used in some formats, learning to write these files is not a requirement to create XML platforms, but it is indispensable to know what they are and how they function. These are terms you will stumble across in your studies frequently and understanding the basic design will be an advantage.What is a DTDThis is an explanation of document type definitions and the role they play in XML design. DTD code comes in two forms, internal and external. This article provides a description and explanation of how DTD files work.The DTD: Elements, Entities, Attributes, and Notation

XML Schema (XSD)

When beginning a study of XML, some may encounter an unfamiliar term that leaves them asking the question, “What is an XML schema (XSD)?” An XML schema is a road map for the XML document similar to a Document Type Definition (DTD). Created by the World Wide Web Consortium (W3C), schemas describe the elements and map out the presentation and nesting of XML documents. Essentially, the schema enables all applications to understand the flow of the page and validate the elements. Why Use An XML Schema? Step away from websites for a minute and consider house building. If the plumber, electrician and contractor all do their own thing, the result is a building with an uneven line, sinks in the bedroom and cable hookups in the bathroom. That does not happen because the architect draws a diagram that maps out the basic structure. With a blueprint, there is no guesswork. The plumber understands where the sinks go, and the electrician knows what rooms need what type of wiring. A schema is the

Difference between XML Namespace (xmlns) and XML Schema (XSD)?

XML namespaces are used for providing uniquely named elements and attributes in an XML document. XML Schema is an XML-based alternative to DTD.It describes the structure of an XML document. A schema describes the structure of the XML: tag names, parent/child relationships, cardinality, types, restrictions, etc. Namespaces are more like packages in Java: They give you a way to distinguish your tags from others. You can combine XML streams together. If you and someone else both have a <name> tag, you can have namespace foo, someone else can have namespace bar, and you can tell the difference with <foo:name> and <bar:name>.

equals() and hashCode()

From the article Override equals and hashCode in Java: Default implementation of equals() class provided by java.lang.Object compares memory location and only return true if two reference variable are pointing to same memory location i.e. essentially they are same object. Java recommends to override equals and hashCode method if equality is going to be define by logical way or via some business logic: example: many classes in Java standard library does override it e.g. String overrides equals, whose implementation of equals() method return true if content of two String objects are exactly same Integer wrapper class overrides equals to perform numerical comparison etc.

Understanding JavaScript Prototype

Function is its own constructor (i.e. "parent"). Function.constructor;  // function Function() { [native code] } Normally you can't do what you're doing. For example, this won't work: f = function () {}; f.prototype.a = 5; f.a;  // undefined This kind of thing only works if you use a function as a constructor, like so: f = function () {}; f.prototype.a = 5; g = new f(); g.a;  // 5 But Function is weird, it is the constructor for all functions and is also a function itself, so it templates its properties off its own prototype. Hence you can call Function.method() in your code. For more info about prototypal inheritance visit  http://javascript.info/tutorial/inheritance Source: Stackoverflow.

Introduction to Object Oriented JavaScript.

JavaScript is object-oriented to its core, with powerful, flexible  OOP  capabilities. This article starts with an introduction to object-oriented programming, then reviews the JavaScript object model, and finally demonstrates concepts of object-oriented programming in JavaScript. JavaScript review If you don't feel confident about JavaScript concepts such as variables, types, functions, and scope you can read about those topics in  A re-introduction to JavaScript . You can also consult the JavaScript Guide . Object-oriented programming Object-oriented programming is a programming paradigm that uses abstraction to create models based on the real world. It uses several techniques from previously established paradigms, including modularity, polymorphism, and encapsulation. Today, many popular programming languages (such as Java, JavaScript, C#, C++, Python, PHP, Ruby and Objective-C) support object-oriented programming (OOP). Object-oriented programming may be seen as the