Solved

an API like thing

Posted on 2000-05-12
5
163 Views
Last Modified: 2010-04-01
how if I am useing jdk1.1.8 on UNIX do I
make a program I make to be imported?

Say I have a program writen, witch takes
3 pices of data in, goes and dos its thing
and returns a result to the calling program

so in a program I would only need to say

import my.file.*
...
result = myfile(a, 10, go);
...

what would I need to be defineing the progema
that dos all the work? what would this look like in code?

Thaks for any help
0
Comment
Question by:thedogeater
  • 2
  • 2
5 Comments
 
LVL 7

Accepted Solution

by:
Sasha_Mapa earned 200 total points
Comment Utility
Umm, I'm really confused about what you want, but here is how you write a class to belong to a package:

------ Calc.java -------

package com.mypackage.calculations;

public class Calc{

  public static int calculate(int x, int y){
    return 2*x+y;
  }

}

---------- End ---------

The Calc.java file must be in a com\mypackage\calculations directory and you must compile it from the directory which the com directory is in with "javac com\mypackage\calculations\Calc.java"


0
 

Author Comment

by:thedogeater
Comment Utility
I am sorry to comfuse but I too learn english :+)
So if I make the Calc class as you say
I will call it by

import com.mypackage.calculations.*;

calculate(1, 10);

kind of thing ye. so com.mypackage.calcualtios
must alos be in my CLASSPATH yes?


Thanks for the help
0
 
LVL 7

Expert Comment

by:Sasha_Mapa
Comment Utility
1. You will have to call it with Calc.calculate(1,10)... The calculate method is a static class method. If you define it non-static you will have to first instantiate the Calc class:
Calc myCalculator = new Calc();
int result = myCalculator.calculate(1,10);

2. You will need to put the directory in which the com directory is in in your CLASSPATH...
0
 

Expert Comment

by:prl
Comment Utility
Or youneed to 'extends' the Calc class, so your new class will inherit the methods in Calc.
0
 

Author Comment

by:thedogeater
Comment Utility
thank you for the helping I was not getting it working
without you help
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now