/ Forside/ Teknologi / Udvikling / Java / Spørgsmål
Login
Glemt dit kodeord?
Brugernavn

Kodeord


Reklame
Top 10 brugere
Java
#NavnPoint
molokyle 3688
Klaudi 855
strarup 740
Forvirret 660
gøgeungen 500
Teil 373
Stouenberg 360
vnc 360
pmbruun 341
10  mccracken 320
package making
Fra : Abdis
Vist : 495 gange
40 point
Dato : 04-02-05 21:04

Hi who can help me on how to build a package i don't have completely any idea of how to make it i will be glad if there is someone to help me



thnks

 
 
Kommentar
Fra : molokyle


Dato : 04-02-05 21:17

Package ? Do you mean *jar files ?

http://java.sun.com/docs/books/tutorial/jar/

Here is some more information on packages : http://www.cs.unc.edu/Courses/jbs/lessons/java/java_jars/

Citat
Packages: Implementation
Implementation of a package is very easy. One simply includes the hierarchical name of the package along with the keyword, package, as the first statement in a program. For example:

package edu.jbs.ooc.ui;

import java.net.*;
import java.io.*;
import java.sql.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

import com.ibm.ejs.ns.jndi.*;
import javax.naming.*;
import javax.ejb.*;

import com.oreilly.servlet.multipart.*;

public class UIServlet extends javax.servlet.http.HttpServlet {
In some other program, if the edu.jbs.ooc.ui package had been imported, UIServlet could be referred by that name alone so long as it was unambiguous. But it could also be referred to as edu.jbs.ooc.ui.UIServlet if there was any question of the particular class.

Another implication of package is the additional scope parameter protected, to go along with public and private. As one may recall, public methods (and variables) can be referenced from any object that can "see" the object in which they are defined. Private methods and variables can only be referenced from within the class where they are defined. Protected methods and variables fall somewhere in-between -- namely, they can be referenced from any object whose class is within the same package.


</MOLOKYLE>

Kommentar
Fra : Abdis


Dato : 04-02-05 21:28

Hi I want to make my own package for a future use f.exmalple i want to put it some methods , which i will use it in the future time and its java package i want to build



thnks

Kommentar
Fra : justuniverse


Dato : 04-02-05 21:28

I guess we are talking coding Java-classes?

If You have a group of classes, that should belong to the same package you should write it in Your code, and place the java-code in similar folders on harddisk.

If we say you want to build a package called kandu.package.example and want the classes KanduInvironment, Question and Answer in that package, You should write in every class as follows: (And they should be placed in the same folder on the harddisk. The folder should be called .\kandu\package\example

Kode
package kandu.package.example;

pubic class KanduInvironment {

public KanduInvironment() {
//code here....
}

public put(Question quest) {
//code here.....
}
}


//New class
package kandu.package.example;

pubic class Question {

public Question (String question) {
//code here....
}

public void putAnswer(Answer answ) {
//code here...
}
}

//New class
package kandu.package.example;

pubic class Answer {

public Answer (String answer) {
//code here....
}
}

//Test class
import kandu.package.example;

pubic class TestClass {

public static void main (String[] args) {
KanduInvironment inv = new KanduInvironment();
Question quest = new Question("How do I make packages?");
Ansver ansv = new Answer("Like this...");

quest.putAnswer(answ);

inv.put(quest);

System.out.println(inv.toString());
}
}


The methods in the example you have to code yourself.

Hope it did help?

Kommentar
Fra : Abdis


Dato : 04-02-05 21:34

thnks that is the answer of my question but I can't make code for exmple u said code here but i can't understand that but thnks u gave me an excellent answer thnks

Kommentar
Fra : Abdis


Dato : 04-02-05 21:49

please tell a littel bit more of here pubic class KanduInvironment {

public KanduInvironment() {


//code here....what this code will look like just a very simple example if u have a time thnks


Kommentar
Fra : justuniverse


Dato : 04-02-05 21:53

Sorry... should be:

Kode
//Test class
import kandu.package.example.*;


Kommentar
Fra : Abdis


Dato : 04-02-05 21:56

thnks but if u can give me a simple example where u have a complet package code will be helpful



thnks

Kommentar
Fra : justuniverse


Dato : 04-02-05 22:04

Well.... we have to go in details with the KanduInvironment class then. The intire class could look like this:
Kode
package kandu.package.example;

import java.util.*;

pubic class KanduInvironment {

private Question localQuestion = null;

public KanduInvironment() {
//code here.... (Actually no code needed right here...)
}

public put(Question quest) {
//code here.....
//could be just this line:

localQuestion = quest;
}

//This method is new to the example, but exists in superclass Object. Her we override:
public String toString() {
StringBuffer buf = new StringBuffer();

buf.append("This is an example of the print of a question and an answer in the KanduInvironment:\n");
buf.append(localQuestion.toString());

return buf.toString();
}
}


Kommentar
Fra : justuniverse


Dato : 04-02-05 22:16

And the other classes similar:

Kode
//Class Answer is in the same package as this class so we don´t need to import....

public class Question {

private String quest = null;
private Answer answer = null;

public Question (String question) {
//code here....
//Could be:

quest = question;
}

public void putAnswer(Answer answ) {
//code here...
//Could be:
answer = answ;
}

public String toString() {
String returnValue = "Question: " + quest + "\n" + "Answer: " + answer.toString();

return returnValue;
}
}

//New class
package kandu.package.example;

public class Answer {

private String answ = null;

public Answer (String answer) {
//code here....
//Could be:

answ = answer;
}

public String toString() {
return answer;
}
}


I didn´t compile it, so I don´t know if it works

Kommentar
Fra : Abdis


Dato : 04-02-05 22:22

thnks very much indeed it s a helpfull hand u gave me tonight thnks indeed I will be proud of u really thnks
and I will continou to ask questions here as I pleased here thnks.

Accepteret svar
Fra : justuniverse

Modtaget 50 point
Dato : 04-02-05 22:24

Your welcome. Remember to close this quetion by accepting the answer

Godkendelse af svar
Fra : Abdis


Dato : 04-02-05 22:43

Tak for svaret justuniverse.
                        

Du har følgende muligheder
Eftersom du ikke er logget ind i systemet, kan du ikke skrive et indlæg til dette spørgsmål.

Hvis du ikke allerede er registreret, kan du gratis blive medlem, ved at trykke på "Bliv medlem" ude i menuen.
Søg
Reklame
Statistik
Spørgsmål : 177577
Tips : 31968
Nyheder : 719565
Indlæg : 6409071
Brugere : 218888

Månedens bedste
Årets bedste
Sidste års bedste