Junilu Lacar

Sheriff
+ Follow
since Feb 26, 2001
Junilu likes ...
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
Columbus OH
Cows and Likes
Cows
Total received
193
In last 30 days
2
Total given
67
Likes
Total received
1599
Received in last 30 days
18
Total given
297
Given in last 30 days
4
Forums and Threads
Scavenger Hunt
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Junilu Lacar

More specific nitpicks:

Nitpick #1

Instead of this:
do this:
Rationale:
1. Prefer to use the interface type (List) instead of the concrete implementation type (ArrayList) when declaring variables
2. Variable names should start with a lowercase letter
3. Use the diamond operator and type inference to reduce redundancy in your code on the right hand side (RHS) of the assignment statement.

Nitpick #2

Instead of this:
do this:
Rationale:
1. Do not create new instances of String if you really mean to use a String literal.
2. Variable names start with a lowercase letter
3. Make your variable names meaningful to other people. Ikkyo is the first technique -- people who don't practice Aikido should be able to get that from your code.

(Yes, I study Aikido)
6 minutes ago
Please clarify what you mean by "hwid" -- that's not as common a term as RAM and CPU.  Also, how does being able to get information about RAM and CPU protect your application? Your question about binary file getting deleted and making a database detect "this information" is also not clear. Can you give more details about what it is you want to do?

From what I can tell, the kind of things you're asking about don't seem like things you'd really want to do at the JVM level. More like at the OS level.
23 hours ago
I'm going to experiment with Consumer some more. I have a nugget of an idea that I might be able to use it to put a twist on a Conway's Game of Life implementation where I'm not using a normal "grid" structure to track generations and populations but rather some kind of sparse matrix that I can stream. The idea is to be able to write something like this:

Consumer lambdas will come into play as encapsulations of the rules for survival from one generation to the next:
- a live cell with 2 or 3 neighbors survive
- a live cell with less than 2 neighbors dies of loneliness
- a live cell with more than 3 neighbors dies of overcrowding
- an empty cell with exactly 3 neighbors becomes a live cell.

Each Consumer will "consume" the current position in the board that is being checked and could potentially produce a side-effect that is manifested in the next generation object. I think this is consistent with the API docs statement about Consumer:

Java API Documentation for Consumer wrote:Unlike most other functional interfaces, Consumer is expected to operate via side-effects.

A constructor that takes a ResultSet and initialized itself from the current row? Yikes. That smells to high heaven.

Line 46
1 day ago
I should point out that while the second example I gave above that uses a Consumer to change the state of the UpDown object via the change(int) method works, the code is still problematic to me.

The semantics of the name "consumer" does not match what the code in the lambda actually does: it is giving a value to its parameter, ud, via the change(int) method. So the "consumer" wasn't actually consuming anything. Instead, it was causing its argument to mutate. That kind of mismatch between what the name in the code says and what the code actually does is what wreaks havoc with my cognitive abilities. My brain doesn't like being made to jump cognitive hoops like that, so it tells me that the code is smelly.

On the other hand, the Function lambda you used doesn't have that problem because what your lambda does lines up with my mental model of what a "function" would do: it uses its argument to calculate a value, then returns the result of that calculation. The client is free to do whatever it pleases with that result.
I think my unease with using a Consumer in this case is that I think of a "consumer" as something that does something with whatever it is passed, not something to, which seems to be what you want to do when you desire to change the internal state of the StateCount object using a lambda. The typical example of a Consumer usually just prints out something using the thing it was passed. Granted, that's probably the easiest way to illustrate how a Consumer works.

My mental model is like this:

A Consumer gets a value from its argument, then uses that value to do something

A Supplier gives its argument a value that the argument then uses to do something

Your code went against this mental model, so it was smelly to me. Let's say I ignore my mental model and went with what you were trying to do instead. I might have tried this:


I would have to add a couple of overloaded change() methods:

See the change2() method here: https://repl.it/@jlacar/SupplierLambdasExample
Sorry for this late response. It's been a pretty busy weekend.

Let me try to clarify some of what I said previously with examples.

OP wrote:...trying out different ways to fail


That's a perfectly fine way to learn. Yoda even said that "The greatest teacher, failure is."

Piet may have already gone over this but I'll reiterate: Your attempt to use a Consumer lambda failed because of the expression c.getCount() += 1.  The += operator is a compound operation which combines an addition operation with an assignment operation. It's illegal to try to assign a value to a method call, which is what c.getCount() is, hence the error message that says "the left hand side of an assignment must be a variable".

OP wrote:why do you say "between the StateCount class and the lambdas"


I think it's because I didn't see any reason for the lambda to know about StateCount. I got a sense that the code you wrote was going around the bush to do something that could be accomplished in a more straightforward manner. If I really wanted to use lambdas to do increment/decrement, I would have done something like this:


You can try this code out yourself here: https://repl.it/@jlacar/SupplierLambdasExample

Study that example for a while and come back if you have any questions.
Piet,

I was addressing OP. I actually agree with practically all of the things that you said in your previous replies.
I second Knute's recommendation for Java 8 in Action -- it has very good discussions about lambdas and other language features that were introduced in Java 8.
1 day ago
You declared the fields as static. That means all instances will share the same value. Remove static from the field declarations to make them instance variables and each new instance will have its own values for those fields.
2 days ago
Additionally, your usage of the Function and Consumer interfaces are smelly. I can't quite put my finger on it but it just seems like there's way too much unnecessary intimacy between the StateCount class and the lambdas. The lambdas having a reference to StateCount does not look right to me. And Consumer seems like the opposite of what you should use. That is, it seems to me a Producer Supplier is more appropriate for what you want to do. I'll try to come up with an example to show something I think is more sensible.
Welcome to the Ranch. What you're seeing is the output of the toString() inherited from Object. You need to override it with a toString() method specifically for the Employee class.
2 days ago
I'm sure there's no disagreement that regular user credentials / passphrases should be hashed, not encrypted.

However, I believe that OP is talking about system credentials, that are part of an automated authentication process.  One way to do automated authentication, of course, is to use SSH key authentication. But that won't work for everything. What if your company policy is to have a generic user assigned to your application, then you have to use that generic user's credentials for database connections and things like that? That's where tools like Jasypt come in handy. Like I said, I used this tool on past projects and it was fine for what we needed, and for a security-related application no less. Again, this is not and should be your only line of defense -- you should have a multi-layered security strategy to protect secrets and confidential assets.

What we did was to use Jasypt to encrypt the DB password and then keep the encrypted string in our application's config file.  We integrated Jasypt into the application startup process where the operator had to key in the passphrase. We used randomly generated passphrases that were kept secure in password manager programs. We had a schedule for changing those passphrases at regular intervals and a process for distributing the password manager databases securely to people who needed them. For other cases, we kept the passphrases as environment settings on servers to which ACLs limited privileges and access.
2 days ago
Check out the Jasypt Project - I've used this in past projects to avoid keeping system credentials from being stored in plain text. Of course, you should have multiple layers of security on top of this, like access control lists (ACL), limited privileges, physical security, etc. By "system" credentials, I mean things like DB passwords, generic user accounts, and other things not pertaining to individual users of the system.
2 days ago
Welcome to the Ranch!

From your menu, try going to Window | Show View | Console
3 days ago