Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Java Question  RSS feed

 
P Jain
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the difference between Package and Interface.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

I'm moving your question to Java in General (Beginner), where it will be more on-topic and likely to get an answer.
 
Marilyn de Queiroz
Sheriff
Posts: 9080
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An Interface is more like (not exactly) an Abstract Class. Its methods are not implemented and its variables are constants.

A Package is more like (not exactly) a Path to the class. For example, if a class is in a package com.javaranch.common, it may be found in a directory structure like this:
 
Paul Santa Maria
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another way of looking at it is like this:

1. A "package" is a namespace. It lets you distinguish between two different classes from two different places that both happen to have the same name (e.g. "com.javaranch.common.Print" vs. "org.someneattoolkit.print").

2. An "interface" is a contract. Any class which "implements" a given interface "promises" to provide each of the methods - with exactly the specified arguments - to any client which invokes it.

'Hope that helps .. PSM
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!