I have a Java class which is the data-model of a table in DynamoDB. I want to use the DynamoDBMapper to save and load items from Dynamo. One member of the class is a List<MyObject>. So I used the JsonMarshaller<List<MyObject>> to serialize and de-serialize this field. The list can be success…
What does decoupling two classes at the interface level mean?
Lets say we have class A in package A and class B in package B . If object of class A has reference to class B, then the two classes are said to have coupling between them. To address the coupling, …
My JSch session doesn’t execute command
I’m trying to write a Java code that can ssh into a Unix server and reset a user’s password. So I tried to implement some of the code found in SO. Eg. Sending commands to remote server through ssh by Java with JSch Take commands(password) from string and set as InputStream to Unix servers in Java …
How to calculate a length of array with out using library
yesterday I appeared in interview,interviewer told me to write a code for calculating a length of array with out using a length property of Array class. For examaple- All answer given here are using String library. Answer
MIDI – MidiMessage Program Change with Instrument From Different Bank
The soundbank of the default synthesizer I’m using contains a variety of different instruments. For example, this code snippet… … prints the following: I can play an instrument from any of these banks through MidiChannel, the programChange method, and noteOn, like so (this plays instrument 1…
Preserve Java stack trace across threads
I am using ExecutorService to send mails asynchronously, so there is a class: That handles the sending. Any exception that gets caught is logged, for (anonymized) example: Not very helpful – I need to see the stacktrace that invoked the ExecutorService that caused all of this. My solution is to create a…
How many objects are created in StringBuilder?
Based on my understanding on String objects, that every string literal is being added/created on the String Constant Pool. two objects are being created, one is the “hello world” being added on the constant pool and the other object is the new instance of String. Does the same principle is being a…
How to enable query logging in Spring-data-elasticsearch
I use spring-data-elasticsearch framework to get query result from elasticsearch server, the java code like this: While how can I know the raw http query sent to elasticssearch server? How can I enable the logging, I tried add log4j, but it seems the spring-data-elasticsearch doesn’t log the query. Answ…
Why method overloading is the best example of static binding in Java?
In java, I know that we have some differences between static binding and dynamic binding and method overloading is the best example of static binding but I don’t know why it is the method overloading instead of the the method overriding? Answer Method overloading is determined at compile time. The compi…
Java simpledateformat Unparseable date, even though the format appears to be right
I’ve got a silly problem, here’s my code: the result is following: Fri Jun 05 2015 15:34:29 GMT+0000 null Unparseable date: “Fri Jun 05 2015 17:30:00 GMT+0000” What’s wrong with my format? It outputs the current date in the same format as the date I want to parse, but keeps telli…