logging in or signing up INTERFACE AND PACKAGES kapil99 Download Post to : URL : Related Presentations : Share Add to Flag Embed Email Send to Blogs and Networks Add to Channel Uploaded from authorPOINT lite Insert YouTube videos in PowerPont slides with aS Desktop Copy embed code: (To copy code, click on the text box) Embed: URL: Thumbnail: WordPress Embed Customize Embed The presentation is successfully added In Your Favorites. Views: 449 Category: Education License: All Rights Reserved Like it (1) Dislike it (0) Added: November 17, 2010 This Presentation is Public Favorites: 0 Presentation Description No description available. Comments Posting comment... Premium member Presentation Transcript Slide 1: INTERFACES AND PACKAGES IN JAVA Slide 2: INTERFACE INTRODUCTION Java does not support ‘Multiple Inheritance’ , but the difficulty and complexities of multiple inheritance in the language leads to an alternate approach known as ‘Interface’ to support the concept of multiple inheritance. Interface is basically a kind of class. It also contains methods and variables like classes but with a major difference . The difference is that interface define only abstract method and final field. It is the responsibility of the class that implements an interface to define the code for implementation of these methods. Slide 3: INTERFACE DECLARATION The basic syntax for declaring an interface looks similar to the syntax used for defining a java class: interface InterfaceName { StaticVariables; AbstractMethods; } Where interface ->keyword , InterfaceName->identifier, StaticVariables are declared as follows , static final type variableName=value; Methods declarations will contain only a list of methods without any body statements which should be declared as follows , returntype methodName(argument list); EXAMPLE:- Interface Item { static final int itemno=1000; static final string itemName=“car”; void display(); } Slide 4: INTERFACE IMPLEMENTATION Interface are used as super-classes whose properties are inherited by classes. It is therefore necessary to create a class that inherits the given interface . In this declaration, the className implements InterfaceName. class className implements InterfaceName { body of class; } In more generalized form, a class extend another class while implementing interface. class className extends superclassName implements interface1,interface2,interfacen { body of class; } NOTE:-Interface can also be extended. Interface name2 extends name1 { body of class; } Slide 5: PACKAGES INTRODUCTION Packages are java’s way of grouping a variety of classes and interfaces together. Packages are nothing but containers for classes. ADVANTAGES:- 1. Classes can be reused. 2.2 classes in 2 different package can have same name . 3.Provides security. 4.Provides way for separate design from coding. Packages are of 2 types:- A> Java API packages. B> Defined packages. Slide 6: JAVA API PACKAGES It provides a large number of classes grouped together into different packages according to its functionality. DIAGRAM:- java util lang awt net io applet Slide 7: JAVA USERDEFINED PACKAGE The following points should be remembered while creating a package: Declare the package at the beginning of a file . Define the class that is to be put in the package and declare it public. Create a subdirectory under the directory where the main source files are stored. Store the listing as the classname .java file in the subdirectory created. Compile the file . This creates .class file in the subdirectory. EXAMPLE:- package firstpackage; public class A { body of class; } continued………. Slide 8: ACCESSING A PACKAGE:- Through the import statement as similar to accessing of inbuilt packages. import packagename.*; example:- import firstpackage.*; NOTE:- The ‘*’ will import all public classes i.e. hidden classes. In this case if the user wants to hide some classes from accessing from outside of the package , should declare such classes as ‘not public’. Example:- package p1; Public class x { //public class , available outside } Class y { //not public , hidden } Importing package is like including c/c++ header files. Slide 9: THANK YOU!!!!!!! You do not have the permission to view this presentation. In order to view it, please contact the author of the presentation.
INTERFACE AND PACKAGES kapil99 Download Post to : URL : Related Presentations : Share Add to Flag Embed Email Send to Blogs and Networks Add to Channel Uploaded from authorPOINT lite Insert YouTube videos in PowerPont slides with aS Desktop Copy embed code: (To copy code, click on the text box) Embed: URL: Thumbnail: WordPress Embed Customize Embed The presentation is successfully added In Your Favorites. Views: 449 Category: Education License: All Rights Reserved Like it (1) Dislike it (0) Added: November 17, 2010 This Presentation is Public Favorites: 0 Presentation Description No description available. Comments Posting comment... Premium member Presentation Transcript Slide 1: INTERFACES AND PACKAGES IN JAVA Slide 2: INTERFACE INTRODUCTION Java does not support ‘Multiple Inheritance’ , but the difficulty and complexities of multiple inheritance in the language leads to an alternate approach known as ‘Interface’ to support the concept of multiple inheritance. Interface is basically a kind of class. It also contains methods and variables like classes but with a major difference . The difference is that interface define only abstract method and final field. It is the responsibility of the class that implements an interface to define the code for implementation of these methods. Slide 3: INTERFACE DECLARATION The basic syntax for declaring an interface looks similar to the syntax used for defining a java class: interface InterfaceName { StaticVariables; AbstractMethods; } Where interface ->keyword , InterfaceName->identifier, StaticVariables are declared as follows , static final type variableName=value; Methods declarations will contain only a list of methods without any body statements which should be declared as follows , returntype methodName(argument list); EXAMPLE:- Interface Item { static final int itemno=1000; static final string itemName=“car”; void display(); } Slide 4: INTERFACE IMPLEMENTATION Interface are used as super-classes whose properties are inherited by classes. It is therefore necessary to create a class that inherits the given interface . In this declaration, the className implements InterfaceName. class className implements InterfaceName { body of class; } In more generalized form, a class extend another class while implementing interface. class className extends superclassName implements interface1,interface2,interfacen { body of class; } NOTE:-Interface can also be extended. Interface name2 extends name1 { body of class; } Slide 5: PACKAGES INTRODUCTION Packages are java’s way of grouping a variety of classes and interfaces together. Packages are nothing but containers for classes. ADVANTAGES:- 1. Classes can be reused. 2.2 classes in 2 different package can have same name . 3.Provides security. 4.Provides way for separate design from coding. Packages are of 2 types:- A> Java API packages. B> Defined packages. Slide 6: JAVA API PACKAGES It provides a large number of classes grouped together into different packages according to its functionality. DIAGRAM:- java util lang awt net io applet Slide 7: JAVA USERDEFINED PACKAGE The following points should be remembered while creating a package: Declare the package at the beginning of a file . Define the class that is to be put in the package and declare it public. Create a subdirectory under the directory where the main source files are stored. Store the listing as the classname .java file in the subdirectory created. Compile the file . This creates .class file in the subdirectory. EXAMPLE:- package firstpackage; public class A { body of class; } continued………. Slide 8: ACCESSING A PACKAGE:- Through the import statement as similar to accessing of inbuilt packages. import packagename.*; example:- import firstpackage.*; NOTE:- The ‘*’ will import all public classes i.e. hidden classes. In this case if the user wants to hide some classes from accessing from outside of the package , should declare such classes as ‘not public’. Example:- package p1; Public class x { //public class , available outside } Class y { //not public , hidden } Importing package is like including c/c++ header files. Slide 9: THANK YOU!!!!!!!