sakthi moorthy

Ranch Hand
+ Follow
since Oct 17, 2007
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
2
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by sakthi moorthy

HI Guys,

I need suggestion for the following scenario
1) There are X number of word Documents saved in a hard disk
2) In Web application upon some action
2.1) the logged in user details has to be fetched from database
2.2) the User details(userId,UserName,Desigantion (hardly some 9 informations)) has to be filled in one of the documents, which has been mentioned in the Step 1.
3) Generate the PDF with the modified content and send it to browser for download.

Solutions
1) Load All the documents into memory as a String or StringBuffer format while application server start up & replace(fill userid, userName and some information) the String or String Buffer & Generate the PDF
2) Load only the requested or specific document as a String or StringBuffer format & replace the String or String Buffer & Generate the PDF
3) Take the contents of word as constants of String Objects and create java program for generating the PDF.


I Think the first two approach will give OutOfMemoryException if everything gets loaded into memory, The Third approach will be performance impact because of more String operations.

how to do it in efficient way.


Thanks & Regards
S.Sathiya

Wow Thanks SeethaRaman Venkatasamy, gurpeet singh. and while reading JLS, any suggestions or steps to be taken care, before reading and understanding some complex stuff's in Java Language Specification, because i do not want to grasp the concepts wrongly.
Hi nam ha minh

yeah its my mistake making the outter class proctected, i have created an inner class and given public, protected access specifiers, still compilation fails.


Hi ,

The following sentences have been taken from the Java Language Specification Third Edition. and Section 8.1.1

A class declaration may include class modifiers.
ClassModifiers:
ClassModifier
ClassModifiers ClassModifier
ClassModifier: one of
Annotation public protected private
abstract static final strictfp

........................
..................
......................


If two or more class modifiers appear in a class declaration, then it is customary,
though not required, that they appear in the order consistent with that shown
above in the production for ClassModifier.




so from the above quote i understand that a class can have two or more class modifiers and I have tried to create a java class with two modifiers as following




i am getting compilation error. or is there wrong in my understanding.
Thanks Stuart i got it now


I wanted to convey one more thing here the code


will compile fine until the default Constructor HHH() throws IOException or IOException's super type, which means if you want to throw a Exception in Intializer block, the same Exception should be thrown in all Constructors thats what the JLS Says. so the following code wont compile.






Again thanks Stuart
Hi Stuart,


Thanks for the reply. I will tell my understanding of the quoted JLS Sentence.

It is compile-time error if an instance initializer of a named class can throw a
checked exception unless that exception or one of its supertypes is explicitly
declared in the throws clause of each constructor of its class and the class has at
least one explicitly declared constructor



In order to throw a checked exception from Instance Intializer following conditions needs to be statisfied

1) At Least One explicitly declared Constructor Say HHH() in this case has to be present
2) The Same that is HHH() Constructor has to throws A Exception or the Exceptions Super Type, so declared the constructor like following



If above conditions are satisfied, you can have an instance intializer block that can throw a Checked Exception like following


I am not able to relate my understanding with your code, to be specific i am not able to understand why you have kept if block in instance intializer. If i am not wrong, statements under conditional checking block will be executed only on certain condition or conditions, which may or may not happen,thats why that compilation problem has resolved.





Hi All,

I am refering the JLS (Instance Intializers Chapter 8.6) which tells the following thing

An instance initializer declared in a class is executed when an instance of the class
is created (§15.9), as specified in §8.8.7.1.
InstanceInitializer:
Block

It is compile-time error if an instance initializer of a named class can throw a
checked exception unless that exception or one of its supertypes is explicitly
declared in the throws clause of each constructor of its class and the class has at
least one explicitly declared constructor.
An instance initializer in an anonymous
class (§15.9.5) can throw any exceptions.



And i tried to create a code as the per the JLS, i not able to suceed.



i am getting compile time error "Initializer does not complete normally" in line 1, but as per the above quoted JLS Stanza, it should not give compile time error because
1) I have atleast one default constructor
2) that Constructor is also throwing the same Checked, IOException, what i am throwing in intance intializer block

So can someone tell me where i am going wrong here.


HI All,

I came across this question in an interview, how do you make a HashMap as index based like ArrayList. for example the way you insert the elements in the HashMap has to be same as the Way you retrieve elements in the HashMap.

The Answer given by me is "always return the same hashCode so that hashCollision occurs and all the elements will be saved in same bucket." still its not maintaing the index. is there any way to make HashMap index based.


The types of the parameters of the first member method are T1, ..., Tn-1, Tn[].

The types of the parameters of the other method are U1, ..., Uk-1, Uk[].

If the second method is generic then let R1 ... Rp (p ≥ 1) be its type parameters, let Bl be the declared bound of Rl (1 ≤ l ≤ p), let A1 ... Ap be the type arguments inferred (§15.12.2.7) for this invocation under the initial constraints Ti << Ui (1 ≤ i ≤ k-1) and Ti << Uk (k ≤ i ≤ n), and let Si = Ui[R1=A1,...,Rp=Ap] (1 ≤ i ≤ k).



not able to understand what the following equation says, can someone give me the idea.

Ti << Uk (k ≤ i ≤ n), and let Si = Ui[R1=A1,...,Rp=Ap] (1 ≤ i ≤ k).

I am eager to know how you did without final,static,protected keywords



Still there is a draw back in my approach, anyhow i will share how i tried to solve this problem


I have made the class A as abstract and method one() as abstract.





Ease up saloni jhanwar

For class B method one() should be accessible and two() should not be accessible
here accessible means i want to access the method one() of class A,So in class B if you override that method(one()) or

access that method(one()) on another method like following


For class C method one() should not be accessible and two() should be accessible.
above mentioned same is applicable for this statement also, but vise versa.


what craziest thing you wrote above


yeah i used to write craziest thing, because mistakes only makes us to learn perfect things

Thanks for the answers



chain singh



saloni jahnwar wrote:
why you have any doubt?? class B and C should extends class A which is going here this condition satisfied and class C has method two you can check.Does this question state specifically that method two should be of class A ??? i think No.




I think this is your consolidated answer and you are not going to edit it again

ok I will put my question in another way











Note in class B two() method is giving compilation error and class C one() method is giving compilation error

magnifier rules apply

saloni jhanwar wrote:Use private access modifier while you define two() in class A.It is working.cheers



if you use private access modifier while you define two() in class A, will it satisfy the following statement ?
For class C method one() should not be accessible and two() should be accessible.

BTW I just got the answer that may be one of the way, just wanted to know different ways of thinking and innovative idea's from other people

Hint is I have not used final, static,protected keywords as a access specifiers for the methods. let me post the answer soon.


Hi Saloni,

I Really Appreciate the way you are thinking , Just wanted to confirm few things with you the method two() in class A is package or default specifier that means class on Another package cant override it, here comes an error



let me also try parallel, any new ideas are always welcome.

Regards
S.Sathiya
Hi folks,

I have came across this question in an Interview and not able to answer, The Question is
I have a class A which has one() and two() methods, and I have two another classes B and C both extends A.
The Question is
For class B method one() should be accessible and two() should not be accessible
For class C method one() should not be accessible and two() should be accessible.

use access specifiers, put B and C in another package and so on... But the above condition should meet.

I have tried so many things not able to solve this,

Just wanted to know is it possible ?