Loading...
Logo
Processing Forum

package

in Contributed Library Questions  •  1 year ago  
Hi, Im taking a look to physics library
 
 
This is an excerpt of the code:
 

package

traer.physics;

public

class Particle

{

protected Vector3D position;

....
 
I dont know what a package is.
 
After there is this code:
 
import traer.physics.*;
 
I thought that in import command there I had to put the file name, that in this case is traer_physics_lib_src but in this case there is the name of the package...is a bit of a mess for me

Replies(3)

Re: package

1 year ago
This is the source code for the library, which is developed in pure Java, and requires some more code than standard Processing sketches...

For some reason, the first line was split across two lines...
It actually looks like this:

Copy code
  1. package traer.physics;

All this does is declare that the source file is part of the package " traer.physics"...
This declaration is necessary in any Java program.

That sounds incredibly redundant, so: A package is an organization of Java source files... for example, processing.core is a package, as is processing.opengl.

The import statement merely imports another part of the library... it is probably necessary. Since the required classes are stored in a different package, the import statement is required.

Re: package

1 year ago
So, if Im creating my own library in processing, simply I can omit this line:
 
  1. package traer.physics;
and I use import like this:
 
import physics.*;
 
With physics being the name of the folder. It´s all correct?

Re: package

1 year ago
If you're creating your own library that requires the physics library, then you need a package declaration for your library and an import statement importing the physics library... so, basically, yes... the library template and examples make it quite easy to figure out.