• Post Reply Bookmark Topic Watch Topic
  • New Topic

Are the classes in Apache Commons utility packages are public classes?  RSS feed

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And the methods for those classes are all static?

For example.

FileUtils.deleteQuietly(atargetFile);

Questions - kind of confusing. Before invoking methods like deleteQuietly of copyFile, don't we have to first instantiate an object of "FileUtils" class?

Thanks
nath
 
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. That's what static means.
 
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The API documentation (of Apache Commons IO) tells you exactly what methods are public and / or static.

Understanding Class Members in Oracle's Java Tutorials explains what "static" means - as Bear says, this means you can use the method without creating an instance of the class.
 
narendra nath
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got it.

Are there any disadvantages of using Static methods?

I read they might thread conflicts.

thanks
nath
 
Saloon Keeper
Posts: 18800
74
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are all sorts of disadvantages of creating static methods. The primary one being that often the methods end up so complex that they need an accompanying instance to avoid things like method calls with 37 parameters.

If you're asking whether it's bad to use static methods that were defined in the Apache Commons classes, no. They've already determined the benefits and drawbacks of making those methods static and designed them accordingly.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!