#1 Difference between SOAP and REST
http://javarevisited.blogspot.in/2015/08/difference-between-soap-and-restfull-webservice-java.html
Why REST is better than SOAP?
Now that you know some differences between REST and SOAP web services, let's summarize our reasons of why REST is better choice for modern day web service requirement :1. REST can be consumed by any client e.g. Java, C++, Python client and even a web browser with Ajax and JavaScript.
2. REST is lightweight as compared to SOAP, it doesn't require CPU consuming XML parsing and it also consumes less bandwidth because unlike SOAP, REST doesn't require a SOAP header for every message.
3. SOAP is an old technology, all modern technical giant are using REST e.g. Google, Twitter, and Flickr.
4. REST is easy to learn, its just nouns and verbs. If you already know HTTP methods then its even easier.
5. Java has excellent support for RESTFul web services, well it also has good support for SOAP web services but you have lots of choices here e.g. Jersey, RESTLet etc.
#2. Variable Arguments (var arg) methods in Java1.5
How variable arguments were handled prior to Java1,5
1. Either overload the method.
2. Can take an array or Collection and pass the no of argument wrapped in array or Collection like List, Set or Map.
Syntax:variable length arguments is presented by 3 dots like display(String...[]) We can replace the one dimensional array with var args like display(String... args)
so all versions of below calling will work
display()
display("hi"),
display("hi","hello")
display(new String("hi","hello")
So it provides greater flexibility because an no of argument can be passed.
Now if we have display(String[] args)
Out of above4 calling only 4th only with array as calling parameters will work,So we can not replace var args with one dimensional array.
Rules:
We can only use only one var args in the method params we can't have display(int... args,int... args1) method like this, compiler will complain
For more than one parameters ,var args should be last like display(int a,int... args)
Q:Why vararg is kept as last param
Ans:because its easy for compiler to map the list of a params to args
like
display(int a,int...args)
calling display(5,10,15,20,30)
it will assign 5 to a and others 10,15,20,30 to args
Every call to varargs method require an anonymous array to be created and initialized which could affect performance in time critical application. There is an alternative of varargs method to achieve better performance. suppose you have a variable argument method sum(int... num) and its called with 2 parameters on 90% of time. In order to avoid array creation and initialization you can use method overloading in Java to provide two versions of sum() which accept int instead of varargs. here is an example of better performance alternative of varargs for 90% of time
public int sum(int a);
public int sum(int a, int b);
public int sum(int... num);
//How to iterate a map to print keys and values separately
Map<String,String> map = new HashMap<String,String>();
map.put("key1", "value1");
map.put("key2", "value2");
map.put("key3", "value3");
// way1: iterate through entry set
for(Entry<String,String> entry: map.entrySet()){
String key =entry.getKey();
String value =entry.getValue();
System.out.println(" key ::"+key+" value "+value);
}
//way2: iterate through map
System.out.println("Iterating the keys in the map");
for (String key :map.keySet()){
String value = map.get(key);
System.out.println(" key :"+key+"Value "+value);
}
#4 Difference between Collections.synchronizedMap(Collection c) and ConcurrentHashMap ConcurrentHashMap
SynchronizedHashMap
#5 What are the points to take care while crafting synchronization policy to entry integrity of data in the face of concurrent access
#6 How does yield() method works
#7 How does join() works
if inside main thread
Thread t = new Thread();
t.start();
t.join(1000);
wait until thread t is done, but if it takes longer than 5,000milliseconds, then stop waiting and become runnable anyway. Param value 0 indicates that main thread to wait forever until t1 is done #8 How many ways Thread can leave running state
|
No comments:
Post a Comment