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

  • SEARCH
  • Home
  • 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 8296429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:59:24+00:00 2026-06-08T14:59:24+00:00

I am familiar with Java but I am still trying to figure out some

  • 0

I am familiar with Java but I am still trying to figure out some concepts.

Say I have FileA.java and FileB.java. Both files use the same import calls at the header of the file, for example:

FileA.java:

import java.util.Scanner;
import java.io.*;
{some code}

FileB.java

import java.util.Scanner;
import java.io.*;
{some code}

I have seen in other languages that when you have common libraries used by several source code files, then you abstract this to a shared file and then you can call this file in the source code files, thus helping reduce maintenance and have to retype them several times. So then for the example above we could do something like:

Common.lib:

import java.util.Scanner;
import java.io.*;

FileA.java:

include Common.lib;
{some code}


FileB.java:
include Common.lib;
{some code}

So I have the following questions and would appreciate if somebody could clarify since I’d admit I’m ignorant of the topic:

  1. Is this doable in Java?
  2. Is this a good idea/best practice? yes/no why?
  3. If it’s not good practice then how do you deal having to type the same import headers for every single java file that use the same ones?
  • 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-08T14:59:28+00:00Added an answer on June 8, 2026 at 2:59 pm

    Is this doable in Java?

    No.

    Is this a good idea/best practice? yes/no why?

    It is not doable without resorting to something like a preprocessor … which makes this a non-Java solution, and definitely NOT “best practice”.

    If it’s not good practice then how do you deal having to type the same import headers for every single java file that use the same ones?

    I deal with it by using an IDE that allows me to hide the import statements when I don’t want to look at them. Even in the old days when I wrote Java using a dumb(-ish) text editor, I never found this to be a significant issue. (But then again, after 30-something years of professional programming and 20-something different programming languages I’ve learnt to be tolerant of minor syntactic irritations.)


    If you look at this early Java White Paper by James Gosling & Henry McGilton, you will see that one of the advantages of excluding #include (and typedef) is as follows:

    “By removing all this baggage, Java becomes remarkably context-free. Programmers can read and understand code and, more importantly, modify and reuse code much faster and easier.”

    In other words, you don’t have to navigate a maze of include files to figure out what a given identifier in the main source file refers to. That information is all in the class source file (assuming you don’t use * imports … which I don’t).

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

Sidebar

Related Questions

I'm not too familiar with networking in JAVA but what i'm basically trying to
I am not familiar with javascript and I have had some exposure to java
I am not familiar with any of the leading frameworks of java but still
I'm not familiar with Java but I need to make a request to a
I am somewhat familiar to Java, but am using it more now for Android.
I am very familiar with C# but starting to work more in Java. I
I am still not so familiar with interfaces in Java. I know that interface
I have been wandering about this for some time now. I'm still a beginner,
I am trying to get familiar with Java EE 6 by reading http://java.sun.com/javaee/6/docs/tutorial/doc/gexaf.html .
I'm not very familiar with Java, but got the job to reverse the following

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.