salvin francis

Saloon Keeper
+ Follow
since Jan 12, 2009
salvin likes ...
Eclipse IDE Google Web Toolkit Java
Mumbai
Cows and Likes
Cows
Total received
55
In last 30 days
9
Total given
87
Likes
Total received
196
Received in last 30 days
12
Total given
69
Given in last 30 days
2
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by salvin francis

Nitpick ...

World.java --> setNeighbors

Offsets are always going to be the same for square block systems (unless you're planning for a hexagonal system or similar) . Maybe it should be a static final variable ? I know that you are just calling that method in the constructor iteration. But, each iteration will create a new array.

I am looking forward to run your code on my machine and see it in action !! Will update you soon.
9 hours ago
I have a simpler reply:

programming noun

www.merriam-webster.com wrote:pro·​gram·​ming | \ˈprō-ˌgra-miŋ,  -grə-\
variants: or less commonly programing
Definition of programming
1 : the planning, scheduling, or performing of a program
2a : the process of instructing or learning by means of an instructional program
b : the process of preparing an instructional program for a device (such as a computer)



Now let's look at program:

program noun

www.merriam-webster.com wrote:pro·​gram | \ˈprō-ˌgram,  -grəm  \
Definition of program (Entry 1 of 2)
1 [ Late Latin programma, from Greek ] : a public notice
2a : a brief usually printed outline of the order to be followed, of the features to be presented, and the persons participating (as in a public performance)
b : the performance of a program
especially : a performance broadcast on radio or television
3 : a plan or system under which action may be taken toward a goal



10 hours ago


will always give the output:

(I tested with Java8, Java9 and Java10)

Can you guess why the numbers are the same and not exactly random whether I run it on my computer or any other computer ?
11 hours ago
Let's take another step down the rabbit hole ...



The delegated call to Random(long seed) with the seed is now passed to initialScramble which does this:

Where multiplier is 25214903917 (Code says its "0x5DEECE66DL") and mask is 281474976710655 (Code says its "(1L << 48) - 1")


Now.. coming back to the original Question...

What does Random r=new Random(); actually do?

It simply initializes the Random class with a seed value.  There is a lot of complicated logic to initialize the seed as I mentioned above, but all you need to know is that new Random() simply initializes a seed variable inside Random class. That's it.



11 hours ago
Hi, This is a very interesting question and it led me to do some research.

Basically, when you call the constructor: Random(), it delegates the call to another constructor: Random(long seed).

For Java8, the implementation is that it Xors a generated number with nano time:


While we know nanoTime returns the current value of the running Java Virtual Machine's high-resolution time source, in nanoseconds. seedUniquifier() is used to generate a number each time it is called.

seedUniquifier is interesting..
There is a static variable initialized to 8682522807148012L and this is multiplied by 181783497276652981 each time this method is called is called.

I have oversimplified a few things above but I hope that is what you are looking for.


You can look at Random.java source code in Java's installation folder by extracting src.zip and going to src/java/util/Random.java
11 hours ago
It's good to know that for loop was covered in your class, now, we can modify the code in a better way.
This is the general form of a for loop : (see here for more details)



there is also a variation of for loops that work with collections and arrays, but lets not go there for the moment.

What do you think should be in "initialization", "termination" and "increment" for your problem statement ?
1 day ago
Welcome to code ranch,

soneand pap wrote:...and how am i supposed to use onlt the "abc" part??

Are you asking about how to get the data from the first element in an array ?
Here's the basic java tutorial about arrays:
https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html
The tutorial example itself shows how to do that.

1 day ago
Oh and Welcome to Code ranch !!!
1 day ago
There are two things you need to learn to do this:
1. UI coding: lets say you load data from database, how are you going to show it in the JTable ?
2. JDBC: How to Connect and load data from database

Here are a few useful links for both:
https://docs.oracle.com/javase/tutorial/jdbc/overview/index.html
https://docs.oracle.com/javase/tutorial/uiswing/components/table.html
1 day ago
If I know the lower bound (in this case 0) as well as the upper bound (in this case 3). I would suggest to use a "for" loop instead of "while" loop. Did your instructor cover "for" loops before giving this exercise ?
1 day ago

Junilu Lacar wrote:How about using the concepts of "occupied/empty" or "live/dead" instead?


That sounds good.
My thought process was "exists" or "isPresent" as a method instead of a property. These are more in line with something exists or is present at a certain location in our world. I love that piet too is thinking in my way that a cell simply is there or is not there, there is no state to it.
1 day ago

Jeremiah Waters wrote:Thank you so much! For both your help and your patience!


I am glad you learnt from this experience. I have a few more comments from my end...
First of all "WordsCompare" does not sound like a right name for a class,  Since "Compare" is a verb. I would suggest to call it "WordsComparer" or similar to make it a noun.

Next, this code does not smell nice :
It seems like we're relying on WordsCompare's "toString()" method to do the actual work of comparison. toString() is a simple method that most programmers use for debugging code. Here's the documentation for that:
https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--

javadocs wrote:Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read.


Can you use your method and constructor knowledge to write this code in a better way ? Don't worry about right and wrong, we all learn at some point of time.
1 day ago
I would suggest to read "Passing Information to a Method or a Constructor" too in the link Ganesh Patekar posted.

Let's read your code line by line:

2 days ago

Junilu Lacar wrote:...

live_cell_with_three_neighbors_lives_on_in_next_generation()
live_cell_with_two_neightbors_lives_on_in_next_generation()
empty_cell_with_exactly_three_neighbors_comes_alive_in_next_generation()

...


This is really awesome, it does tell a story. I agree with Junilu's description about the Builder pattern as well. The only concept that I am still finding hard to digest is "empty cell". This gives the analogy of a "cell" (like a table cell or a prison cell) as a placeholder instead of a living organism. We're dealing with the creation of life here

I would call Junilu's last test case as :
On second thought, I am now having issues with the rules of the game.. What kind of sick ritual requires 3 members to mate !!?!
2 days ago

Aldos Kraut wrote:

I am afraid these do not follow java coding guidelines for naming method names. Java methods are verbs. "catAge", "catGender", etc.. do not quality this naming convention.

2 days ago