Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
652 votes
30 answers
528k views

Can you find all classes in a package using reflection?

Is it possible to find all classes or interfaces in a given package? (Quickly looking at e.g. Package, it would seem like no.)
Jonik's user avatar
  • 81.2k
544 votes
6 answers
262k views

What is the convention for word separator in Java package names?

How should one separate words in package names? Which of the following are correct? com.stackoverflow.my_package (Snake Case using underscore) com.stackoverflow.my-package (Kebab Case using hyphens) ...
Jigar's user avatar
  • 9,271
477 votes
8 answers
299k views

javax vs java package

What's the rationale behind the javax package? What goes into java and what into javax? I know a lot of enterprise-y packages are in javax, but so is Swing, the new date and time api (JSR-310) and ...
Jaka Jančar's user avatar
  • 11.5k
306 votes
34 answers
1.8m views

How can I solve "java.lang.NoClassDefFoundError"?

I've tried both the examples in Oracle's Java Tutorials. They both compile fine, but at run time, both come up with this error: Exception in thread "main" java.lang.NoClassDefFoundError: ...
Jonathan Lam's user avatar
  • 17.3k
232 votes
7 answers
173k views

Are there best practices for (Java) package organization? [closed]

A little while ago, I saw a question answered here regarding the fine-grained organization of Java packages. For example, my.project.util, my.project.factory, my.project.service, etc. Are there best ...
Cyntech's user avatar
  • 5,532
211 votes
3 answers
66k views

How Do I Document Packages in Java?

In the Java APIs I can see Javadoc comments for packages. How/where do I place Javadoc comments to document a package?
jjnguy's user avatar
  • 138k
186 votes
9 answers
79k views

Making certain methods visible only to particular packages

I have two packages in my project: odp.proj and odp.proj.test. There are certain methods that I want to be visible only to the classes in these two packages. How can I do this? If there is no concept ...
Nick Heiner's user avatar
156 votes
5 answers
62k views

Java packages com and org

What are the meaning of the packages org and com in Java?
Gabriel's user avatar
  • 1,569
147 votes
7 answers
231k views

Package structure for a Java project?

Whats the best practice for setting up package structures in a Java Web Application? How would you setup your src, unit test code, etc?
mawaldne's user avatar
  • 3,989
128 votes
9 answers
186k views

The import android.support cannot be resolved

I am trying to run the code provided HERE I downloaded the code from their Github and imported into Android SDK, but it shows error at the lines import android.support.v4.app.FragmentActivity; ...
user13267's user avatar
  • 7,145
109 votes
4 answers
186k views

How to get current class name including package name in Java?

I'm working on a project and one requirement is if the 2nd argument for the main method starts with “/” (for linux) it should consider it as an absolute path (not a problem), but if it doesn't start ...
La bla bla's user avatar
  • 8,668
108 votes
3 answers
123k views

Java JUnit: The method X is ambiguous for type Y

I had some tests working fine. Then, I moved it to a different package, and am now getting errors. Here is the code: import static org.junit.Assert.*; import java.util.HashSet; import java.util.Map; ...
Nick Heiner's user avatar
99 votes
4 answers
91k views

Naming conventions of composed package names

I want to create a package named form validator. Is it better to write form_validator, formValidator or formvalidator? I want to mention that I want to avoid form.validator. And that form-validator ...
Mohamed Taboubi's user avatar
96 votes
14 answers
72k views

Should interfaces be placed in a separate package? [closed]

I'm new to a team working on a rather large project, with lots of components and dependencies. For every component, there's an interfaces package where the exposed interfaces for that component are ...
kctang's user avatar
  • 11.1k
93 votes
6 answers
32k views

Do unused import and objects have a performance impact?

Do the unused imports and unused objects in Java code create any performance impact? Suppose an object is initialized and never used, what happens? And what is the cost of unused imports?
Dheeraj Joshi's user avatar
93 votes
15 answers
35k views

What strategy do you use for package naming in Java projects and why? [closed]

I thought about this awhile ago and it recently resurfaced as my shop is doing its first real Java web app. As an intro, I see two main package naming strategies. (To be clear, I'm not referring to ...
Tim Visher's user avatar
  • 12.8k
90 votes
14 answers
150k views

Eclipse: The declared package does not match the expected package

I have a problem importing an external project. I go File -> Import... -> Existing Projects into Workspace, choose the folder where the project is located and everything is imported - but the package ...
HenryNguyen's user avatar
  • 1,153
87 votes
6 answers
69k views

Java Package Vs Folder-Structure? what is the difference

I would like to know What are the difference between folder-structure and package used in Eclipse IDE for Java EE development. When do we use which one and why?. Whats should be the practice ...
Mrinmoy's user avatar
  • 1,629
81 votes
3 answers
52k views

Why should java package name be lowercase?

Actually this is completely theoretic question. But it's interesting why java specification don't allow uppercase characters letters in package and cause write something like this: com.mycompany....
Oleksii Kolotylenko's user avatar
72 votes
5 answers
81k views

Simple statistics - Java packages for calculating mean, standard deviation, etc [closed]

Could you please suggest any simple Java statistics packages? I don't necessarily need any of the advanced stuff. I was quite surprised that there does not appear to be a function to calculate the ...
Peter Perháč's user avatar
66 votes
3 answers
34k views

Is the use of Java's default package a bad practice?

Is the use of Java's default package a bad practice?
H2ONaCl's user avatar
  • 11.1k
60 votes
5 answers
49k views

Hyphenated company name in Java packages

Say you're working on the core module of the foo project for BarBaz Incorporated. Your code fragment might look like this: package com.barbaz.foo.core; import com.barbaz.foo.util; What would the ...
corsiKa's user avatar
  • 82.2k
55 votes
14 answers
423k views

Java Package Does Not Exist Error

So there's a folder /usr/share/stuff in the root directory in stuff there are a bunch of java files with package org.name definitions at the top I am running javac test.java where test.java is in a ...
algorithmicCoder's user avatar
54 votes
5 answers
26k views

What's the convention for java package names without a domain association?

I can't find a Q/A on SO that answers my exact question, so I figure I'd post it and see what comes back. As far as the naming convention goes for Java packages, I understand that it's supposed to be ...
Mike's user avatar
  • 48.6k
52 votes
4 answers
56k views

How do I add package level annotations or edit package-info.java?

I'm trying to add package level annotations but I don't have a clue on how to do it. Examples are appreciated.
link_boy's user avatar
  • 1,075
51 votes
2 answers
25k views

Netbeans - is it possible to see project source folders in a tree (hierarchical) view, rather then a flat view?

I have some huge NetBeans projects with many packages, sub-packages, sub-sub-packages .etc, and it gets very confusing seeing all these package folders in the flat layout that NetBeans shows.. e.g. a....
José's user avatar
  • 1,565
51 votes
9 answers
24k views

public methods in package-private classes

Does it make a difference to mark methods as public in package-private classes? class SomePackagePrivateClass { void foo(); // package private method public void bar(); // public ...
fredoverflow's user avatar
51 votes
11 answers
54k views

What is the purpose of defining a package in a Java file? [closed]

I am a newbie and just learned that if I define say package my.first.group.here; ... then the Java files that are in this package will be placed under my/first/group/here directory. What is the ...
derrdji's user avatar
  • 13.1k
51 votes
6 answers
33k views

C++ Namespaces, comparison to Java packages

I've done a bunch of Java coding recently and have got used to very specific package naming systems, with deep nesting e.g. com.company.project.db. This works fine in Java, AS3/Flex and C#. I've seen ...
Mr. Boy's user avatar
  • 62.8k
50 votes
6 answers
119k views

Why do package names often begin with "com" [duplicate]

Possible Duplicate: Java packages com and org I am a java developer. Nowadays I am learning struts and when reading a tutorial a curiosity intruded in my mind regarding package com.something....
Nishant Kumar's user avatar
50 votes
6 answers
20k views

What is the significance of the reverse domain name for java package structure

Why do we use reverse domain name like com.something. or org.something. structure for java packages? I understand this brings in some sort of uniqueness, but why do we need this uniqueness?
Vaishak Suresh's user avatar
49 votes
2 answers
136k views

How to use org.apache.commons package?

On various web examples I see imports such as: import org.apache.commons.net.ftp.FTPClient; I don't understand how to use these, and the apache website is fairly unclear. How to I use these classes? ...
Connor's user avatar
  • 1,973
46 votes
9 answers
97k views

How to wildcard include JAR files when compiling?

I have the following in a java file (MyRtmpClient.java): import org.apache.mina.common.ByteBuffer; and ByteBuffer is inside a JAR file (with the proper directory structure of course). That jar file ...
user avatar
45 votes
6 answers
16k views

What is the clearest way to deprecate a package in Java?

I'm working on a new codebase and migrating the system to a new framework. There are a number of packages that I would like to deprecate, just to make it very clear to other developers that ...
Daniel Alexiuc's user avatar
44 votes
5 answers
9k views

Is a Java package the equivalent of a .Net assembly?

I am a .Net developer starting Java development for Android and would like to know if it's correct to think of Java packages like .Net assemblies.
JimDaniel's user avatar
  • 12.7k
43 votes
5 answers
119k views

Running java in package from command line

I have read the previously posted questions. Some are vague and none solved my problem so I am forced to ask again. I have two simple classes, package One; import One.Inner.MyFrame; public class ...
user2756339's user avatar
43 votes
15 answers
179k views

How to avoid Visual Studio Code warning: "[myfile].java is a non-project file, only syntax errors are reported"

I am running a build task in a Java project in Visual Studio Code. The warning in the "PROBLEMS" tab: [myfile].java is a non-project file, only syntax errors are reported It refers to the ...
questionto42's user avatar
  • 8,688
42 votes
13 answers
82k views

How to run a .class file that is part of a package from cmd?

I keep getting errors when I make my .class part of a package and try to run it from cmd. Here's the code that works after using javac and then java: class HelloWorld { public static void main(...
user avatar
42 votes
3 answers
43k views

difference between protected and package-private access modifiers in Java? [duplicate]

I have seen various articles on differences between the protected and package private modifiers. One thing I found contradictory between these two posts Isn't "package private" member ...
eagertoLearn's user avatar
  • 10.1k
40 votes
9 answers
37k views

Java package cycle detection: how do I find the specific classes involved? [closed]

What tool would you recommend to detect Java package cyclic dependencies, knowing that the goal is to list explicitly the specific classes involved in the detected 'across-packages cycle'? I know ...
VonC's user avatar
  • 1.3m
39 votes
12 answers
48k views

@RestController in other package doesn't work

I start with learning Spring and I create basic project which creates database, insert values and next print it in web browser. My problem is that when I have RestController in the same package like ...
CeZet's user avatar
  • 1,513
38 votes
4 answers
8k views

"Cannot subclass the final class" error, but the class is not final [closed]

Here is my code: package basic; public abstract class Entity {} package characters; import basic.Entity; public abstract class Character extends Entity {} package player; public class Player ...
Fletcher's user avatar
  • 621
38 votes
4 answers
3k views

Why I am able to re-create java.lang package and classes?

I am just playing with package structure. And to my surprise I can bypass the default classes by creating my package and class name with that name. For ex: I created a package called java.lang and ...
Suresh Atta's user avatar
37 votes
6 answers
210k views

Help with packages in java - import does not work

I'm a C++ developer - not a java developer, but have to get this code working... I have 2 public classes that will be used by another product. I used the package directive in each of the java files. ...
Tim's user avatar
  • 20.3k
37 votes
2 answers
9k views

How do I prevent Android Studio from automatically collapsing my packages in project navigation?

I have run into this annoyance over and over again and have been unable to find a solution or an answer here for it: When I create a package in my application and then add a package within it, if I ...
Christopher Rathgeb's user avatar
37 votes
3 answers
11k views

IntelliJ: Display .java extension in Packages View

I am pretty new to IntelliJ and I can't find an option to display all file extension in the packages view (in my case .java). As you can see on the sceenshot it just says "Main" or "Controller" on ...
kon's user avatar
  • 547
36 votes
10 answers
13k views

How should I name packages if I don't have a domain associated with me? [closed]

So most Java resources when speaking of packages mention a com.yourcompany.project setup. However, I do not work for a company, and don't have a website. Are there any naming conventions that are ...
Bernard's user avatar
  • 45.4k
34 votes
4 answers
21k views

Package name is different than the folder structure but still Java code compiles

I am using Notepad++ to write my Java code and Command Prompt to compile and run it. Following is my sample Java code, package abraKadabra; public class SuperClass{ protected int ...
whitehat's user avatar
  • 2,391
34 votes
8 answers
6k views

Too many imports are spamming my Java code

In my project I have a shapes package which has shapes I designed for my graphics program, e.g., Rectangle and Circle. I also have one or two more packages that have the same names as java.awt classes....
ApprenticeHacker's user avatar
34 votes
3 answers
48k views

What is the default package in which my classes are put if I don't specify it?

Let's assume I have a file named Main.java with the following code: public class Main { public static void main(String[] args) { System.out.println("Hello world"); } } Is it ...
devoured elysium's user avatar

1
2 3 4 5
46