Showing posts with label Java 程式設計. Show all posts
Showing posts with label Java 程式設計. Show all posts

Sunday, December 5, 2021

Spring Professional Certificate Study Guide Section 1-1, Question 16-28

16. What does the @Bean annotation do?

17. What is the default bean id if you only use @Bean? How can you override this?

18. Why are you not allowed to annotate a final class with @Configuration

19. How do you configure profiles? What are possible use cases where they might be useful?

20. Can you use @Bean together with @Profile?

21. Can you use @Component together with @Profile?

22. How many profiles can you have?

23. How do you inject scalar/literal values into Spring beans?

24. What is Spring Expression Language (SpEL for short)?

25. What is the Environment abstraction in Spring?

26. Where can properties in the environment come from – there are many sources for properties – check the documentation if not sure. Spring Boot adds even more.

27. What can you reference using SpEL?

28. What is the difference between $ and # in @Value expressions?

Tuesday, November 30, 2021

Spring Professional Certificate Study Guide Section 1-1, Question 1-15

1.1 Container, Dependency and IOC

In this article, I'm going to answer the first 15 questions of Section 1.1 from the Professinal VMware Spring Certificate study guide. Those questions are:
  1. What is dependency injection and what are the advantages of using it? 
  2. What is an interface and what are the advantages of making use of them in Java? 
  3. What is an ApplicationContext?
  4. How are you going to create a new instance of an ApplicationContext?
  5. Can you describe the lifecycle of a Spring Bean in an ApplicationContext?
  6. How are you going to create an ApplicationContext in an integration test?
  7. What is the preferred way to close an application context? Does Spring Boot do this for you?
  8. Are beans lazily or eagerly instantiated by default? How do you alter this behavior?
  9. What is a property source? How would you use @PropertySource?
  10. What is a BeanFactoryPostProcessor and what is it used for? When is it invoked?

Friday, September 17, 2021

Best Practices & Principles in OOP

SOLID principles

Before even beginning to introduce all the essential OOP principles and patterns, keep in mind that:

  • Focus only on KISS ("Keep it simple and stupid") and OOP Principles first, then observe your code to see which pattern it might need for a code quality improvement -> apply patterns  

1. Single Responsibility 

"A class should have one, and only one, reason to change."

Tuesday, September 14, 2021

Generics in Java

What are Generics?

Enable us to parameterize the type of variables in a class or interface by its definition, so code can be reused for more general types of inputs. Moreover, the type of variables would be checked more thoroughly at compile time, so errors in run-time due to misinterpretation of data are minimized.

Wednesday, August 25, 2021

About Collections and Maps in Java

Today we are gonna have a brief view over the Collection and Map interfaces in Java:

As following diagram shows, while they are all used to save a group of objects of same types, Sets, Lists, Queues and Deques belong to the Collection interface, whereas Maps have their own interface.

Reference: https://www.codejava.net/java-core/collections/java-map-collection-tutorial-and-examples

----------------------------------------------------------------------------------------------------------------------

Friday, August 20, 2021

"Final" Keyword, Immutability and Thread Safety in Java

關於Java的Final關鍵字,Immutability與Thread Safety

1. Definition of "Thread safety": Multiple threads will access a shared object coordinately such that unsaved changes made by one thread would not be overwritten by the other.

How to achieve thread safety?