Questions tagged [java-package]

Packages are used in Java in-order to prevent naming conflicts, to control access, to make searching/locating and usage of classes, interfaces, enumerations and annotations easier etc. A Package can be defined as a grouping of related types(classes, interfaces, enumerations and annotations ) providing access protection and name space management

A package allows a developer to group classes (and interfaces) together. These classes will all be related in some way – they might all be to do with a specific application or perform a specific set of tasks. For example, the Java API is full of packages. One of them is the javax.xml package. It and its subpackages contain all the classes in the Java API to do with handling XML.

A package is a grouping of related types providing access protection and name space management. Note that types refers to classes, interfaces, enumerations, and annotation types. Enumerations and annotation types are special kinds of classes and interfaces, respectively, so types are often referred to in this lesson simply as classes and interfaces

  • Every class is part of some package.
  • All classes in a file are part of the same package.
  • You can specify the package using a package declaration:
    package name ;
    as the first (non-comment) line in the file.
  • Multiple files can specify the same package name.
  • If no package is specified, the classes in the file go into a special unnamed package (the same unnamed package for all files).
  • If package name is specified, the file must be in a subdirectory called name (i.e., the directory name must match the package name).
  • You can access public classes in another (named) package using: package-name.class-name You can access the public fields and methods of such classes using:

package-name.class-name.field-or-method-name

You can avoid having to include the package-name using:

import package-name.*;

For more tutorial see here.

96 questions
0
votes
0 answers

Eclipse imports these java projects incorrectly (main, site, test paradigm)

I encounter a few projects that have a set of folders in the src directory: main, site and test. A few levels under main eventually I encounter the com.x.x. package, all the files have package names that start with the com folder, not the main…
CQM
  • 42,592
  • 75
  • 224
  • 366
0
votes
2 answers

Listing abstract classes within a Java package

Is there any way to list all abstract classes within a java package? For example, in java.lang package.
Ricardo Cristian Ramirez
  • 1,194
  • 3
  • 20
  • 42
-1
votes
1 answer

Why do I get "The method createLL() is undefined for the type LinkedListUse" error when calling from same package in Java?

Class linkedListUse package linkedlists; public class LinkedListUse { public static void main(String[] args) { // TODO Auto-generated method stub Node head=createLL(); printLL(head); } } Class…
-1
votes
1 answer

Why are Spring libraries including same parent packages made seperate?

I've just noticed two different libraries sharing paths. Example is as follows. There are two seperate packages - spring-boot-actuator, spring-boot-actuator-autoconfigure. Packages included in these libraries share the same parent package or…
Now.Zero
  • 1,147
  • 1
  • 12
  • 23
-1
votes
1 answer

Can I publish apps on Google Play with different package names?

My question is not if I can upload two apps with the package names ..app and ..app2. (the app's name changes here) It is if I can upload 2 apps with the package names ..app and ..app on Google Play.…
-1
votes
1 answer

Java how can i create my own methods which are calling via dot operator

For example we have .toString() but we don't have .toStringAndTrim() or .toStringAndReplace(). So I want to create my own methods inside a library and when I import this library I want to access after dot operator. How can I do this in java? Is this…
gurkan
  • 509
  • 1
  • 4
  • 18
-1
votes
1 answer

package convention for java Springboot lightweight controllers?

We have the controllers already being used with many apis in the package com.mycomp.myapp.controllers The controllers developed are heavy, so planning to add light weight apis with minimum request parameters. confused between these…
sagar K
  • 3
  • 4
-1
votes
2 answers

Is there any way to define a private class in Java which only other classes in the same package can access it?

I've always had this question on top of my mind that why defining private classes within a package in Java is not possible like the way we can define it in a namespace in .Net. Let's say I have a ds package in my Java Project. I have two classes in…
moorara
  • 3,897
  • 10
  • 47
  • 60
-1
votes
1 answer

Android R file and Java Sub-package: R can not be resolved to a variable

To better organize my classes, I made a few sub-packages (that is an extension in the package's hierarchical name structure). But to my surprise I have been getting an R cannot be resolved to a variable for like every resource I am trying to use…
Solace
  • 8,612
  • 22
  • 95
  • 183
-1
votes
1 answer

MapReduce package error

//what Packages needed for these 3 programs??? how to combine this 3 program into one program?? how to do mapreduce using this 3 program in eclipse?? please help me to run this program successfully os : linux Exception Faced : The method…
Apk
  • 11
  • 2
-1
votes
4 answers

Receiving Java error "cannot find symbol" in MVC package

Sorry, I'm sure this is some rookie istake I'm making but I have a MVC pattern package which keeps returning this errors to me: ====================================== hrms.java:22: error: cannot find symbol hrmsModel HRMSModel = new…
dizzyone
  • 43
  • 7
-2
votes
1 answer

how to fix java package problem in vs code

# please help me to fix such thing. when I make a directory and inside such try to write java code this problem occurs. some time it does not give any error but when I run this code, this thing come to me Error: Could not find or load main class…
-2
votes
1 answer

Java OpenGL Syntax

i am new here and have a little problem. I included OpenGl into eclipse and tried to run a little test program and everything is working fine as it should, but i have a problem with the syntax. Here is a little example…
-2
votes
1 answer

Restructuring of package

Hi I am trying to restructure the package but with no luck. Suppose there are multiple packages in a project like: main.java.com.wms.package1 main.java.com.wms.package2 main.java.com.wms.package3 I want to restructure it in the below…
Pramod Bhat
  • 49
  • 1
  • 6
-2
votes
1 answer

Issue encountered executing Selenium Java code

To get started, you need to import following two packages: org.openqa.selenium.*- contains the WebDriver class needed to instantiate a new browser loaded with a specific driver org.openqa.selenium.firefox.FirefoxDriver - contains the FirefoxDriver…