This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring in Action (5th edition) and have Craig Walls on-line!
See this thread for details.
Win a copy of Spring in Action (5th edition) this week in the Spring forum!

Winston Gutkowski

Bartender
+ Follow
since Mar 17, 2011
Winston likes ...
Eclipse IDE Hibernate Ubuntu
35 years of computing, from junior COBOL nerd to sysadmin for Sun...with a lot of DBA and modelling in between. Resistentialist. Beer lover. Fat cyclist. Bridge Player (fanatical, but mediocre). Trivia buff. Collector of oddities. Liberal (in the old-fashioned sense; but still ABC - Anything but Conservative).
Girvan, South Ayrshire, Scotland
Cows and Likes
Cows
Total received
66
In last 30 days
0
Total given
256
Likes
Total received
1543
Received in last 30 days
0
Total given
2104
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Winston Gutkowski

Carey Brown wrote:I'm not sure what you're after but this will give you an array of arrays.

<nitpick>
You're better off using "+", because in this case you only want to include 1 or more spaces in the delimiter, not 0, and that can speed things up quite a bit (although "*" will also work).
Viz:</nitpick>

Lesson: Don't use '*' in regexes unless you specifically mean '0 or more'.

HIH

Winston
1 year ago

Campbell Ritchie wrote:Even confirmed Scannerophobes like Winston thought that shou‍ld be possible.


I resemble that remark!
Hi all. Long time no Ranchee. Though I'd pop back to find some pearls of wisdom about Java 9, since I've just acquired a new laptop for a steal (150 quid for a 5-year old i5 HP, with 8 gig and and a fingerprint scanner) and want to install it.

Winston
1 year ago

rick pine wrote:yes in know my code looks as crooked as my teeth before braces, we are being forced to write our code on an editor that has no autocomplete or auto format features, its cool because it helps train my eye to formatting errors...


It's also a good idea anyway, because it forces you to learn how the Java language actually works - eg, how to compile and jar classes, correct (and avoid) errors, and use the API docs. Lots of people here who've only ever used an IDE basically never learn that stuff, or rely on the IDE to do it for them; so kudos to your teacher.

I notice that you haven't yet tackled the "distinctive" part yet, so here's a tip for you if and when you decide to:

Rather than try and work out if a particular value is the same as any of the ones you've already used - which can be time-consuming and fiddly - Java has an interface called Set which specifically defines a collection of distinct items. This, in turn, defines a method called add(value) that you'll probably find very useful. Have a look at the link and see if anything leaps out at you.

HIH

Winston
2 years ago

Sergiu Dobozi wrote:The method reverseIteration does not take any parameters and it doesn't act on a (which is not even declared as an int[]).


As Dave said: yes it does. Look a bit more closely.

However, what you may be noticing is the fact that those methods are tightly coupled - specifically, they require a separately defined array (the one defined at line 2) in order to work.

And there's no good reason why they should. For example:does the job just as well, and doesn't rely on an outside variable; and is arguably even better. And the same holds true for reverseRecursive().

FYI:
1. The above logic can be compressed quite a bit by using a for loop instead.
2. The start/end test doesn't need to include '=', because if the array contains an odd number of elements, the one in the middle doesn't need to be moved.
Viz:
HIH

Winston
2 years ago

Jesús Calvo wrote:The first one prints "hipo false", as expected, but... does somebody know why the second one prints "hipo true"?


Hopefully, Campbell and Jesper have answered for you.
Nice question though, +1 - took me a few seconds to work out.

Hopefully, this also illustrates that 'instanceof' is an operator - just like '+' and '*' - even though it doesn't look like one.
And as such, it has a precedence.

HIH

Winston
2 years ago

Campbell Ritchie wrote:For those who are not familiar with the JLS@ beware. It can be very difficult to read.


That conversion also surprises me, since promotion of an int to a float could easily lose precision (with long to double, it's far less likely, and also unavoidable); but I bow to superior "interpretation".

Winston
2 years ago

Daniel Peichev wrote:I am currently working on a document management system....


First: Welcome to JavaRanch.

Second: Excellent description of your problem. Have a cow.

Now to the answer - or rather, my answer, because it's purely my opinion:
1. The best place to store files is on a filesystem, because that's what they're designed for.
2. The best place to store data - especially data that contains relationships - is in a database.

When you're dealing with document management you have both; so my preference would be to store the document files (compressed or not) in a filesystem, and store the path (or URL) to the file in the database, along with any other data you need.

Now not everyone will agree with this, so let me explain my reasoning:
1. You can handle the storage (and backup) of your repositories (database and files) separately.
2. You can keep your database and files on separate servers if you want.
3. You can use existing system, 3rd party or Java utilities to read, compress/uncompress, backup, sync, and even version your files if you want. If you store them as BLOBs, you're pretty much forced to use SQL to retrieve them, and the code tends to be clumsy.

Now let me qualify that a little. One thing that many modern databases can do very well is "enhanced searching" on text - eg, "find me every document that contains the words "corporate" and "philosophy" within 5 words of each other" - so if that's a major requirement of your system, or if you want to be able to use a search engine like Google, you might have to rethink my suggestion a bit.
Unfortunately, I've been out of the document management biz for a while now, so I can't really comment; but my gut feel would still be to keep document files and data about those files (even if it includes some or all of the text) separate.

HIH

Winston
2 years ago

Hobi Kod wrote:And program convert this String to Char Array. (sentence=sntn.toCharArray())...


Why? Were you told to?

And what if your user types in:
  The   quick brown  fox      jumps over the   lazy dog
(ie, more than one space between words)

As Campbell has hinted, there are much better ways to get "words" from a String.

HIH

Winston
2 years ago

Ioanna Katsanou wrote:I know that when having to do with operators in Java , and different data types, then the result is promoting to the larger of the data types


You need to be a bit careful with your terminology.

What you're posting about are specifically primitive data types, and even more specifically numeric primitives (ie, everything except boolean) and arithmetic operators (+, -, *, / and %). It also applies to bitwise operators, but I'd say that's beyond the scope of this question.

Basically, when Java does arithmetic on two primitives that are NOT the same type, it has 3 "native" modes:
1. It converts both arguments to int, and returns the result as an int.
2. It converts both arguments to long, and returns the result as a long.
3. It converts both arguments to double, and returns the result as a double.
and it chooses them in that order.
So:
1. If both types are integers (ie, not float or double) AND both are smaller than a long, it converts them to ints.
2. (Assuming 1 is false) If both types are integers, it converts them to longs.
3. (1 and 2 are false) It converts them to double.

Plug that into your question and see if it helps.

Winston
2 years ago

jon ninpoja wrote:how would i manipulate the instance variables or create a new object that is slight different from the previously created button,or one i create after.
is it just done through parameters?


As you can see, there are several ways to do it, but one perfectly valid option which has not really been covered is not to allow internal fields to be changed AT ALL.

Classes like this are called "immutable", and they have many advantages - not the least being that they are naturally Thread-safe. And just because a class is immutable doesn't mean that you can't do some very useful things with it. java.lang.String is just one example of an immutable class that you can do all sorts of things with, but almost all its "manipulation" methods return a new String object, rather than changing the one you run the method on.

Obviously, it isn't appropriate for every kind of class - for example, if you have a Person class, you'll probably want a changeName() method - but you'll be surprised how many classes can be made immutable. And even for classes that you can change (these are called "mutable"), you'll probably want to keep the number of things you can change to a minimum.

So the general rule is: write as many "getter" methods as you like; but think three times before you write a public "setter" method - and in particular, think ten times before you write the first setter method for a class.

HIH

Winston
2 years ago

bob john wrote:If I run the program, console will display:
On tree grows fruit: apples 11
....

What I want to get? This is what I want to get in console, without modify text file:
apples 11
...


OK, that's a good description of what you want to see, but you actually have TWO problems:
1. You need to read lines from a text file.
2. You need to extract the above information from EACH line.

It appears that you've solved the first problem, but you're having problems with the second one. So, eliminate the first one and concentrate on the second.

My suggestion: Write a completely new program that looks something like this:Do you see the idea?

Now you have a program that deals specifically with the problem you want to solve, and you can test it with any "sample" line you like by simply changing the literal for 'line' and running it.

You've already been given several suggestions as to how to do it, so I suggest you re-read the previous posts in this thread

And as soon as this program works - every time - you can take its logic and copy it into your other one.

It's called "problem isolation", and its a technique we all use when we have problems.

HIH

Winston
2 years ago

Dawn Goxhaj wrote:that was an easy fix (I think) by just adding this before my if statement:


I don't think that'll be enough because that means that when you execute the if statement, 'position' will always be null, which means it will throw a NullPointerException whenever the list is empty.

However, it's now a bit difficult to follow everything that you've changed, so could you post the latest version of the whole thing?

Winston
2 years ago

bob john wrote:


Problem: Whenever you use a 'next....' method, you should use its associated 'hasNext...' method.
What do you think that might be?

Winston
2 years ago
Do you actually have a question?

I suggest you read the guidelines on How to ask questions here, because we're not in the business of doing your homework for you.

Winston
2 years ago

Hobi Kod wrote:please help


PatienceIsAVirtue. We're all volunteers on here, so please don't badger. It's more likely to delay responses than speed them up.

You also haven't shown us any code, so we have no more idea what your problem is than you do.

Winston
2 years ago