Tomek Ziolkowski

Greenhorn
+ Follow
since Mar 07, 2012
Tomek likes ...
Eclipse IDE Ubuntu Java
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
3
Received in last 30 days
0
Total given
4
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Tomek Ziolkowski

If you don't get any exceptions (so that you don't know where the problem is) and your code still doesn't work as expected then you should probably think of where the problem may exists inside the code, then put some breakpoints there and debug the code step-by-step, verifying expected results at each step. Can't see any other way.
11 years ago
Hi,

You can use an int variable to act as a counter and regex which will be a randomly retrieved line of text. Then, you can read the whole file from the beginning counting each line and at each line you can do a check whether a regex matches a line with text, if matches then return an int value which will be a line number.
11 years ago


...maybe this will help
11 years ago
Refer to the description of a Serializable interface http://docs.oracle.com/javase/7/docs/api/java/io/Serializable.html

If your class Box does not implement directly a serializable interface then probably it extends from a class which is serializable.
11 years ago
I would personally suggest to avoid commenting very obvious things, for example in your code:


a comment //An instance of a person can be avoided. Remember that you're passing information in your code mainly to other programmers (for i.e. later development of your project etc.) and for a programmer it will definitely be obvious that you're instantiating a PeopleCreation object.

Also a code starting at line 4 should probably be a description of a class and thus should be located after import statements and before your class name signature. Comments should be in right places. You provide in your comments description of your decisions, which are not necessarily needed (you need to think whether it is actually needed in a particular place - usually it would be needed if you create a temporarily fix for a complex code and leave an information for the future that other consideration could be taken to improve this part of code later), if it is not needed then it would be better to provide short (one sentence) description of what you're doing here. If you are interested you can read about software metric 'comment density' in source files and the impact it may have on the code readability.
11 years ago
I think this is a question for cricket fans only
11 years ago
The 'd' variable must be initialised outside of the if condition or there must be added 'else' similar as with initialisation of 'c' to any of the conditions at lines 7,8,9.It seems that a compiler doesn't know whether an if condition is passed at line 10 and thus takes a possibility that this condition may not be true.
11 years ago
Thank you guys for the answers. Rob, I don't use this code technique (firs example) either , just noticed this in some places in projects I'm working on and started to think what might be a reason of doing this and any possible associated issues, as I didn't notice inside the project's code any obstacles of using the "standard" way (second example). I think it is also a matter of how different people are used to write the code etc.

...the code: seems more sensible to me in my specific case than the code in first example.
11 years ago
Hi,

What do you think, is it a good programming practice to do something like this:



...instead of doing this:



Dereferencing object in the first example prevents modifications of the class variable someObjects outside of the class. Are there any issues you might think of in doing something like this?

Thanks!
11 years ago