?
Solved

an API like thing

Posted on 2000-05-12
5
Medium Priority
?
167 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 800 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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 …
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses
Course of the Month13 days, 21 hours left to enroll

801 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