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:
- Is this doable in Java?
- Is this a good idea/best practice? yes/no why?
- 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?