Tag Info

Hot answers tagged

10

You needn't use return with void methods in Java, although some coding conventions may call for it, it is not a requirement of the language. Semantically they behave exactly the same way, as the "end" of a void method is an implicit return. Now, it is also possible to put a return; in a conditional block (if, for, while, etc...) where it might exit the ...


8

The Java language has a lot of historical baggage. In Java, everything is an object – with the exception of primitive types such as int or byte that represent C-like value types. While these primitives are generally more efficient, they have some serious restrictions: You can't call methods on non-objects. There is a compiler technique called “autoboxing” ...


8

Good question. The use of enum in Java is primarily meant to handle information that is somewhat categorical in nature. The classic example being using enum to handle the four types of suits that a card could have. It provides all the performance advantage of using an integer and it is also clear in your program. So outside of Java, why wouldn't you ...


8

I've had contractors who have left after creating a database layer with a set of unit tests which passed, but didn't actually save anything to the database so everything was lost if you restarted the system. So test the parts of your system you want to work by writing tests which compare the expected behaviour with the real behaviour. If those parts are ...


5

You wouldn't use it. It's mainly out there as an exercise to help you understand the interesting properties of java enums, for which there are a few uses beyond the more traditional C++ style uses. It's less verbose and requires some relatively deep knowledge of the language, which makes it attractive to the "look how clever I am" breed of programmers. ...


5

Initializing as a parameter breaks encapsulation in that the caller can then do with the passed in list what it wants (clear at odd times). ArrayList<String> list = new ArrayList<String>(); Initializer init = new Initializer(list); //do various thing list.clear(); //now the list in init is also empty while init may still expect it to be filled ...


4

The fact that you need to make a change to the interface of a superclass but do not also have a similar need to change its subclasses suggests to me that you have a design error of some kind. Your subclasses would appear, at least in some cases, not to be substitutable for their base class, otherwise they would need to change too. It may be that your ...


4

Use generics to specify the parameter type. The parent class would restrict this parameter to be a subclass of GeneralParameter: abstract class GenericAlgorithm<Param extends GeneralParameter> { void someMethod(Param p); } Then, the subclass would extend the parent class but provide the used parameter type as a type argument: class ...


3

Just my two cents. The goal of this answer is to give some thoughts and attract more answers, not trying to sound like definitive or even informative. Why are streams abstract base classes instead of interfaces? It is possible to define a strictly minimal interface. Typically this consists of: read, write, seek, tell (returns current file position), ...


3

Yes, it is good practice. It looks a bit boilerplate and weird, because Java 7 and below does not support functional programming very well. The difference to just a regular expression is, that a regular expression limits you in your options to filter for files. E.g. lets say you want to filter files not by their name only but [just/additionally] by their ...


2

Unit tests are essentially tests of a single component. With perhaps some mock objects to fake some interfaces used by the module. You are testing that for a given input you receive the expected output. If you test involves other modules components or services which cannot be mocked then it is no longer a unit test. As such they are very useful. You can ...


2

Let's address the fundamentals of Dependency Injection with a brief review of the dependency injection principle When following this principle, the conventional dependency relationships established from high-level, policy-setting modules to low-level, dependency modules are inverted (i.e. reversed), thus rendering high-level modules independent of the ...


2

There is only one real benefit, yet its huge: Separation of Concerns. So, instead of process orchestration logic being embedded in our system, it becomes and external configuration. A map, basicly. You can change it (much more) independently, you can have multiple processes, multiple versions of processes, multiple versions of multiple processes running at ...


2

While reflection is slow, doing it a handful of thousand times while processing a file will probably not be an issue: the file access is likely to be slower still. Still, you should be able to improve the performance of the code you posted by moving the initiation of ' field' outside of your loop.


2

There's no inherent reason to believe that those are the only subtypes of InputStream. They are merely the only ones described by the Java language beforehand. The implementation of the socket can use any subtype. It is an implementation detail that is not specified.


1

Because we are not passing buffer as argument of out.write(#bytes) method[which looks non-intuitive] unlike the first program which passes user buffer out.write(byteBuf,,)? No, you are not passing buffer as argument, you are passing the single byte that you have read. You have that single byte in the byteRead variable, returned by BufferedInputStream, ...


1

I won't present an efficient algorithm. You may have a look at zero-supressed decision diagrams (ZSDD / ZDD) to enumerate all paths and represent every path in a compact form. Zero-Suppressed BDDs for Set Manipulation in Combinatorial Problems by Shin-ichi Minato (NTT LSI Laboratories) since you now have a compact representation you can search for the ...


1

I feel many people implement inheritance too quickly. Using it as a tool to reduce code. This is not the purpose for inheritance. Used like this, you will always have these problems because inheritance is not implemented properly. On the basics, inheritances spells out a relationship between 2 classes. The relationship is called an "IS A" relationship. In ...


1

Below statements are my personal experience using workflow tools, specifically Oracle BPM Suite(10.3G & 11G). First to specify, your question is focusing on workflow tools which are enabling modeling executable process models, these tools are part of Business Process Management Systems(BPMS). This specific process modeling is definitely developing and ...


1

By storing state inside a static nested class, you are limiting yourself to only being able to instantiate a single instance of this object. If you ever need to use multiple DAO implementations, or add another dependency that needs to change, this could cause a problem. Such requirements seem to me to be quite likely in order to sufficiently unit test this ...


1

Most CI servers are somewhat language agnostic -- at the end of the day you are really just executing shell scripts with some fancy reporting -- so your general premise is correct. The physical deployment of PHP apps is typically pretty simple -- they are just files on disk so rsync is your friend here. The difficult parts come in with things like user data ...


1

I agree with Neil's answer, but just an addition: In java enums are Objects, so they can have fields and methods. So you can give each enum some manualy specified value and when referencing it for outside work, use that value instead. It will survive both adding/removing/reordering and changing name of enum instance. But you will have to write ...



Only top voted, non community-wiki answers of a minimum length are eligible