1
vote
5answers
112 views

Where to read from file?

In Java: I have a class Students. I would like to read a list of students from a file. Which one is more elegant: Reading and constructing the list in main(), and creating a Student object with the ...
2
votes
3answers
132 views

About the usage of assertions [duplicate]

I stumbled upon an article named Programming With Assertions. And beside the mechanism of turning on and off assertions after compile time, I don't get it. Why were assertions introduced on language ...
2
votes
1answer
206 views

Unindented elses

Been writing code since about 18 years now. Lately, I've got into the habit of not indenting elses and when I look at the code it does worry me a bit mostly that someone who might look at the code ...
5
votes
3answers
622 views

Is there an appropriate coding style for implementing an algorithm during an interview?

I failed an interview question in C years ago about converting hex to decimal by not exploiting the ASCII table if (inputDigitByte > 9) hex = inputDigitByte - 'a'. The rise of Unicode has made ...
3
votes
5answers
307 views

In Java, should private helpers go above or below public methods?

I've noticed that a coworker and I have opposite practices regarding the ordering of methods in our Java classes. One of us begins a class with its major public methods, and then put all of the ...
3
votes
1answer
239 views

Why Doesn't Java Allow Default Parameters/Arguments [closed]

Basically something like public void jumpToRoom(String roomName = Rooms.DEFAULT_ROOM) would be convenient. Many languages nowadays seem to support it (Ruby, PHP, even C#). What is Java's ...
17
votes
6answers
842 views

What are the benefits of prefixing function parameter names with p*?

I often see projects (in Java projects and teams using Eclipse) that prefix function parameters with p. For example public void filter (Result pResult) ... I personally don't see any benefit in ...
5
votes
2answers
443 views

Should you create a class within a method?

I have made a program using Java that is an implementation of this project: http://nifty.stanford.edu/2009/stone-random-art/sml/index.html. Essentially, you create a mathematical expression and, ...
0
votes
4answers
239 views

Is 'Protection' an acceptable Java class name

This comes from a closed thread at stack overflow, where there are already some useful answers, though a commenter suggested I post here. I hope this is ok! I'm trying my best to write good ...
7
votes
4answers
320 views

Warn about 3rd party methods that are forbidden

Note: This question refers to code written in Java or C#. I am managing a couple of large projects where we have discovered issues (not necessarily bugs) with some 3rd party/SDK methods and have ...
8
votes
5answers
411 views

Is it customary to write Java domain objects / data transfer objects with public member variables on mobile platforms?

We performed a code review recently of mobile application Java code that was developed by an outside contractor and noticed that all of the domain objects / data transfer objects are written in this ...
2
votes
3answers
410 views

Is there a faster way to work out this logic?

The purpose of this assignment was the find the smallest and largest of the integer(User inputs 5 entries) I am a beginner Java programmer with no prior experience. Is there an easier way to do this ...
10
votes
5answers
2k views

Should a string constant be defined if it's only going to be used once?

We're implementing an adapter for Jaxen (an XPath library for Java) that allows us to use XPath to access the data model of our application. This is done by implementing classes which map strings ...
61
votes
10answers
3k views

Never use Strings in Java?

I stumbled upon a blog entry discouraging the use of Strings in Java for making your code to lack semantics, suggesting that you should use thin wrapper classes instead. This is the before and after ...
8
votes
8answers
1k views

What is the accepted style for using the `this` keyword in Java?

I come from languages like Python or Javascript (and others that are less object-oriented) and I am trying to improve my working knowledge of Java, which I know only in a superficial way. Is it ...
4
votes
1answer
401 views

Programming in academic environment vs industry environment [duplicate]

Possible Duplicate: Differences between programming in school vs programming in industry? This is a general discussion about programming in the industry environment. The background story is ...
5
votes
3answers
454 views

Is it bad idea to use flag variable to search MAX element in array?

Over my programming career I formed a habit to introduce a flag variable that indicates that the first comparison has occured, just like Msft does in its linq Max() extension method implementation ...
7
votes
3answers
475 views

What makes for “good style” in Java?

I had asked this question on Stackoverflow, and before it got booed off, I received the helpful suggestion from Péter Török that this might be a better place to post it. I've been programming in Java ...
6
votes
6answers
6k views

How are multiple values returned in Java?

Sometimes you want to return multiple values from a function. How is this normally done in Java? One option is to use an array, like this Python snippet that returns a list or tuple: value, success ...
2
votes
6answers
1k views

Line break before/after operator

While Sun's Java code convention suggests to put line break before the operator many other guidelines disagree with it. I do not see any obvious pros and cons, so are there advantages of using one of ...
5
votes
3answers
1k views

Should I use default access modifier or not — Coding practice?

Normally when creating new global variables I do not define its access modifier. So as per java it will adopt property default access modifier. When I'm need to access that variable in out of default ...
12
votes
4answers
3k views

In Java, should I use “final” for parameters and locals even when I don't have to?

Java allows marking variables (fields / locals / parameters) as final, to prevent re-assigning into them. I find it very useful with fields, as it helps me quickly see whether some attributes - or an ...