https://reflectoring.io/getting-started-with-spring-webflux/
static
method in Java?throw
and throws
in Java.transient
keyword?ArrayList
and LinkedList
?HashSet
, LinkedHashSet
, and TreeSet
differ?HashMap
and ConcurrentHashMap
.hashCode()
and equals()
methods.fail-fast
and fail-safe
iterators.https://www.sohamkamani.com/java/kafka/
https://developers.redhat.com/articles/2022/04/05/developers-guide-using-kafka-java-part-1#what_setup_do_you_need_to_get_started_
public static void main (String arg[]) {
List<Integer>numbers= Arrays.asList(10,3,56,7,8);
System.out.println(numbers.stream().sorted(Collections.reverseOrder()).skip(1).findFirst().get());
System.out.println(numbers.stream().sorted().skip(1).findFirst().get());
}
https://www.javaguides.net/2022/07/event-driven-microservices-using-spring-boot-and-apache-kafka.html
To run Apache Kafka from the binary distribution, you need to follow a series of steps. Below are the general steps for running Kafka on a Unix-like system (Linux or macOS). Make sure you have Java installed on your machine before proceeding.
Java Installation: Ensure you have Java installed on your system. You can check your Java version using:
bash
java -version
If Java is not installed, you can install it by following the instructions for your operating system.
Download and Extract Kafka: Download the Kafka binary distribution from the official Apache Kafka website. Once downloaded, extract the contents of the tarball:
bash
tar -xzf kafka_2.12-3.7.0.tgz
cd kafka_2.12-3.7.0
Kafka uses ZooKeeper, so you need to start it before starting Kafka.
bash
bin/zookeeper-server-start.sh config/zookeeper.properties
In a new terminal, start the Kafka server.
bash
bin/kafka-server-start.sh config/server.properties
In another terminal, you can create a Kafka topic to test your setup.
bash
bin/kafka-topics.sh --create --topic mytopic --bootstrap-server localhost:9092 --partitions 1 --replication-factor 1
You can now use the Kafka producer and consumer to test your setup.
Producer:
bash
bin/kafka-console-producer.sh --topic mytopic --bootstrap-server localhost:9092
Consumer:
bash
bin/kafka-console-consumer.sh --topic mytopic --bootstrap-server localhost:9092 --from-beginning
Type messages in the producer terminal, and you should see them being consumed in the consumer terminal.
These are basic steps to run Kafka locally for testing and development. In a production environment, you may need to configure Kafka appropriately for your specific use case and environment. Additionally, consider creating systemd service files or using other deployment tools based on your needs.
// @ExceptionHandler({MethodArgumentNotValidException.class})
// public ResponseEntity<ApiFail> handleValidationExceptions(
// MethodArgumentNotValidException ex, HttpStatus httpStatus) {
// Integer error_code_global = ex.hashCode();
// Map<String, String> errors = new HashMap<>();
// ex.getBindingResult().getAllErrors().forEach((error) -> {
// String fieldName = ((FieldError) error).getField();
// String errorMessage = error.getDefaultMessage();
// Integer error_code = error.hashCode();
// errors.put(fieldName, errorMessage);
// });
// Map data = new HashMap();
// data.put("field", errors);
// return new ResponseEntity<ApiFail>(new ApiFail(error_code_global, data), HttpStatus.BAD_REQUEST);
// }
@Override
protected ResponseEntity<Object> handleMethodArgumentNotValid(MethodArgumentNotValidException ex, HttpHeaders headers, HttpStatusCode status, WebRequest request) {
Map<String, Object> errorMessageBody = new LinkedHashMap<>();
Map<String, Object> resBody = new LinkedHashMap<>();
ex.getBindingResult()
.getFieldErrors()
.stream().forEach(error->{
errorMessageBody.put(error.getField(),error.getDefaultMessage());
});
resBody.put("success", false);
resBody.put("message_code", status.value());
resBody.put("data", errorMessageBody);
return new ResponseEntity<>(resBody, headers, status);
}
// import static org.junit.jupiter.api.Assertions.assertEquals;
// import org.junit.jupiter.api.Test;
import java.util.*;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class Main {
public static void main(String[] args) {
System.out.println("Objects are equal:"+Color.REDP.getHexCodevs());
System.out.println("Objects are equal:"+Color.REDP.getHexCode());
}
}
enum Color {
REDP("FF0000","opp"),
GREEN("00FF00","opl"),
BLUE("0000FF","niop");
private final String hexCode;
private final String vs;
// Constructor for enum constants
Color(String hexCode,String vs) {
this.hexCode = hexCode;
this.vs=vs;
}
// Getter method
public String getHexCode() {
return hexCode;
}
public String getHexCodevs() {
return vs;
}
// Custom method
public void displayInfo() {
System.out.println("Color: " + this.name() + ", Hex Code: " + hexCode);
}
}