Anton Golovin

Ranch Hand
+ Follow
since Jul 02, 2004
Cows and Likes
Cows
Total received
1
In last 30 days
0
Total given
0
Likes
Total received
5
Received in last 30 days
0
Total given
1
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
(keep public parts private until JForum day)
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt
Moderation Tools

Recent posts by Anton Golovin

sreedevi langoju wrote:Hi,
I am preparing for the OCAJP8 certification.While taking the mock exams i found this question.
Here when this break z; statement will get execute ? If not will it become unreachable statement which gives compilation error ?
when i run this program in eclipse it is running successfully .output: 3567

Thanks in advance,
Sree



Sreedevi,

The continue statement immediately goes to the next iteration of the loop whereas the break statement exits the loop. If you have nested loops, and you use continue or break from within the innermost loop in order to exit an enclosing loop, you can use the break and continue statement with a label so that the compiler knows which loop you are exiting.

I think on reading the code, it would have to be some pretty sophisticated static analyzer to report it as unreachable code. It is unreachable for all means and purposes, but the compiler is not designed to catch this sort of thing.

With best regards,

Anton.

Hi, Jason,

This means most nearly that you should abstract your datasource-access functionality in such a way as to make it easily extensible whether you access a file on the filesystem or a database. You don't have to implement database access, but you should make it easy to be able to, should one want to.

Why is this forum so inactive?

With best regards,

Anton.
Hi, Tim, I meant it is not difficult to mis-use ORM technology in terms of the underlying relational paradigm. What you are writing is using the technology correctly via multi-table entities, etc., in the first place.

If used correctly (i.e., approximating how you would use raw SQL), ORM is very powerful. But if not used correctly...

With best regards,

Anton.
1 year ago

s ravi chandran wrote:Hi,

I am a java programmer with 7 years of development experience. I wish to join some open source project to learn more and to contribute to some projects that are under development.

I have most of my experience in core java and Middleware programming. How and where should I search for such projects.

Thanks



Hi, Ravi,

The best way to join an open source project is to start your own. GitHub is a great place for interaction.

There are so many unmet software needs that would greatly benefit from a pre-written solution and make other people's lives easier.

Think about what it could be.

Think about Hadoop - it was once only a figment of someone's imagination. Now it is the de facto standard for parallel computing in Java.

So just set your mind to it, come up with an interesting idea, and soon you will have others joining in.

With best regards,

Anton.
1 year ago

dipti zone wrote:I have cleared Oracle Certified Professional Java Programmer exam (OCPJP). Oracle is giving me some offer for the higher level exam. Shall I take Oracle Certified Web Component Developer (OCEJWCD) or any higher version of Java like OCPJP8(JDK1.8).



Hi, Dipti,

I don't put much value in certifications, so I would say, only to give you the confidence that you have mastered the skills being tested. Rote memorization for the sake of rote memorization is not recommended.

It is useful sometimes when you have a chance to work on a technology and want to get up to speed quickly. But in general, the value of certifications is when they prove an existing skill (first and foremost for you yourself because confidence in yourself contributes pretty significantly to success as well as having a skill).

With best regards,

Anton.

neerav arora wrote:Could anyone please help me in Question number 20 at the following link webpage .  How can there be more than two A's,B's,C's in the output ?



Hi, Neeraj,

Any one thread will always write at most up to 2 As, 2 Bs, and 2Cs; however, there are two of them, so you may get up to 4 As, 4 Bs, and 4 Cs in some weakly determined order but i would surmise always starting with an A?

With best regards,

Anton.

jon ninpoja wrote:hi guys,

wrote a simple bridge length program that only lets you create a bridge no less than 20m up to 150m using
accessors and mutators...

here is the code:



i removed "this" from:
this.bridgeLength = bridgeLength;

now it always gives me 0 as the value...im sure its pretty simple (and i prob should know this by now)
what value is the .this giving the variable

from what i read...this will use the instance variable instead of the local one right?
but i thought nothing was assigned to the local variable,its just declared...is that why it gets 0

think im confused:
local variables are assigned null,0 if no assignment right? is it instance variables that wont give a default value?

thanks



Hi, Jon,

When you don't use in this particular instance, the variable you're using then is the same as the variable of the parameter you're passing in, and it exists only for the duration of the method run, hence you never set the instance variable in your class, which is initialized by default to 0 and is never altered by you later one.

With best regards,

Anton.
1 year ago

Rajeev Srikhar wrote:Thanks for replying, actually I got the ResultSet by using Stored Procedure like you mentioned. But I'm curious to use cursors in stored procedures and retrieve Result set data in java program.



Hi, Rajeev,

Should only use cursors when line by line data-processing on your result set is unavoidable for some reason. Have pity on your db server.

Read up a good recent book on MS SQL server, Amazon has plenty.

With best regards,

Anton.
Hi, Serge,

This code calls for breaking the overall code into smaller parts and combining them. Then, the error will show itself easily.

Otherwise you should really love polynomials in order to delve into this code for the error.

With best regards,

Anton.
1 year ago

Dipanjan Pramanik wrote:A bluej java program to print the position of the character which has double letters......
Example: Little star shinning bright
It is tt and nn

here is my program:
import java.io.*;
class Abc
{
    static void main() throws IOException
    {
    BufferedReader obj= new BufferedReader(new InputStreamReader(System.in));
    System.out.println("Input a String");
    String s= obj.readLine();
    s=s+" ";
    for(int i=0;i<(s.length()-1);i++)
    {
         System.out.println("The chars to check:"+s.charAt(i)+" "+s.charAt(i+1));
        if( s.charAt(i)== s.charAt(i+1))
        {
            System.out.println("The position of the character is:"+(s.indexOf(s.charAt(i+1))));
        }
}}}



Dipanjan, use available data structures, put it in a Map<Char, Integer>, get the stream of that and use a lambda to get at a Collection<Char> with the condition that the Integer in that Map would be > 1, something like that. Or use loops. But definitely use a Map<Char, Integer>.

Then, loop through the char array of that String and make another Map<Char, List<Integer>> and add to that list when you encounter that char...

You will end up with a Map that has a Char key and a List of its locations with the String you're parsing.

You can then use that data for further analysis on these chars.

With best regards,

Anton.
1 year ago

Mike Curwen wrote:I'm looking for advice on the best approach to a problem like the following.  I have an object that is responsible for retrieving rows from a database and doing quite a bit of processing for each entry. It also does further queries for each row, does a bit of templating and merging, potentially generating an email.  Right now, the object just takes the selection criteria in the form of a key; work on all the rows that have 'this' value in the status field.



What if my rowcount is in the thousands?  Right now it's just hundreds, and a single thread takes an acceptable amount of time.  Eventually, I'm going to click a button, and it will take all night.  So I want to multithread this...

My questions is.. where do the threads go?

1)
Should I produce a 'Manager' object? Move the overall query from the existing class into this manager object, turn it into a SELECT COUNT(*) rather than SELECT *, have it divide by the 'maxThreads', and then instantiate 'maxThreads' instances of my (now slightly modified) processing object.  Each modified object would then work on its own subset of rows. The only change in the existing processor object (I think) is the method signature would be two long ids, rather than one and the query would change from SELECT * where status=id to SELECT * where row_id between first_id AND last_id.  Otherwise, all the code remains the same.

2)
Forget the 'Manager' and simply implement threads within the existing class?

Is there a best practice here?  Is there a better idea?



hmm... I just thought better of this.  While currently, my rows are pretty much always in a contiguous block, this is not a guarantee.  And the way MySql does LIMIT is not safe either:
If you use LIMIT # with ORDER BY, MySQL will end the sorting as soon as it has found the first # lines instead of sorting the whole table.


So I think I need to retrieve all the PK's and stuff them into a List. Then send sublists into the processor object. Yes?
[ December 31, 2003: Message edited by: Mike Curwen ]



Hi, Mike,

Don't reinvent the wheel, what you are trying to do is processing- and io-intensive, use an available enterprise-grade component such as Quartz in Java to process your workload. You can cluster Quartz but you will have to come up with a mechanism for partitioning your data yourself so that a Quartz job picks up a portion of your total workload.

I am not sure if that's the answer you're looking for. I don't think you should mess with thread pools and the like when all you really want is dependable parallelism. No job is too small for Quartz.

With best regards,

Anton.

Harish Shivaraj wrote:Hi all.

Im asking things,because im not sure if this is a best practice or how would you do it?

I have a database called Vehicle and query the database using JDBC. I have wrapper around the JDBC library such that every time i do a select on the table it return me a list of object with each object corresponds to a row in the table.

I mean this

Table - Vehicle

Select method

public ArrayList<Vechile> Select(...) { .. }

Would you do it this way or would you just return the ResultsSet? I found it much neater when ? I return the Vehicle object where each row data is content within an object.

Thanks



Hi, Harish,

So you found the ORM concept which parses the ResultSet for you and which puts data into objects and returns the objects to you.

This is much more convenient, but not without its pitfalls.

For example, in raw SQL you will have not only direct selects, but joins and sometimes queries that should calculate data on the fly before returning it to you. I am just giving you some hints about using ORM correctly because if you use it to get array on entities mapped to single tables, and you need to do joins, you will find yourself bringing that data into the code and transforming it there - not a performant way to work with ORM.

So, multi-table entity mapping and custom entity types to the rescue (including using stored procedures as supported). Even if now it does not tell you much, as you progress in your skills with ORM, keep it in mind.

ORM is very convenient but you must model it to your schema very carefully to keep your application performant.

With best regards,

Anton.
1 year ago
Shankara,

Are you properly identifying the primary key in your Hibernate entity (simple or compound)? If you don't, Hibernate won't know what it is. If you're using annotations, there is a specific annotation for that; if you're using xml, there is specific xml for that.

With best regards,

Anton.
Hi, Dawn,

In general...

You must iterate a linked list in O(N) fashion, meaning just iterate to the middle of the list (this list must know how many items are in it with a simple method call) and rearrange the references in the item just before the middle and just after the middle to point to a new item that you are inserting.

You have to account for a fact that a doubly linked list is traversable in both directions, so references must be re-assigned not in one (for a singly linked list it is ok) but in two objects just before and after the insertion point.

With best regards,

Anton.
1 year ago

Peter Park wrote:Beginner here,

This is from another thread:  https://coderanch.com/t/245950/certification/Exam-Prep-post-increment I read but I could not understand what the JMM125.i on the last line of code means. Especially that period between the JMM125 and i. What does it do to make it come out as a 3?

Explanation? Thank you!



Product:

1
2
1
2
0
1
3



Hi, Peter,

When you loop within the static main method, you don't declare a new int variable in your loop, you assign a value to one that already exists, the static one. You don't have to qualify the static variable's name with class name if you don't want to. It's a tricky piece of code. I would always qualify for readability.

So basically, it increments the static i variable and then prints out its last value.

With best regards,

Anton.
1 year ago