Les Morgan

Rancher
+ Follow
since Sep 29, 2015
Les likes ...
C++ Java MySQL Database Netbeans IDE Oracle Tomcat Server
Cows and Likes
Cows
Total received
19
In last 30 days
0
Total given
1
Likes
Total received
129
Received in last 30 days
0
Total given
114
Given in last 30 days
1
Forums and Threads
Scavenger Hunt
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Les Morgan

looks like you have a pretty good solution there just by order the rules by the index, 2nd to last digit of rules.
5 days ago
posted this over at Oracle yesterday

From the Java Tutorial on "Concurrency" in the "Immutable Objects" section, this statement is given:

"The impact of object creation is often overestimated, and can be offset by some of the efficiencies associated with immutable objects. These include decreased overhead due to garbage collection, and the elimination of code needed to protect mutable objects from corruption."

I completely see "elimination of code needed to protect mutable objects from corruption", but could someone explain to me what is meant by "decreased overhead due to garbage collection"?

With an immutable object garbage collection need is always increased because anytime you need to have change you are forced to create a new object.  I see this all the time in new programmers using String, since String is an immutable object, every time a "change" is made to the String, what is really happening is that they are getting a new String object and the old is being deferenced and available for garbage collection.  This can add significant overhead if care is not taken to eliminate the creation of the new objects.

Les

BTW: nice example there on using "final" to create an immutable instance.
3 weeks ago
Hari,

Yes, the name of the game is to get the objects to exist, not just have null references, however you initialize it.

Les

Hari Nagarjuna wrote:

Campbell Ritchie wrote:

Les Morgan wrote:. . . If we type int[3] what we have created is a reference that will point to 3 integers, but it is still only the variable that will reference the ints, we have not constructed an array yet--just a referencing scheme. . . .

Can you write int[3] as a type? I thought you can only use the number on the right of the assignment operator:

. . . you typed in a literal array/collection of ints. . . .

That is called an array initialiser. Unlike writing new int[3], which creates an array filled with 0s/nulls/falses, an initialiser creates an array filled with the actual values desired. Code like...both declares the reference and creates the array object in one line.



Thanks for your reply.
So there is no special purpose in using

apart from initializing the array elements to 0's/null's/false's?
as object can be created directly using

1 month ago
Campbell,
You are quite correct, just remembering this and that and mixing it into the wrong context again--multiple languages is not always a blessing
Les

Campbell Ritchie wrote:Can you write int[3] as a type? I thought you can only use the number on the right of the assignment operator:

. . . you typed in a literal array/collection of ints. . . .

1 month ago
Hari,

In your example:

the array is created, by you, in that, you typed in a literal array/collection of ints.  You used the Java defined syntax to do so {1, 2, 3}, the curly braces in this case tells Java there is an array coming and the literals within are the it.  You already made the object--the variable "num" is just assigned the reference to it.

Les

Hari Nagarjuna wrote:

Les Morgan wrote:Hari,

I am not sure I understand completely what you are asking, but let me see if I am getting a piece of what you are saying.

When we "create an array" in Java and many other languages, I think what you are referring to is the left side of the expression: int[] in the case we wish to build an integer array.  When we type int[], there is no array created, but instead what we have made is a reference that will be set to reference an array object.  If we type int[3] what we have created is a reference that will point to 3 integers, but it is still only the variable that will reference the ints, we have not constructed an array yet--just a referencing scheme.



Yes this is exactly where I am confused.
in
I have just created a reference.
But I have not created an actual array object using

which should create create integer array object of required space in which we can give our input.
But in

There is no array object created .Reference just points to the object created and will not store any data given by us.
So where integers 1,2,3 stored since there is no object created.


1 month ago
Hari,

I am not sure I understand completely what you are asking, but let me see if I am getting a piece of what you are saying.

When we "create an array" in Java and many other languages, I think what you are referring to is the left side of the expression: int[] in the case we wish to build an integer array.  When we type int[], there is no array created, but instead what we have made is a reference that will be set to reference an array object.  If we type int[3] what we have created is a reference that will point to 3 integers, but it is still only the variable that will reference the ints, we have not constructed an array yet--just a referencing scheme.

on the right side of the expression, we create the object, in Java you can use "new" to create new objects or in some cases you can type literals with specific syntax to fit into our reference that we set up on the left side.  In the  cases you show, that is the later, you are telling Java to reference the literals that you typed in on the right by the references that you set up on the left side.

Les
1 month ago
Alexandra,

Mostly I get--noise, noise, noise... blah, blah, blah, out of that article.  Do your own survey around your area where you actually want to work.  My main bread and butter, so to say, is no longer Java, but straight SQL development, so I am a little out of touch nationally.  With 30 years of programming in, I am not looking for the next big thing, other than a sunny beach some where and my wife beside me.  Having said that I still look in the local market.  I live outside of the Metro Area in WA, and I tend to keep an eye on what the smaller guys want, than what is buzz feed to bots that are reading resumes.

But there is what people look at locally:

SQL -- Yes, they want you to have SQL skills.  More than just what is available by hitting a query in Java.  They actually expect to see that you can write some pure SQL and do it competently.
Web -- They want to see that  you can script like a demon and others can read it when it's all done.
Language -- Java is but one of the tools in the shed, and many of the little guys: under 1000 employees, don't particularly care what you program in as long as it maintainable in their enterprise.

After all that, they want to know can you play well with the other kids on the block.

That's the highlights... right now my resume says, in this order: SQL, SAS, C#, and Java.  Realistically the guys hire me for my SQL skills and the rest is just a fill-in where needed.

Les
1 month ago
Randy,

Jim Venolia gave a sage piece of advice when he said: walk away from it... I started my grand venture in programming by taking a general engineering course.  My prof there told us the very same thing: when you work to futility, walk away. Go do something else, have fun, but don't think of the problem any more, but be sure you have a pencil and piece of paper at your bedside because your subconscious mind is going to work on that and find a solution.

Are you really asking if there is a way to improve your logic?  The answer there is yes, get a symbolic logic text and read it.  It was required course in my computer science curriculum at the university I attended for my computer science degree.  I think, though you as about logic, what you really want to know is how to improve your problem solving, algorithm building, skills.  The best answer there that I have is: solve more problems!  Not just programming problems either.  People ask me how I acquired the skills of programming, and to that I have to answer this: it started out when I was very young, my father was an automobile mechanic and home "do it yoursselfer".  He included me in his mania for working on cars and love of fixing things.  By the time I was graduated HS I literally was a journeyman level mechanic with 1000's of hours of problem solving, diagnosing and solving mechanical problems, to my credit.  There was the start of me becoming a computer programmer and developing the skills to so become.

Great you say, I don't have a mechanic father that will help me diagnose and fix cars.  Problem solving is problem solving, you have to develop a way that works for you to tackle something that you may not be able to wrap your head around at first.  How? you may ask.  I would say: have you ever eaten a water melon?  Your response will be, "of course not", but if I ask, "In all of your life, do you think you have eaten enough water melon to equal the weight of a whole water melon?"  You answer would probably include: "of course".  You did that by eating one bite at a time.  The same is true for problem solving.

The largest problem is nothing more than the sum of all the little problems that make it up.  Lean to recognize the little problems that make up the whole, then chip away at the little problems until you can wrap your head around the enormity of the whole.

I had a Math instructor that gave us these same words: "There is no magic."  I don't remember the exact wording of the rest, but he explained that Math is a collection of rules, procedures to follow, and if you know them, then you'll have an easy time of it.  He was right, but that same logic applies to all things--know the rules and how to apply them and it becomes easy.  Programming is that way too: identify the problem, break it into it's simplest sub components, and start from the end and work back to the beginning for implementation.--a "ground up" approach.  It really works.

At about this time in my speeches to up coming programmers I throw in: get the book "The Mythical Man Month".  Will it help me? you may ask.  I don't know is always my reply, but it's a good short read, and it may keep your from blowing your foot off before you start the journey sometime.  I have referenced it continually since my required reading of it in one of my computer science courses.  I was actually able to quote a line from it, "You cannot put 9 women in the room and tell them to make a baby in 1 month.", to a supervisor of mine and I got away with it because it is a classic work concerning computer development.  That was well worth the read in and of itself!

Any way Randy, remember to have fun, and don't be afraid to entertain the absurd as a possible solution--doing so have saved my bacon many times, and people are in awe of some of the solutions that it has led to development.

Les
1 month ago
Lawrence,

Yes.  I generally use an array for keeping track of the Tiles in my games.  For a flat world, checker boards and etc, a 2D array.  If you have more dimensionallity, then an array with appropriate dimensions to fit your needs.

Here is something you are going to be faced with very soon--you may need more than 1 board to play: the state you are in the start of your turn, and  one to many more to calculate movements.

Les
1 month ago
Lawrence,

There are basically 2 options with several variations on each one:

1 - do it properly with Object Oriented Code
 here you make tiles and place them, the board is then made up of Tiles and a boarder.  You make a mouse listener and add it to each of the Tiles.  The mouse listener tells the tiles where the pointer is located and the Tile that has been placed where the mouse listener highlights itself and the ones that are not where the pointer is, unhighlights themselves.

2 - you do more of the functional programming model and implement a mouse listener.  The mouse listener sets a highlight region (Tile), according to your mouse location (use some math to calculate the (X, Y) and Width Height for the rectangle) and when the screen is repainted, then only the set hightlight region is highlighted.

Les
1 month ago
Please note these lines:

velocities is defined as the same size as coords, but is forces to be accessed as x+1 so it actually runs from 1 to 12, thus exceeding the size of your array.  I suspect the actual error you are getting is related to this.
1 month ago
Please post the exact wording of the error as given.
1 month ago
Campbell,
Every class implicitly extends Object, unless you are explicitly extending Object. All classes are derived from Object.
Les

Campbell Ritchie wrote:

Les Morgan wrote:. . . A sub class is any class that is derived from an existing class: so see "extends".

Les

. . . but don't forget that every class implicitly extends Object if you don't specify another superclass with extends.

emma,

I am not sure what you are saying:



There is a very simple equals Override for Object , so simple in fact that it does nothing except return true for every case.  Could you please give us a small example of what you have tried--an example of what you tried works much better than my crystal ball does at this time.

A sub class is any class that is derived from an existing class: so see "extends".

Les