Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

packages..  RSS feed

 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how do you make a package?

i tried

public package A
{
// then all my classes

}


it's not on a test or anything, im still in csII

I just want to know..

thanks!

-Justin-
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Packages are declared before anything in your class, and outside of the class.



This makes SomeClass belong to the package com.test.

com.test.SomeClass
 
Yuriy Zilbergleyt
Ranch Hand
Posts: 429
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A package can be thought of the directory path to the class file when taken from the root of the classpath. So if your class path starts at "./", and the class is in the directory "./abc/def", then the class is in the package "abc.def". At the top of the .java file you must declare this with "package abc.def".
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sweet thanks...


I don't understand the whole..


So if your class path starts at "./"


what does this mean?

and if i did name my package such as:

package A;

class one
{}

i would have to do

class b extends A.one
{}
?

if they were in separate classes?

thanks

-Justin-
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh wait!!

or do i import my package like

import java.util.Scanner;

but instead.

import A.one;

-Justin-
 
Yuriy Zilbergleyt
Ranch Hand
Posts: 429
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Justin Fox:

oh wait!!

or do i import my package like

import java.util.Scanner;

but instead.

import A.one;

-Justin-


Yes, that would work. But packages are usually lowercase, while class names start with capital letters. You can also import all classes in package A through "import A.*"
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sweet man,
thanks


-Justin-
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!