Skip to main content

Posts

Showing posts from December 30, 2018

Difference between Class and Interface

Java Programming   *Difference between Class and Interface                                                  Class 1.  The members of a class can be constant or variables.  2. The class definition can contain code for each of its methods. That is, the methods can be    abstract or non-abstract. 3. It can be instantiated by declaring objects. 4. It can use various access specifier like public,private or protected.                                                Interface     1. The members of an interface are always declared as constant, i.e. their values are final.  2. The methods in an interface are abstract in nature, i.e., there is no code associated with  ...

Interfaces

Java Programming Interfaces The interface keyword takes the abstract concept one step further. You could think of it as a “pure” abstract class. It allows the creator to establish the form for a class: method names, argument lists and return types, but no method bodies. An interface can also contain data members of primitive types, but these are implicitly static and final. An interface provides only a form, but no implementation.  An interface says:   “This is what all classes that implement this particular interface will look like.” Thus, any code that uses a particular interface knows what methods might be called for that interface, and that’s all. So the interface is used to establish a “protocol” between classes. The syntax for defining an interface is similar to creating a new class:   interface <InterfaceName>  {          // constant declarations, if any      ...

Abstract class in Java

Java Programming Abstract class in Java A class that is declared with abstract keyword, is known as abstract class. Before learning abstract class, let's understand the abstraction first. Abstraction  Abstraction is a process of hiding the implementation details and showing only functionality to the user. Ways to achieve Abstraction  There are two ways to achieve abstraction in JAVA 1. Abstract class (0 to 100%)  2. Interface (100%)  Example abstract class Bike  {      abstract void run();  } class Honda extends Bike  {    void run()  {  System.out.println("running safely..");  }       public static void main(String args[])  {     Bike obj = new Honda();    obj.run();     } } 

Wrapper Classes

Java Programming Wrapper Classes  As we know that, Collection cannot handle primitive data types.  It may be converted into object types by using the Wrapper classes. As the name says, a wrapper class wraps (encloses) around a data type and gives it an object appearance. Wherever, the data type is required as an object, this object can be used. Wrapper classes include methods to unwrap the object and give back the data type.