Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8202659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T07:15:49+00:00 2026-06-07T07:15:49+00:00

I am creating a Java library, as a final product in intend to distribute

  • 0

I am creating a Java library, as a final product in intend to distribute this .jar to developers.

I am “translating” my library from Objective-C where I control which classes header files are available to the developer. In other words I am only exposing to the developer a few classes they can handle.

In my Java library I am using packages and my package has grown quite big. So I decided to separate into different packages my models and controllers. But now the models I wanted to keep private I need to mark as public in order to use from the main package.

My question is does this go against what I was doing in Objective-C ?

For example I have an Event class which is really only used internally and I don’t want the user to know about it or think about it. I have another class TimedEvent, which the user can get an instance of an manage.

In my Objective-C, I simply excluded Event class from the library public scope, allowing TimedEvent.

If I am making things more tidy in my library then it seems packages aren’t the way. Since now, my main controller is in the main package and all the models are in another package – forced to have a public scope.

Opinions ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T07:15:51+00:00Added an answer on June 7, 2026 at 7:15 am

    This is possible with Java but there are reasons why (almost) no one does it…

    If you put the implementation and the interface into the same package, then you can omit all access modifiers (private, protected, public) from classes and methods to give them “default” or “package” visibility: Only classes in the same package are allowed to see/use them.

    Drawback: You’ll have to mix API and implementation.

    The other approach is to move the implementation into a package *.private.*. No more mixing of API and implementation but malicious users can easily access the implementation – it’s just a naming convention. Like a STOP sign: It means something (“be careful”) but doesn’t actually stop you.

    Lastly, you can implement the interface inside of the interface. For example:

    public interface IFoo {
        String getName();
    
        private static class Foo implements IFoo {
            public String getName();
        }
    
        public static class FooFactory {
            public static IFoo create() { return new Foo(); }
        }
    }
    

    Ugly, ain’t it?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using a JAR file of my own, which uses a Java library (JHDF5),
I'm creating a GWT version of a Java library which has support for the
Firefox 3.5 does not allow creating java OBJECT tag with Javascript (document.write)? this technique
I am creating a java application with RestFB. At this url, Facebook explains how
I'm creating an XML-RPC server in Java using the Redstone XML-RPC library . The
Preon is a Java library meant for creating binary codecs: you simply place annotations
Can you please recommend a Java library for creating trees? I am looking for
I am creating an application using the linkedin-j Java library and JavaLoader, and I
I'm creating a library that includes both Clojure and Java code, and would like
I am looking for an open-source java library for creating yahoo-pipes like GUI. Wireit

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.