Although Apache Maven could be installed on Windows, Linux, Solaris and Mac OS systems but today we would discuss about how to install Maven on Windows system. Don't worry if you have Unix based system because we would providing some hints, using that one could easily install Maven in their Unix based systems also.
Saturday, December 16, 2017
Tuesday, December 12, 2017
Differences between @RequestParam and @PathVariable annotations in Spring MVC?
Have you came across @RequestParam & @PathVariable annotation used in the Spring MVC framework? If your answer is yes, then do you know exactly when, one should use @RequestParam or @PathVariable annotation because both the annotations are used to extract data from the incoming request. If your answer is no, then you must learn/know about these annotations because it's widely used in both the traditional web application development & RESTful Web Services development using Spring.
2. Scope
3. When to use which annotations?
4. Where and How of annotations?
5. Conclusion
Table Of Content
1. Introduction2. Scope
3. When to use which annotations?
4. Where and How of annotations?
5. Conclusion
How to add delay in your program?
Would like to add delay for a couple of seconds in your program written in Java, then Thread's sleep() method comes to our rescue. It suspends/delays the execution of the current thread for a specified period.
Choose the required method from overloaded version of sleep() method:
Note:
Look at the main() method, it throws InterruptedException. This is an exception thrown by sleep() method when another thread interrupts the current thread while sleep is active.
Since this application has not defined another thread to cause the interrupt, it doesn't bother to catch InterruptedException. But one should catch the InterruptedException exception using try catch block.
References:
https://docs.oracle.com/javase/tutorial/essential/concurrency/sleep.html
Choose the required method from overloaded version of sleep() method:
public static void sleep(long millis) throws InterruptedException
public static void sleep(long millis, int nanos) throws InterruptedException
- The sleep time is not guaranteed to be precise, because they are dependent on the facilities provided by the underlying OS.
- Also, the sleep period can be terminated by interrupts.
package com.anshulsblog; import java.util.Date; public class TestSleepMethod { public static void main(String[] args) throws InterruptedException { System.out.println("Time before calling sleep() method: " + new Date()); Thread.sleep(5000); //sleep 5 seconds System.out.println("Time after calling sleep() method: " + new Date()); } } Output: Time before calling sleep() method: Tue Dec 12 10:08:17 IST 2017 Time after calling sleep() method: Tue Dec 12 10:08:22 IST 2017
References:
https://docs.oracle.com/javase/tutorial/essential/concurrency/sleep.html
Subscribe to:
Posts (Atom)