Unmesh Chowdhury

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

Recent posts by Unmesh Chowdhury

Hi,

I want to implement Java EE 7 applications based on the hexagonal architecture (a.k.a. ports and adapters) or onion architecture or clean architecture. Now, the problem is that where I should place my entities. If I place my entities in the application circle then my application will depend on a particular persistence infrastructure, moreover, any kinds of technical infrastructures should not be exposed in the application layer. Thus, the entities should be placed into the persistence adapters, but if so, then when I retrieve entities from the persistence adapter then the dependency rule will be broken, since the rule says that source code dependency can only point inwards, i.e. nothing in an inner circle can know anything at all about something in an outer circle. An alternative could be that I can use DTOs in the application layer and save and retrieve the data through the ports (APIs) that will be defined in the application hexagonal and implemented by the persistence adapters. In this case the duplication of code would be increased definitely, which is a bad design indeed. What should I do in this context?

Thanks,
Unmesh

Related Links:
http://alistair.cockburn.us/Hexagonal+architecture
http://blog.8thlight.com/uncle-bob/2012/08/13/the-clean-architecture.html
Yesterday, I've taken the OCJP6 Exam and scored 93%.

For grasp the concepts according to the objectives the K&B book is the best.
For practicing and drilling the concepts the exercises of the K&B book and the MasterExam are the best.
To get the touch of the real exam and to take the complete preparations according to the objectives the ExamLab is dispensable.
CertPal is also helpful.
My ExamLab history is as follows:
Diagnostic Exam: 91%
Practice Exam1: 83%
Practice Exam2: 90%
Practice Exam3: 86%
Final Exam: 80%
(single attempt)
MasterExam (94%, 97%, 97%)

I think more attempts with ExamLab will be helpful in the real exam.
Last of all, drag and drop questions are deserved more practice otherwise they will can consume unexpected time
13 years ago


MasterExam Quiz A



Which of the following will fulfill the equals() and hashCode() contracts for this class?

According to the MasterExam, the following two are correct answers:

C. return ((SortOf)o).code.length() * ((SortOf)o).bal == this.code.length() * this.bal;
D. return ((SortOf)o).code.length() * ((SortOf)o).bal * ((SortOf)o).rate == this.code.length() * this.bal * this.rate;

C is ok. But I've query about the D. In this case, there is a scope of breaking hashCode() and equals() contracts. The second contract of the hashCode() states that, "if two objects are equal according to the equals(Object) method, then calling the hashCode method on each of the two objects must produce the same integer result."

Now, suppose there are two SortOf objects - the first object is s1, where code = "ja", bal = 2, and rate = 5 and the second object is s2, where code = "va", bal = 5, and rate = 2.

According to the above two objects and the D answer, the equals(Object) method will return true but for the first object the hashCode() will return 4 and for the second object hashCode() will return 10.


How should we tackle this type of question?

Congratulations.
Absolutely, a great Score.
Your appreciation is excellent.
13 years ago
You can try with the following example:
At the compile time which overloaded method will be called is determined by the compiler according to the reference types. And the compiler try to match with more appropriate method. In your case the render(Circle, Shape) method exactly match with your passing reference types. Moreover, if there is no render(Circle, Shape) method in your class then it will be a compile time error since supertype reference can not assigned into the subtype reference.
If the Java language designers let us overridden the instance variable then the instance variable need to be declared with any access modifier rather than private which will break a fundamental principle of object oriented programming, i.e., encapsulation. But, we can override the properties method in the subclasses as follows:
Let’s see how the k = k / --k statement is evaluated as k = 12 / 11 statement.

Initially, k = 12.

k = k / --k, is an assignment statement so the right hand expression will be evaluated first.

Now, k / --k expression will be evaluated from left to right.

k is evaluated as 12 and the value is loaded into the processor register or into the processor cache memory (according to the processor architecture) from the physical memory (RAM).

--k is a pre-decrement and single expression. When it is evaluated, there are two things will be happened – the value of its will be decreased by 1 and a value will be returned. Since it is a pre-decrement expression so the new value will be returned, that is, 11 will be returned. So, --k is evaluated as 11 and the value is loaded into the processor register as usual.

So, the k / --k expression is evaluated as 12 / 11.

(The rest of the story, that is, the execution of the simple integer arithmetic is done by the processor and returns the value accordingly which is 1 and the value is assigned into the k variable.)

In the case of post-increment or post-decrement, the evaluation is done in the same way but return the previous value.
@Abimaran Kugathasan
Explain how?

There is no scope of should be.
int k = 12;

Line 7:
k/=--k;

or, k = k / --k
or, k = 12 / 11
or, k = 1
Line 8:
Print 1

Line 9:
k*=k++;

or, k = k * k++
or, k = 1 / 1
or, k = 1
Line 10:
Print 1

Line 11:
k*=++k;

or, k = k * ++k
or, k = 1 * 2
or, k = 2
Line 12:
Print 2
When a thread is in the runnable or in the run state then the thread is in alive state and there is a thread of execution, that is, a call stack for that thread in the JVM stack. Generally, the alive state of the thread means that either the thread can be chosen by the scheduler any time or the thread is being run.

Now my question is that, what does happen when the thread is in either blocked or waiting or sleeping state?

When the thread stays one of these three states then the thread has been gone to such a state that it can to be alive again but currently it is not alive. If it is true, then what does happen of the thread of execution or call stack of that thread? The thread of execution or call stack has been suspended or totally removed from the JVM stack.
According to your ChicksYack class definition, there is a Chicks type reference variable in every instance of ChicksYack classes which is c.

When you create an instance of ChicksYack at line 12 the c reference variable of the instance gets null typically, after that, you invoke go() method on this instance, so in the go method the instance which is created at line 12 is involved. Now when you assigned a Chicks object in c at line 15, the involved instance’s c reference variable gets the value which was previously null. Now at line 16 and 17 you have created two instances of ChicksYack and their Chicks type references (individual c) are gets null typically and they are not assigned elsewhere but in both threads method is invoked on that references (those are not still refereed any actual Chicks object on the heap by their c reference variables) individually at line 20.
The most basic characteristic of a non-static inner class is that, an instance of an inner class must be tied up with an instance of an outer class. Thus, we can think the regular inner class is an instance member of the outer class. Another basic characteristic of regular inner class is that, it cannot have any static context. Whether you will specify the regular inner class as abstract or final (but not both) is totally depended on your requirements. The following is a very basic example of regular inner class:
The output of the program is JVM depended, that is, in which sequence the JVM starts the threads will dominate the output of the program.