Solved

an API like thing

Posted on 2000-05-12
5
164 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
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
java jdbc batch example 8 41
use lov values 2 64
spring jars download 1 35
mysql jsp example issue 32 51
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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 learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

830 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