Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>When to Use Separate package in java:</p> <p><em>Lets us take an example in favor of this question.</em></p> <p>Suppose you have an java program that deals with the database connectivity also it need two separate threads to perform this task and also it need some arraylist to store the database information that has been retrieved from the database. in this case it's very easy to use package.If I need database package I know that where it it I will simply import my <code>java.sql package</code></p> <p>If I have to handle with thread I will use <code>java.lang.Thread</code> package. And I have to deal with arraylist then I will use my <code>java.util</code> package. Think how it is simple to just import package based on your need.</p> <blockquote> <p>Moreover suppose you implement your own package that performs addition ,multiplication,subtraction of two numbers.that what you will do can create a simple package that will deal with these operations.and everywhere you can use this package where ever you will be in need of those operations then you will need not to write code for these operations every time in your application.</p> </blockquote> <p>e.g </p> <pre><code>package Arithmetic; public class Operations { public long sum(long a ,long b) { return a+b; } public long subtraction(long a,long b) { return a-b; } public long multiply(long a,long b) { return a*b; } } </code></pre> <p>Now I can use this package into by another class </p> <pre><code> import Arithmetic.*; class Demo { public static void main(String...k) { Operations op=new Operations(); System.out.println(op.sum(12,23)); System.out.println(op.multiply(23,23)); System.out.println(op.subtraction(342,23)); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload