Win a copy of Murach's MySQL this week in the JDBC and Relational Databases forum!

Praveen Kumar M K

Ranch Hand
+ Follow
since Jul 03, 2011
Merit badge: grant badges
For More
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Praveen Kumar M K

Needless post alert

You can add all the existing numbers in the array and find the difference between that and [Summation(1-50)], and then do a full scan of the array to find the missing numbers using a little intelligence. An example here,

Say you were working with numbers 1 to 10. And the input array was like this 1, 2, 3, 4, 7, 8, 9, 10 with 5 and 6 missing (sorted/unsorted doesnt matter here).

So we have Summation(1 to 10) - Summation(input array) = 11. Now 11 can either be due to (1,10), (2,9), (3,8), (4,7) etc. Do a linear scan and and when you find a number in one of these combinations, you can eliminate that particular combination of numbers.(Also, if you find 2 in the input array you dont have to check for 9).
Agreed. But, irrespective of what getConnection returns, from your functions perspective, you know that the reference can only have 2 states, either null or not null. Wouldn't that be much easier?

The point am trying to make here is purely on the lines of best practice, nothing technical. Am just thinking it would be better to initialize the variables to a known quantity apriori, so that its much easier to program the rest of the stuff around that value.
11 years ago

Campbell Ritchie wrote:
Of course, if your variables are reference types, you cannot initialise them to 0. You would have to use null, and as you doubtless know, nulls are dangerous. You will find discussion of null problems and other mistakes, in this thread.
The same applies to fields, though they do have default values.

A little confused about this part. Consider this small piece of code

Am I wrong in writing something like this? Lets says I had to use conn reference across the entire function and not just under the scope of 1 try-catch block.
11 years ago
The message was indeed right, in a different way

Unlike C and C++, Java enforces strict type checking extensively during compilation. Here the individual expressions of your if statement i.e., intentToGraduate = true and majorSheet = true
did not yield a boolean type with value "true" or "false" as they were assignment operations. Hence you got an unexpected type error.
11 years ago
Could you please post the question in full, I dont have the book

I'm afraid this is not how you do an equality check. You would have to use the equality operator rather than the assignment operator. Pleas go through this link -> Equality operators
11 years ago
In case the problem statement needs to incorporate so many conditional checks, wouldn't a rules engine help? I personally haven't implemented it myself, but have seen colleagues doing it.
11 years ago

Wout Er wrote:

Henry Wong wrote:
if the variable had been a Boo instance (and reference), then it would have been allowed to access the protected resource defined by the Roo class.

Henry, thanks for pointing this out and luckily this works! Still, I don't see the rationale for why it doesn't work on a Roo-typed reference within subclass code in another package, while it does within any code in the same package.

Ok, probably you can think of a hypothesis like this. What difference does it make if these 2 lines of code were in package b or package c or package d OR within class Boo(subclass) or any class Foo(not subclass)? There is no absolutely no difference.
11 years ago
Sure, but wouldnt it be easier to make just this change in your main function

The idea here with the static instance is to work with only ONE instance of WorkerLoad object, else it would be of no use.
11 years ago
Welcome! Do share here the change that you did, so that other ranchers can benefit.
11 years ago
Again, this is you main function

And this is the call in check method

Here you are fetching the static instance variable and calling the getWork method on it. Has this static instance variable been assigned to anything?

abc.getWork() is not equal to WorkerLoad.getInstance().getWork();
11 years ago
Oh so your running class is WorkerLoad!(When you said that the second class succeeded, it put me off track)

instance is a static variable, but the very first line of main creates a new WorkerLoad object. So where are you connecting that to instance
11 years ago
In WorkerLoad, I dont see a call being made to the method loadFromDb.
11 years ago
Well considering that you have an array(which in actuality is an array of arrays) you want to write a program to convert from Ain to Aout on the same array. Hope I got that right.

Ain =
1 2 3
4 5 6

Aout =
1 4
2 5
3 6

It is not possible either in C or in Java to convert a 2x3 array to 3x2. A single array's dimensions and capacity are fixed during compile time and you cannot change that programmatically.

You can take an input array, create an output array(with dimensions switched) and then iterate and fill the output array.
Thank you and you are welcome
11 years ago