Results 1 to 10 of 10
  1. #1
    shaggyoo7 is offline Member
    Join Date
    Jan 2009
    Posts
    19
    Rep Power
    0

    Default how to save Interface (file extension)

    When we write an interface what file extension is to be used to save the file

  2. #2
    Join Date
    Dec 2008
    Location
    Italy
    Posts
    79
    Rep Power
    0

    Default

    .java as usual...

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Yes the file extension must be same as ordinary Java file, that's *.java. Name must be same as the interface name. At compile time, compiler check that class or interface name, and compiler identify Java related sources using *.java extension.

    Simply on following two lines, as an example

    class MyClass
    This is a class, compiler found the class key-word.

    interface MyInterface
    This is an interface.

    Did you read any materials related to Java interfaces?

  4. #4
    shaggyoo7 is offline Member
    Join Date
    Jan 2009
    Posts
    19
    Rep Power
    0

    Default

    Yes i read but was a bit confused and as u said ive saved the interface in the correct way but i am getting a problem compiling the class file that has implementerd the interface have a look.
    --------------------------------------------------------------------------
    package Shapes;
    public class Circle implements Shape
    {
    private double area;
    public double area(double rad)
    {
    area = 3.14159 * rad * rad;
    return area;
    }
    }
    --------------------------------------------------------------------------
    public interface Shape
    {
    double area(double a);
    double area(double a, double b);
    }
    --------------------------------------------------------------------------
    D:\Program Files\Java\jdk1.7.0\bin\Shapes>javac Shape.java

    D:\Program Files\Java\jdk1.7.0\bin\Shapes>javac Circle.java
    Circle.java:2: cannot find symbol
    symbol: class Shape
    public class Circle implements Shape
    ^
    1 error

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    First you must implement all abstract methods of the interface in your class.

    Second, you cannot have two public sources in the same file. That's nothing to do with interface, that's Java basis.

  6. #6
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    6

  7. #7
    shaggyoo7 is offline Member
    Join Date
    Jan 2009
    Posts
    19
    Rep Power
    0

    Default

    Hey thanks i got it ill make the necessary changes.

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Quote Originally Posted by mtyoung View Post
    using meaningful variable name is important
    That's really important I think, but that's the lots of programmers missed.

  9. #9
    darrenabc is offline Member
    Join Date
    Jan 2009
    Posts
    5
    Rep Power
    0

    Default

    i think it will be .java

  10. #10
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

Similar Threads

  1. Read file from URL and save to FTP
    By nitinmukesh in forum Networking
    Replies: 6
    Last Post: 06-03-2012, 08:45 PM
  2. upload and save file
    By chennee72 in forum JavaServer Pages (JSP) and JSTL
    Replies: 4
    Last Post: 06-29-2011, 02:27 PM
  3. File Extension Filter
    By heartysnowy in forum New To Java
    Replies: 9
    Last Post: 10-09-2010, 01:33 PM
  4. Replies: 0
    Last Post: 04-05-2008, 10:13 AM
  5. Regex for file extension
    By gapper in forum New To Java
    Replies: 1
    Last Post: 01-31-2008, 03:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •