0% found this document useful (0 votes)
2 views2 pages

Java Spring CheatSheet

This cheat sheet covers the Java Collections Framework, Spring Framework, and Spring Boot essentials. It outlines key concepts such as collection types, dependency injection, bean scopes, and RESTful service creation in Spring Boot. Additionally, it provides sample code for a REST controller demonstrating basic API functionality.

Uploaded by

ms7644942
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Java Spring CheatSheet

This cheat sheet covers the Java Collections Framework, Spring Framework, and Spring Boot essentials. It outlines key concepts such as collection types, dependency injection, bean scopes, and RESTful service creation in Spring Boot. Additionally, it provides sample code for a REST controller demonstrating basic API functionality.

Uploaded by

ms7644942
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Java Collections, Spring Framework & Spring Boot - Cheat Sheet

Java Collections Framework

- Collection Framework: Group of interfaces & classes to handle data as objects.


- Hierarchy:
Collection -> List / Set / Queue
Map is separate (for key-value pairs).
- List: Ordered, allows duplicates. (ArrayList, LinkedList, Vector, Stack)
- Set: No duplicates. (HashSet, LinkedHashSet, TreeSet)
- Queue: FIFO (LinkedList, PriorityQueue)
- Map: Key-value pairs. (HashMap, TreeMap, LinkedHashMap, Hashtable)
- Iterator: For traversing collections.
- Comparable: For natural sorting using compareTo().
- Comparator: For custom sorting using compare().
- Properties: For config values in key-value format.

Spring Framework (Core)

- DI (Dependency Injection): Spring manages object dependencies.


- IoC (Inversion of Control): Spring controls object creation.
- AOP: Used for cross-cutting concerns like logging, security.
- Bean Scopes:
Singleton (default), Prototype, Request, Session, Application.
- Autowiring: Automatically inject dependencies using @Autowired.
- Annotations: @Component, @Service, @Repository, @Controller.
- Life Cycle: @PostConstruct, @PreDestroy for init and destroy callbacks.
- Bean Config Styles: XML, Annotation-based, Java-based (@Configuration).

Spring Boot

- Build Systems: Maven/Gradle for dependency management.


- Code Structure: Organized into controller, service, repository.
- Spring Boot Runners: CommandLineRunner for code on startup.
- Logger: Use LoggerFactory for logging.
- RESTful Services:
@RestController for creating APIs.
@GetMapping, @PostMapping, @PutMapping, @DeleteMapping for methods.
@RequestBody: Accept request JSON.
@PathVariable: Extract values from URL.
@RequestParam: Extract query params.

Sample REST Controller Code

@RestController
public class HelloController {
@GetMapping("/hello")
Java Collections, Spring Framework & Spring Boot - Cheat Sheet

public String sayHello() {


return "Hi";
}

@PostMapping("/add")
public String add(@RequestBody Student s) {
return "Added " + s.getName();
}
}

You might also like