Solved

A simple question?

Posted on 2004-09-22
8
218 Views
Last Modified: 2010-03-31
Hi Experts, I am a Java Newbie and am just about getting my head around Java Code. I have been looking at some source code available on the net and was wondering if someone could explain this (simply to me). first the code (or part of it(:

-----------------------------------------------------------------------------------------------------------
import java.io.FileNotFoundException;
import java.io.IOException;

public class FileManager
{
  public FileManager() {  }
  public static void setFileTypeAndCreator(String s, long l, long ll) throws IOException {}
  public static void setFileType(String s, long l) throws IOException{}
  public static void setFileCreator(String s, long l) throws IOException{}
  public static long getFileTypes(String filename) throws IOException
  {
    return 0L;
  }
}

---------------------------------------------------------------------------------------------

The question is a simple one. What is the point of having a method for example that (if I understand this correctly), does nothing. For example the:

public static void setFileType(String s, long l) throws IOException{}

What does a method like this actually do? I keep seeing this sort of thing all over the place but I am puzzled as to what it is meant to achieve -- any help appreciated.


0
Comment
Question by:zaphod_beeblebrox
8 Comments
 
LVL 35

Expert Comment

by:girionis
ID: 12121781
>
> The question is a simple one. What is the point of having a method for
> example that (if I understand this correctly), does nothing. For example the:

> public static void setFileType(String s, long l) throws IOException{}

> What does a method like this actually do? I keep seeing this sort of
> thing all over the place but I am puzzled as to what it is meant to
> achieve -- any help appreciated.

Where did you get the code above? It is pointless to have it the way it is, you are right. However is you had an intereface where you need to implement you would need to provide implementations of the methods defined in the interface, even if they do nothing at all, so you coudl have somethign like the above.
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 75 total points
ID: 12121785
It's there so it can be overridden and implemented in a subclass or becuase it requires an implementation to fulfil an interface or abstract class
0
 
LVL 18

Expert Comment

by:armoghan
ID: 12121788
This class seems to be kind of Adaptor class which implements method with nothing in it.
When you extend from these classes you override these functions and provide implementation
0
 
LVL 35

Expert Comment

by:girionis
ID: 12121793
Or maybe this is a generic class and the subclasses need to extend it, but again you do not extend any functionallity, so it's pointless I'd say.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 35

Expert Comment

by:girionis
ID: 12121797
It would be better for the class to have been decalred abstract I reckon.
0
 

Author Comment

by:zaphod_beeblebrox
ID: 12121808
Hell guys, that was quick. I just wanted to know if the code made any sense as it was. I am awarding the points to CEHJ because his answers makes the most sense to me, but all your answers are good and much appreciated
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12121818
>>It would be better for the class to have been decalred abstract I reckon.

Indeed. It's obviously been written by someone who doesn't understand interfaces/abstract classes
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12121859
:-)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Hibernate Not Rolling Back When something fails in a stored procedure 2 50
mockito example issue 8 62
servlet  URL Rewriting 1 25
java jdbc batch example 8 20
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now