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 770213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:27:46+00:00 2026-05-14T18:27:46+00:00

I have created a pkg for my regular simple commands. They are non-static, to

  • 0

I have created a pkg for my regular simple commands. They are non-static, to be more extensible, but somewhat more time-consuming to use because of creating object to use one. My other classes use them.

$ ls  *.java
CpF.java      IsBinary.java      RmLn.java        Tools.java
F2S.java      IsRoot.java        SaveToDisk.java  WordCount.java
Filters.java  ModRelativePaths.java  SetWord.java     WordNumber.java
Find.java     powerTools.java        Sort.java

Which option would you choose to use them easier?

  1. to develop a small interface like ‘powerTools.java’ for the pkg.
  2. to create a class with static methods for them.
  3. to add a static method to each class
  4. to stop overusing ‘creating too many files’ and centralising some?
  5. sthing else?

Static VS object-discussion

  1. How can you get outside methods work like in their own classes without referencing them with their class-name? Not class_name.method(), just method(). Outside methods are from separate pkgs.

Code not Working with Import-static with my class and Pkg

$ cat Test.java 
import static a.*;

public class Test
{
    public static void main(String[] args)
    {
        a.printHello();
    }
}
$ cat a/Hello.java 
import java.io.*;

public class Hello
{
    public static printHello(){System.out.println("Hello");}
}

$ javac Test.java 
Test.java:1: cannot find symbol
symbol: class a
import static a.*;
              ^
Test.java:7: cannot find symbol
symbol  : variable a
location: class Test
        a.printHello();
        ^
2 errors
$ sed -i 's@a.printHello@printHello@g' Test.java 
$ javac Test.java 
Test.java:1: cannot find symbol
symbol: class a
import static a.*;
              ^
Test.java:7: cannot find symbol
symbol  : method printHello()
location: class Test
        printHello();
  • 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-05-14T18:27:46+00:00Added an answer on May 14, 2026 at 6:27 pm

    At first glance, I bet that none of them maintains any state and thus can be safely declared static. I also have the impression that each class has actually only one public method which does only one task at once. It also sounds like as if they are tied to a specific platform.

    If all of above is true, then you have 2 options:

    1. Just group them all in a public final class PowerTools class with a private constructor (so that it cannot be instantiated) and public static methods, each doing the desired task. You can eventually use the original classname as method name.

    2. Define a public interface PowerTools so that you can implement LinuxPowerTools, WindowsPowerTools, MacPowerTools, etcetera accordingly and create an abstract PowerToolsFactory to return the desired implementation automatically based on the current platform (you can use the system property os.name to sniff the current platform).

    If this is for pure hobby purposes, option 1 would suffice. But option 2 is more “professional”, if you understand what I mean.

    Update: as per your update, you can use the import static statement for this. Also see this Sun Tutorial.

    E.g.

    import static java.lang.System.*;
    
    public class Test {
        public static void main(String... args) {
            out.println("foo");
            exit(-1);
        }
    }
    

    If you have a com.example.PowerTools class containing the public static methods, then you could import it as follows:

    import static com.example.PowerTools.*;
    
    public class Test {
        public static void main(String... args) {
            if (isBinary(file)) {
                // ...
            }
            saveToDisk(file);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have created a UIButton programmatically, all works as expected but how can I use
I have created an installer using packagemaker, but i don't see how to add
As a postlude to Consuming an EJB question. I have created an ejb on
I have a pkg file created by Install Maker for Mac. I want to
I have created a QWidget with a bunch of QToolButtons in it and I
I have created 3 classes as following Ext.mine.TextParent - Inherting from Textfield Ext.mine.child.TextChildA -
I have created some JQuery that will expand a div 'popup' on hover and
I have created a JSP / servlets application running in Tomcat 7. It runs
I have created an EDMX in visual studio 2010 SP1. It has been built
I have created an android application that calls (using kSOAP library) a SOAP based

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.