Solved

an API like thing

Posted on 2000-05-12
5
165 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 7

Accepted Solution

by:
Sasha_Mapa earned 200 total points
ID: 2805938
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
ID: 2806760
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
ID: 2806871
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
ID: 2807006
Or youneed to 'extends' the Calc class, so your new class will inherit the methods in Calc.
0
 

Author Comment

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

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

737 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