[{"content":"In this article, you’ll discover what YOLO is and how to use it to analyze a video and detect and count people within it.\nWe’ll walk through a simple Python script that lets you configure basic parameters and choose the most appropriate video source for your needs.\nWhat is YOLO? YOLO (You Only Look Once) is a real-time object detection algorithm based on neural networks.\nPut simply, YOLO analyzes each video frame (whether from a file or a webcam/IP stream) to identify objects such as people, vehicles, animals, and more.\n🔗 For an in-depth look at YOLO, check out this link.\nWhat is OpenCV? OpenCV (Open Source Computer Vision Library) is a powerful open-source library originally developed by Intel. Its main goal is to facilitate image processing and computer vision.\nWith OpenCV, we can process video frames and visually display recognized objects by drawing bounding boxes around them.\n🔗 Want to know more about OpenCV? Visit this link.\nWhat is Python? Python is one of the most popular programming languages in the world. It’s known for its simplicity and power, and is widely used in data science, AI, and automation.\n🔗 We’ve already covered Python in this article.\nThe Idea This mini-project is meant to be a gentle introduction to artificial intelligence, allowing us to get started without too much complexity or overwhelm.\nWhat You Need Here’s what I used for this project:\nPython 3.12.6 YOLO 8.3.169 OpenCV 4.12.0.88 GPU Nvidia GeForce RTX 3060 Ti The Code The script was designed to let users configure the following:\nSelect the YOLO model to use Choose the video source (file, webcam, IP stream) Enable or disable GPU usage Depending on the chosen settings, the performance and playback speed may vary.\nOnce the settings are selected, the appropriate YOLO model is automatically downloaded.\nThe core functionality is implemented in the cv_player.py file.\nInitializing the Output Window The video frame dimensions are read:\nframe_height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) frame_width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) The frames per second (fps) value is also retrieved:\nframes_per_second = int(cap.get(cv2.CAP_PROP_FPS)) Frame Analysis and Tracking Each frame is analyzed using the selected YOLO model:\nresults = model(img, stream=True, device=selected_device) From the detection results, we extract the coordinates to draw bounding boxes.\nThe script also uses the deep_sort_realtime library to assign a unique ID to each detected person, making it possible to track them across frames:\ntracker = DeepSort(max_age=frames_per_second) Visual Output We update the frame with tracking info:\ncvzone.putTextRect(img, f\u0026#39;ID: {track_id}\u0026#39;, (x1, max(30, y1 - 10)), scale=1, thickness=1) cvzone.putTextRect(img, f\u0026#34;Detected {len(unique_ids)} unique people\u0026#34;, (15, 25), scale=0.75, thickness=1) cv2.imshow(\u0026#34;main\u0026#34;, img) Conclusion This was my first hands-on experience with YOLO, OpenCV, and object detection through AI.\nI hope to improve this script or build new ones in the future to dive deeper into the world of computer vision and artificial intelligence.\n🔗 For the full code, click this link.\n💬 Got suggestions or feedback? Feel free to leave a comment below!\n","permalink":"https://antoniomontemurro.com/en/posts/yolo-opencv-python-count-people/","summary":"\u003cp\u003eIn this article, you’ll discover what YOLO is and how to use it to analyze a video and detect and count people within it.\u003cbr\u003e\nWe’ll walk through a simple Python script that lets you configure basic parameters and choose the most appropriate video source for your needs.\u003c/p\u003e\n\u003ch2 id=\"what-is-yolo\"\u003eWhat is YOLO?\u003c/h2\u003e\n\u003cp\u003eYOLO (You Only Look Once) is a \u003cstrong\u003ereal-time object detection\u003c/strong\u003e algorithm based on neural networks.\u003cbr\u003e\nPut simply, YOLO analyzes each video frame (whether from a file or a webcam/IP stream) to identify objects such as people, vehicles, animals, and more.\u003c/p\u003e","title":"Detecting and Counting People with YOLOv8"},{"content":"In all programming languages, one of the most important aspects is code organization and readability. In Python, as in many other languages, this goal is also achieved through the use of functions.\nBy convention, all the code we write is executed within a main function, often called main. However, we can—and should—split our code into multiple functions to simplify maintenance and encourage reuse.\nWhat are functions in Python? The function definition in Python is done using the def keyword, followed by the function name and parentheses. There are two main types of functions:\nFunctions with a return value Functions without a return value Let’s look at both types in detail.\nFunctions with a return value These functions return a result to the caller using the return keyword. They are useful when we need to use the output of a computation.\ndef compare_x_and_y(x, y) -\u0026gt; bool: if x \u0026gt; y: return True else: return False Functions without a return value These functions do not return any value. They are used to perform operations such as printing to the screen or modifying global variables, without needing to return a result.\ndef print_even_numbers(numbers): for elem in numbers: if elem % 2 == 0: print(elem) Conclusion In this article, we explored the function definition in Python, highlighting the difference between functions with and without a return value. Functions are a fundamental tool for writing clean, reusable, and testable code.\nIn the next tutorials, we’ll cover more advanced use cases of functions, including optional parameters, nested functions, and lambda expressions.\nYou can find the example code at this link.\n","permalink":"https://antoniomontemurro.com/en/posts/function-in-python/","summary":"\u003cp\u003eIn all programming languages, one of the most important aspects is code organization and readability. In Python, as in many other languages, this goal is also achieved through the use of \u003cstrong\u003efunctions\u003c/strong\u003e.\u003c/p\u003e\n\u003cp\u003eBy convention, all the code we write is executed within a main function, often called \u003ccode\u003emain\u003c/code\u003e. However, we can—and should—split our code into multiple functions to simplify maintenance and encourage reuse.\u003c/p\u003e\n\u003ch2 id=\"what-are-functions-in-python\"\u003eWhat are functions in Python?\u003c/h2\u003e\n\u003cp\u003eThe function definition in Python is done using the def keyword, followed by the function name and parentheses. There are two main types of functions:\u003c/p\u003e","title":"Function Definition in Python"},{"content":"If you’re reading this article, it’s probably your first experience with Java — and perhaps with programming in general. In this article, we’ll go over how to install the Java SDK, choose an IDE, and write a simple program to make sure everything is working correctly.\nAfter discussing why Java can be a great choice for both beginners and experienced developers, let’s now see how to install the Java SDK and choose the most suitable IDE.\nInstalling Java First of all, unless you have specific requirements, the best thing to do is visit this link and, in the “Java Release Support Timeline” section, identify the latest LTS (Long Term Support) version.\nOnce you’ve found the version to download, go to this link to get the desired SDK (we’ll soon see how IntelliJ can also handle this step for you).\nOnce installed, you can verify that Java has been correctly installed by opening a terminal or command prompt and typing:\njava --version If the terminal responds by showing the Java version, the installation is complete.\nIf instead the terminal doesn’t recognize the command, you’ll need to add the SDK to your system’s environment variables. I recommend following a guide specific to your operating system.\nWhich IDE Should You Use? Now that Java is installed, the next question is: which tool should you use to write and run your code?\nWhat Is an IDE? An IDE (Integrated Development Environment) is an application that provides helpful tools for software development. Two key features are the debugger and IntelliSense:\nIntelliSense: This auto-completion feature reduces typing time and minimizes syntax errors. Debugger: Helpful for analyzing your code, it assists in identifying and fixing bugs. IntelliJ There are several IDEs that support Java. Many are free, and others offer a free basic version.\nWe’ll use IntelliJ, in its free Community Edition. Once downloaded, start the installation and, when prompted, I recommend selecting all available options.\nAfter installation, we’re ready to write our first Java program.\nHello World There’s nothing more classic for a developer than starting with a “Hello World” program.\nOpen IntelliJ and accept the terms of use on first launch. If you already have other IDEs installed, IntelliJ may ask if you want to import their settings.\nClick “New Project”, give your project a name (e.g., helloWorld), choose a destination folder, and leave the default settings. Then click “Create”.\nIntelliJ is a fairly complete IDE, so it will likely generate everything needed for your “Hello World” automatically.\nIf it doesn’t, or if you chose a different IDE, here’s the code you’ll need to write:\npublic class Main { public static void main(String[] args) { System.out.println(\u0026#34;Hello world!\u0026#34;); } } ","permalink":"https://antoniomontemurro.com/en/posts/install-java-and-choose-ide/","summary":"\u003cp\u003eIf you’re reading this article, it’s probably your first experience with Java — and perhaps with programming in general. In this article, we’ll go over how to install the Java SDK, choose an IDE, and write a simple program to make sure everything is working correctly.\u003c/p\u003e\n\u003cp\u003eAfter \u003ca href=\"/en/posts/why-learning-java/\"\u003ediscussing why Java can be a great choice\u003c/a\u003e for both beginners and experienced developers, let’s now see how to install the Java SDK and choose the most suitable IDE.\u003c/p\u003e","title":"Installing Java and Choosing an IDE"},{"content":"\nJava is an object-oriented programming (OOP) language, known as a strongly-typed language, meaning that variable types are specified statically directly in the source code.\nJava was created in 1992 at Stanford University under the name “Oak,” later renamed to “Java” due to copyright issues (source).\nThe main strength of Java is probably its portability: it can run on different platforms without modifying the code, making it extremely versatile and contributing to its widespread adoption.\nAdvantages and Features The main features of Java include:\nEase of Learning: It is one of the easiest programming languages to learn. Portability and Independence: Once written, the code can run on any platform equipped with a Java Virtual Machine (JVM). Object-Oriented: Java follows the object-oriented programming paradigm. Type Safe: Being a strongly-typed language, every variable has a defined and immutable type. Continuous Support: Java is constantly updated with new features and fixes. Initially, new versions were released every two years; today, a new version is released every six months, and every three years a Long Term Support (LTS) version is provided with extended support. Use Cases Thanks to its simplicity and versatility, Java is used in a wide range of fields, including:\nSoftware development (cloud and mobile applications) Big Data Game development Why Learn Java? The simplest answer might be: “Why not?”\nOver the years, Java has earned a prominent position in the software development world, as confirmed by GitHub data (source).\nAs previously mentioned, Java has an accessible learning curve and is cross-platform, meaning you can develop applications compatible with Windows, macOS, and Linux without having to create separate codebases.\nIf you want to learn more, visit the official Java website or explore our dedicated section in the top menu.\n","permalink":"https://antoniomontemurro.com/en/posts/why-learning-java/","summary":"\u003cp\u003e\u003cimg alt=\"Logo Java\" loading=\"lazy\" src=\"/img/why-learning-java/java_img.webp\"\u003e\u003c/p\u003e\n\u003cp\u003eJava is an object-oriented programming (OOP) language, known as a strongly-typed language, meaning that variable types are specified statically directly in the source code.\u003c/p\u003e\n\u003cp\u003eJava was created in 1992 at Stanford University under the name “Oak,” later renamed to “Java” due to copyright issues (\u003ca href=\"https://en.wikipedia.org/wiki/Java_%28programming_language%29\"\u003esource\u003c/a\u003e).\u003c/p\u003e\n\u003cp\u003eThe main strength of Java is probably its portability: it can run on different platforms without modifying the code, making it extremely versatile and contributing to its widespread adoption.\u003c/p\u003e","title":"Java: What It Is and Why You Should Learn It"},{"content":"In all modern programming languages, conditional statements and loops are essential for two primary purposes:\nMaking decisions based on given or computed values. Automating repetitive tasks to avoid rewriting the same code. If…else The if...else statement allows you to change the normal flow of code execution by evaluating a specific condition.\nHere is an example\nx = int(input(\u0026#34;Insert a number:\u0026#34;)) if x % 2 == 0: print(\u0026#34;Your number is even\u0026#34;) else: print(\u0026#34;Your number is odd\u0026#34;) This code will print a different message depending on whether the value entered by the user is an even or an odd number.\nIn Python, there is also a variation called elif, which allows you to chain multiple conditions. For example:\nx = int(input(\u0026#34;\\n3Insert a number greater than 0:\u0026#34;)) if x == 0: print(\u0026#34;Invalid value!\u0026#34;) elif x \u0026gt; 0: print(\u0026#34;You inserted a positive number!\u0026#34;) else: print(\u0026#34;You inserted a negative number!\u0026#34;) With this code, we can check if the entered value is not 0, and if it isn’t, determine whether it is positive or negative.\nLoops in Python Python supports two main types of loops: for and while. Both are used to repeat blocks of code without rewriting them, but they differ in their logical behavior:\nwhile: Executes the code as long as a specified condition remains true. for: Iterates over a collection of data (such as lists, tuples, or strings) and executes the code for each element in the collection. Here are a couple of examples:\nWhile Loop print(\u0026#34;Printing all values from 10 down to 6...\u0026#34;) x = 10 while x \u0026gt; 5: print(x) x = x - 1 In this example, the while loop prints numbers starting from 10 and continues until the value of x is greater than 5. In each iteration, the value of x is decreased by 1.\nFor Loop fruit_list = [\u0026#34;Apple\u0026#34;, \u0026#34;Banana\u0026#34;, \u0026#34;Coconut\u0026#34;, \u0026#34;Raspberry\u0026#34;, \u0026#34;Strawberry\u0026#34;] print(\u0026#34;Printing all elements in the list...\u0026#34;) for fruit in fruit_list: print(fruit) This example uses a for loop to iterate over a list of fruits and prints each element in the list.\nCombining Loops and If…else We can combine loops with conditional statements (if...else) to create more complex logic. Specifically, the continue and break statements allow us to control the flow of loop execution.\nExample with continue print(\u0026#34;Printing all elements in the list except for Banana...\u0026#34;) for fruit in fruit_list: if fruit == \u0026#34;Banana\u0026#34;: continue print(fruit) In this case, the loop prints all the elements in the fruit list except “Banana”. The continue statement skips the current iteration and proceeds with the next one.\nExample with break print(\u0026#34;Printing all numbers in the list. Break the loop if there is any non number element\u0026#34;) number_list = [1, 2, 3, \u0026#34;a\u0026#34;, 4, 5] for x in number_list: if type(x) is int: print(x) else: print(f\u0026#34;Found not number element: {x}\u0026#34;) print(\u0026#34;For Loop will be terminated immediately\u0026#34;) break Here, the loop stops execution as soon as it encounters an element that is not a number. Unlike continue, the break statement terminates the loop entirely and moves to the next instruction in the program.\nConclusions Conditional statements and loops are essential tools for automating tasks and making decisions in Python programs. In future tutorials, we will delve deeper into their practical applications.\nFind the link to the example codes here.\n","permalink":"https://antoniomontemurro.com/en/posts/control-flow-loops-python/","summary":"\u003cp\u003eIn all modern programming languages, conditional statements and loops are essential for two primary purposes:\u003c/p\u003e\n\u003col\u003e\n\u003cli\u003eMaking decisions based on given or computed values.\u003c/li\u003e\n\u003cli\u003eAutomating repetitive tasks to avoid rewriting the same code.\u003c/li\u003e\n\u003c/ol\u003e\n\u003ch2 id=\"ifelse\"\u003eIf…else\u003c/h2\u003e\n\u003cp\u003eThe \u003ccode\u003eif...else\u003c/code\u003e statement allows you to change the normal flow of code execution by evaluating a specific condition.\u003c/p\u003e\n\u003cp\u003eHere is an example\u003c/p\u003e\n\u003cdiv class=\"highlight\"\u003e\u003cpre tabindex=\"0\" style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"\u003e\u003ccode class=\"language-python\" data-lang=\"python\"\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003ex \u003cspan style=\"color:#f92672\"\u003e=\u003c/span\u003e int(input(\u003cspan style=\"color:#e6db74\"\u003e\u0026#34;Insert a number:\u0026#34;\u003c/span\u003e))\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\u003cspan style=\"color:#66d9ef\"\u003eif\u003c/span\u003e x \u003cspan style=\"color:#f92672\"\u003e%\u003c/span\u003e \u003cspan style=\"color:#ae81ff\"\u003e2\u003c/span\u003e \u003cspan style=\"color:#f92672\"\u003e==\u003c/span\u003e \u003cspan style=\"color:#ae81ff\"\u003e0\u003c/span\u003e:\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    print(\u003cspan style=\"color:#e6db74\"\u003e\u0026#34;Your number is even\u0026#34;\u003c/span\u003e)\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\u003cspan style=\"color:#66d9ef\"\u003eelse\u003c/span\u003e:\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    print(\u003cspan style=\"color:#e6db74\"\u003e\u0026#34;Your number is odd\u0026#34;\u003c/span\u003e)\n\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\u003cp\u003eThis code will print a different message depending on whether the value entered by the user is an even or an odd number.\u003c/p\u003e","title":"Control Flow and Loops in Python"},{"content":"In the previous articles… As we introduced in the first article, Spring is an excellent tool for Java application development. We also explored how to set up a basic project and create an initial, simple API.\nIn this article, we’ll connect the project to a database, specifically PostgreSQL, and explore how to persist and manipulate saved data.\nPostgreSQL PostgreSQL, originally known as “post-ingres,” was conceived by Michael Stonebraker in 1985. It serves as a robust alternative to other relational databases like MySQL. The key distinction of PostgreSQL lies in its support for defining custom data types (based on standard SQL types) and data type inheritance.\nFor detailed insights, refer to the official website.\nSpring \u0026amp; PostgreSQL Database Installation First, ensure PostgreSQL is installed. Follow this guide for installation instructions.\nDependencies To begin, add the necessary dependencies to your project:\n\u0026lt;dependency\u0026gt; \u0026lt;groupId\u0026gt;org.postgresql\u0026lt;/groupId\u0026gt; \u0026lt;artifactId\u0026gt;postgresql\u0026lt;/artifactId\u0026gt; \u0026lt;/dependency\u0026gt; \u0026lt;dependency\u0026gt; \u0026lt;groupId\u0026gt;org.springframework.boot\u0026lt;/groupId\u0026gt; \u0026lt;artifactId\u0026gt;spring-boot-starter-data-jpa\u0026lt;/artifactId\u0026gt; \u0026lt;/dependency\u0026gt; With these dependencies, you now have access to all entity manipulation features provided by “spring-boot-starter-data-jpa” and all database communication interfaces provided by “postgresql.” There is no need to specify the version of the PostgreSQL driver: Spring Boot manages it and picks a compatible one.\nFor IntelliJ users, each time you modify the pom.xml file, click the dedicated icon to apply the changes.\nPostgreSQL Configuration With dependencies in place, you need to set the connection parameters your application will use to interface with the database. Open the “application.properties” file and add the following settings:\nspring.datasource.url=jdbc:postgresql://localhost:5432/YOUR_DB_NAME spring.datasource.username=YOUR_USERNAME spring.datasource.password=YOUR_PASSWORD There is no need to specify the driver: Spring Boot detects it automatically from the connection URL.\nBefore creating domain entities, add the following setting to auto-generate the schema for domain entities:\nspring.jpa.hibernate.ddl-auto=update Domain Entities Now, let’s create a domain entity.\nWithin your project, create a new package named domain and add a file called User.java with the following code:\n@Entity @Table(name = \u0026#34;users\u0026#34;) public class User { @Id @GeneratedValue(strategy= GenerationType.IDENTITY) private Long id; private String username; public User() {} public User(String username) { this.username = username; } public void setId(Long id) { this.id = id; } public Long getId() { return id; } public void setUsername(String username) { this.username = username; } public String getUsername() { return username; } } Here are some of the annotations we used:\n@Entity: Marks this class as a domain entity. @Table(name = \u0026quot;users\u0026quot;): Sets the name of the database table. By default it is derived from the class name, but we customized it here since “User” is a keyword in Postgres. @Id: Indicates the primary key field. @GeneratedValue(strategy=GenerationType.IDENTITY): Specifies that the database should auto-generate the ID field, with Postgres creating a unique sequential identifier of type long. Repository Repositories are interfaces providing methods for managing (creating, reading, updating, etc.) database records.\nIn our case, implementations of these interfaces are provided by the “spring-boot-starter-data-jpa” dependency.\nCreate a package named repository and add the file UserRepository.java with the following content:\n@Repository public interface UserRepository extends JpaRepository\u0026lt;User, Long\u0026gt; {} We’ll leave the interface as is for now, as we’re only using basic CRUD operations. We’ll explore custom functionalities for this interface later.\nDTO To create or update a user, the client will send data in the request body as JSON, for example {\u0026quot;username\u0026quot;: \u0026quot;user1\u0026quot;}. To let Spring automatically convert that JSON into a Java object, we define a class describing its structure: a DTO (Data Transfer Object).\nCreate a package named dto and add the file UserRequest.java:\npublic class UserRequest { private String username; public UserRequest() {} public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } } The attribute name must match the field name in the JSON. Without a DTO, declaring the parameter simply as a String, Spring would hand us the entire body as is, braces and quotes included.\nController Now it’s time to create the controller for managing users. In the main package, create a new file UserController.java and add the following code:\n@RestController @RequestMapping(\u0026#34;/user\u0026#34;) public class UserController { private final UserRepository userRepository; public UserController(UserRepository userRepository) { this.userRepository = userRepository; } } This code creates a new API path under “/user.” Next, define the CRUD methods for the User entity by adding the following:\n@PostMapping(value = \u0026#34;/register\u0026#34;) public ResponseEntity\u0026lt;User\u0026gt; register(@RequestBody UserRequest request) { User newUser = new User(request.getUsername()); userRepository.save(newUser); return ResponseEntity.ok(newUser); } @GetMapping(value = \u0026#34;\u0026#34;) public ResponseEntity\u0026lt;List\u0026lt;User\u0026gt;\u0026gt; getAll() { List\u0026lt;User\u0026gt; users = userRepository.findAll(); return ResponseEntity.ok(users); } @GetMapping(value = \u0026#34;/{userId}\u0026#34;) public ResponseEntity\u0026lt;User\u0026gt; getById(@PathVariable Long userId) { User user = userRepository.findById(userId).orElse(null); if (user == null) { return ResponseEntity.notFound().build(); } return ResponseEntity.ok(user); } @PutMapping(value = \u0026#34;/{userId}\u0026#34;) public ResponseEntity\u0026lt;User\u0026gt; updateById(@PathVariable Long userId, @RequestBody UserRequest request) { User user = userRepository.findById(userId).orElse(null); if (user == null) { return ResponseEntity.notFound().build(); } user.setUsername(request.getUsername()); user = userRepository.save(user); return ResponseEntity.ok(user); } @DeleteMapping(value = \u0026#34;/{userId}\u0026#34;) public ResponseEntity\u0026lt;User\u0026gt; deleteById(@PathVariable Long userId) { User user = userRepository.findById(userId).orElse(null); if (user == null) { return ResponseEntity.notFound().build(); } userRepository.delete(user); return ResponseEntity.ok().build(); } In this example, we introduced a new annotation and a new way to write the API URL. Consider the Get API example:\n@GetMapping(value = \u0026#34;/{userId}\u0026#34;) public ResponseEntity\u0026lt;User\u0026gt; getById(@PathVariable Long userId) { User user = userRepository.findById(userId).orElse(null); if (user == null) { return ResponseEntity.notFound().build(); } return ResponseEntity.ok(user); } This API’s URL will look like “localhost:8080/user/1” since “/{userId}” tells Spring that the URL will contain a variable component. The @PathVariable annotation maps this variable to the userId parameter. In the register and update methods, the @RequestBody annotation applied to a UserRequest parameter tells Spring to convert the received JSON into our DTO.\nTesting To test the API, use Postman or an equivalent app.\nGet user list: Method: GET URL: localhost:8080/user Response: [] Create new user: Method: POST URL: localhost:8080/user/register Body: {\u0026quot;username\u0026quot;: \u0026quot;user1\u0026quot;} Response: { \u0026#34;id\u0026#34;: 1, \u0026#34;username\u0026#34;: \u0026#34;user1\u0026#34; } Get user by ID: Method: GET URL: localhost:8080/user/1 Update user: Method: PUT URL: localhost:8080/user/1 Body: {\u0026quot;username\u0026quot;: \u0026quot;user2\u0026quot;} Delete user: Method: DELETE URL: localhost:8080/user/1 Conclusion In this second part, we connected to a database and learned how to persist and manipulate data. In the third and final part, we’ll implement authentication with JWT Token and Spring Security.\nThe complete code for this example is available at this link.\n","permalink":"https://antoniomontemurro.com/en/posts/spring-framework-part2/","summary":"\u003ch2 id=\"in-the-previous-articles\"\u003eIn the previous articles…\u003c/h2\u003e\n\u003cp\u003eAs we introduced in the \u003ca href=\"/en/posts/spring-framework-part1/\"\u003efirst article\u003c/a\u003e, Spring is an excellent tool for Java application development. We also explored how to set up a basic project and create an initial, simple API.\u003c/p\u003e\n\u003cp\u003eIn this article, we’ll connect the project to a database, specifically PostgreSQL, and explore how to persist and manipulate saved data.\u003c/p\u003e\n\u003ch2 id=\"postgresql\"\u003ePostgreSQL\u003c/h2\u003e\n\u003cp\u003ePostgreSQL, originally known as “post-ingres,” was conceived by Michael Stonebraker in 1985. It serves as a robust alternative to other relational databases like MySQL. The key distinction of PostgreSQL lies in its support for defining custom data types (based on standard SQL types) and data type inheritance.\u003cbr\u003e\nFor detailed insights, refer to the \u003ca href=\"https://www.postgresql.org/about/\"\u003eofficial website\u003c/a\u003e.\u003c/p\u003e","title":"Spring Framework – Part 2"},{"content":"In Python, as in every programming language, there are various operators for manipulating numbers, logical values, and comparing objects.\nArithmetic Operators The most familiar ones are the mathematical operators.\nSum: + Subtraction: - Multiplication: * Division: / or // Exponentiation: ** Modulus: % Let’s see an example for each operator:\nprint(10 + 3) # Addition: 13 print(10 - 3) # Subtraction: 7 print(10 * 3) # Multiplication: 30 print(10 / 3) # Division: 3.3333... print(10 // 3) # Floor Division: 3 print(10 ** 3) # Exponentiation: 1000 print(10 % 3) # Modulus: 1 Of these, the one worth a quick note is the // operator, also known as “Floor Division.” This operator simply rounds down the division result to the nearest integer.\nComparison Operators These operators help determine the relationship between two objects.\nEqual to: == Not equal to: != Less than: \u0026lt; Greater than: \u0026gt; Less than or equal to: \u0026lt;= Greater than or equal to: \u0026gt;= The result of each of these operators is a boolean (True or False), indicating if the condition is met.\nExample for each operator:\nprint(10 == 3) # Equal to: False print(10 != 3) # Not equal to: True print(10 \u0026lt; 3) # Less than: False print(10 \u0026gt; 3) # Greater than: True print(10 \u0026lt;= 3) # Less than or equal to: False print(10 \u0026gt;= 3) # Greater than or equal to: True Logical Operators These operators will be very useful in upcoming tutorials. For now, know that they are used in boolean operations.\nLogical AND: and Logical OR: or Logical NOT: not Example for each operator:\nprint(True and False) # Logical AND: False print(True or False) # Logical OR: True print(not True) # Logical NOT: False Conclusion In upcoming tutorials, we’ll delve deeper into using these operators, especially the logical ones. We’ll also see how both arithmetic and comparison operators can be applied to more than just numbers.\nAs always, find the sample code link here.\n","permalink":"https://antoniomontemurro.com/en/posts/operators-python-arithmetic-comparison-logical/","summary":"\u003cp\u003eIn Python, as in every programming language, there are various operators for manipulating numbers, logical values, and comparing objects.\u003c/p\u003e\n\u003ch2 id=\"arithmetic-operators\"\u003eArithmetic Operators\u003c/h2\u003e\n\u003cp\u003eThe most familiar ones are the mathematical operators.\u003c/p\u003e\n\u003cdiv class=\"highlight\"\u003e\u003cpre tabindex=\"0\" style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"\u003e\u003ccode class=\"language-text\" data-lang=\"text\"\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003eSum: +\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003eSubtraction: -\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003eMultiplication: *\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003eDivision: / or //\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003eExponentiation: **\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003eModulus: %\n\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\u003cp\u003eLet’s see an example for each operator:\u003c/p\u003e\n\u003cdiv class=\"highlight\"\u003e\u003cpre tabindex=\"0\" style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"\u003e\u003ccode class=\"language-python\" data-lang=\"python\"\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003eprint(\u003cspan style=\"color:#ae81ff\"\u003e10\u003c/span\u003e \u003cspan style=\"color:#f92672\"\u003e+\u003c/span\u003e \u003cspan style=\"color:#ae81ff\"\u003e3\u003c/span\u003e)    \u003cspan style=\"color:#75715e\"\u003e# Addition: 13\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003eprint(\u003cspan style=\"color:#ae81ff\"\u003e10\u003c/span\u003e \u003cspan style=\"color:#f92672\"\u003e-\u003c/span\u003e \u003cspan style=\"color:#ae81ff\"\u003e3\u003c/span\u003e)    \u003cspan style=\"color:#75715e\"\u003e# Subtraction: 7\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003eprint(\u003cspan style=\"color:#ae81ff\"\u003e10\u003c/span\u003e \u003cspan style=\"color:#f92672\"\u003e*\u003c/span\u003e \u003cspan style=\"color:#ae81ff\"\u003e3\u003c/span\u003e)    \u003cspan style=\"color:#75715e\"\u003e# Multiplication: 30\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003eprint(\u003cspan style=\"color:#ae81ff\"\u003e10\u003c/span\u003e \u003cspan style=\"color:#f92672\"\u003e/\u003c/span\u003e \u003cspan style=\"color:#ae81ff\"\u003e3\u003c/span\u003e)    \u003cspan style=\"color:#75715e\"\u003e# Division: 3.3333...\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003eprint(\u003cspan style=\"color:#ae81ff\"\u003e10\u003c/span\u003e \u003cspan style=\"color:#f92672\"\u003e//\u003c/span\u003e \u003cspan style=\"color:#ae81ff\"\u003e3\u003c/span\u003e)   \u003cspan style=\"color:#75715e\"\u003e# Floor Division: 3\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003eprint(\u003cspan style=\"color:#ae81ff\"\u003e10\u003c/span\u003e \u003cspan style=\"color:#f92672\"\u003e**\u003c/span\u003e \u003cspan style=\"color:#ae81ff\"\u003e3\u003c/span\u003e)   \u003cspan style=\"color:#75715e\"\u003e# Exponentiation: 1000\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003eprint(\u003cspan style=\"color:#ae81ff\"\u003e10\u003c/span\u003e \u003cspan style=\"color:#f92672\"\u003e%\u003c/span\u003e \u003cspan style=\"color:#ae81ff\"\u003e3\u003c/span\u003e)    \u003cspan style=\"color:#75715e\"\u003e# Modulus: 1\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\u003cp\u003eOf these, the one worth a quick note is the \u003ccode\u003e//\u003c/code\u003e operator, also known as “Floor Division.” This operator simply rounds down the division result to the nearest integer.\u003c/p\u003e","title":"Operators in Python: Arithmetic, Comparison, and Logical"},{"content":"Have you ever noticed that some websites have a private section that requires a username and password to access? You might also have noticed that, once logged in, you’re often not asked to re-enter your username and password for subsequent visits. In stateless web applications, this behavior is achievable by using a JWT token. JWT, which stands for JSON Web Token, is a data exchange standard defined by RFC7519 in 2015.\nIn simple terms, a JWT token allows a user to communicate their identity to a REST application without needing to enter a username and password each time.\nStructure of the Token A JWT token consists of three main components:\nHeader: Contains information about the type of token and the signing algorithm used. Payload: Contains all the information exchanged between the user and the application. Signature: The signature of the previous two sections, computed using a secret key. It lets the server verify that the token has not been altered. JWT Token: An Example To see what a JWT looks like, you can visit jwt.io. Here’s an example of a token structure:\nHeader { \u0026#34;alg\u0026#34;: \u0026#34;HS256\u0026#34;, \u0026#34;typ\u0026#34;: \u0026#34;JWT\u0026#34; } Payload { \u0026#34;sub\u0026#34;: \u0026#34;1234567890\u0026#34;, \u0026#34;name\u0026#34;: \u0026#34;John Doe\u0026#34;, \u0026#34;iat\u0026#34;: 1516239022 } Signature HMACSHA256( base64UrlEncode(header) + \u0026#34;.\u0026#34; + base64UrlEncode(payload), your-256-bit-secret ) The result is:\neyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c You can distinguish the three components, as they’re separated by a “.”\nCustomizing the JWT Token JWT tokens can be customized using Claims. Claims are a map of values representing information useful for the application. These are placed within the Payload and contribute to the token’s overall size.\nHere’s an example of a customized Payload:\n{ \u0026#34;sub\u0026#34;: \u0026#34;johndoe@test.com\u0026#34;, \u0026#34;firstName\u0026#34;: \u0026#34;John\u0026#34;, \u0026#34;lastName\u0026#34;: \u0026#34;Doe\u0026#34;, \u0026#34;iat\u0026#34;: 1728830222, \u0026#34;exp\u0026#34;: 1728866222 } The resulting token will look like:\neyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJqb2huZG9lQHRlc3QuY29tIiwiZmlyc3ROYW1lIjoiSm9obiIsImxhc3ROYW1lIjoiRG9lIiwiaWF0IjoxNzI4ODMwMjIyLCJleHAiOjE3Mjg4NjYyMjJ9.OYqR8KbYa0n6-Zrx1SQKXZAeX4a2iO6xZKrkC2_wLwQ What Not to Do! Now that we understand what a JWT token is and how it can be customized, let’s look at a common security mistake. Imagine you have APIs protected by JWT, accessible only to users with a specific role. Here’s an example of a JWT Payload for an admin user:\n{ \u0026#34;sub\u0026#34;: \u0026#34;johndoe@test.com\u0026#34;, \u0026#34;firstName\u0026#34;: \u0026#34;John\u0026#34;, \u0026#34;lastName\u0026#34;: \u0026#34;Doe\u0026#34;, \u0026#34;role\u0026#34;: \u0026#34;ADMIN\u0026#34;, \u0026#34;iat\u0026#34;: 1728830222, \u0026#34;exp\u0026#34;: 1728866222 } With this token, our application identifies “John Doe” and grants access to admin-only APIs.\nThe token is signed, so nobody can change its content without the server noticing: if John Doe had the role “USER” and manually changed it to “ADMIN”, the signature would no longer match and the token would be rejected (as long as the server actually verifies it).\nThe real mistake is a different one: treating the content of the token as always current. The signature guarantees that the data has not been altered, not that it is still true. If John Doe’s ADMIN role is revoked, the token issued earlier keeps declaring him an administrator until it expires.\nFor this reason, it is a good idea to:\nUse short expiration times, so that outdated data is short-lived. For the most sensitive operations, check the user’s role and status against your app’s database instead of relying on the token alone. Never put confidential information in the Payload: it is encoded, not encrypted, and anyone can read it. Conclusion JWT tokens are a popular standard for authorizations in web applications. For further details, refer to this link. Have you used JWT tokens in your applications? Let us know in the comments!\n","permalink":"https://antoniomontemurro.com/en/posts/jwt-authentication/","summary":"\u003cp\u003eHave you ever noticed that some websites have a private section that requires a username and password to access? You might also have noticed that, once logged in, you’re often not asked to re-enter your username and password for subsequent visits. In stateless web applications, this behavior is achievable by using a JWT token. JWT, which stands for JSON Web Token, is a data exchange standard defined by RFC7519 in 2015.\u003c/p\u003e","title":"JWT Authentication"},{"content":"What is a Framework A Framework, in simple terms, is a set of predefined classes, libraries, and tools that provide a basic structure for software development. The use of a framework allows developers to avoid implementing basic features from scratch, enabling them to focus on developing specific, customized functionalities for their projects.\nSpring Spring is an open-source framework for Java application development. The first version of the framework was released in 2003 by Rod Johnson, and it has been enhanced over the years with a series of extensions. Over time, Spring has earned a leading role in Java application development, thanks to its highly active community and the vast availability of documentation and practical examples.\nIn this article, we’ll see how to create a basic application for API development using Spring. The example will be built in Java, and we’ll use SQL as the database.\nWeb Apps with Spring As mentioned, the base Spring framework has been enriched over time with numerous features, effectively creating a family of frameworks. By utilizing one or more of these resources, it is possible to create a web service in Java that implements REST APIs, which can be used for a website or any other application (e.g., an Android/iOS app).\nWeb Service A web service is a software application capable of communicating via the HTTP protocol with any application, offering specifically implemented functionalities. An example might be a weather forecasting website: behind the graphical interface displaying the map of the area of interest, a web service processes the user’s request (such as selecting a location) and provides a weather forecast based on available data.\nREST API When talking about RESTful APIs, we’re not referring to protocols or standards, but to a series of universally accepted rules.\nThe main characteristics that an API must have to be considered RESTful are:\nThere must be two actors, Client and Server, and resources to share. Communication between Client and Server must be stateless. Caching tools can be used to enhance the speed of interactions between Client and Server. An interface should be provided to standardize the transferred information. Sample Application Now, we’ll create a sample application based on Spring, using the Java language. Later, we’ll add the ability to save data in an SQL database and finally implement a user authentication mechanism.\nStart by visiting this link to generate a project with basic configurations for Java and Maven (or Gradle).\nAlthough dependencies can be automatically configured, I prefer to add them manually, as we’ll see shortly. Once all options are set, click on Generate to download a zip file containing everything you need to get started.\nMake sure you have everything properly installed in your development environment. By opening the downloaded project in your preferred IDE, you can start the application, which, at this point, won’t do anything yet.\nDependencies Now let’s look at the minimum dependencies required to create our web service. The best place to search for dependencies is mvnrepository.com.\nOpen the pom.xml file and define the necessary dependencies. The first and probably most important one is:\n\u0026lt;dependency\u0026gt; \u0026lt;groupId\u0026gt;org.springframework.boot\u0026lt;/groupId\u0026gt; \u0026lt;artifactId\u0026gt;spring-boot-starter-web\u0026lt;/artifactId\u0026gt; \u0026lt;/dependency\u0026gt; This dependency should be added within the \u0026lt;dependencies\u0026gt;\u0026lt;/dependencies\u0026gt; tags.\nIf you are using IntelliJ, every time you modify the pom.xml file, you’ll need to click the appropriate icon to apply the changes:\nBy restarting the application, you’ll see log entries similar to these:\nTomcat started on port 8080 (http) with context path ‘/’ Started DemoApplication in X seconds (process running for Y) These logs indicate that the application has started correctly and is listening on the default port 8080.\nCreating the First API Now we’re ready to create our first API. In the folder where the main class is located, create a new file called DemoController. Inside this file, add the following code:\n@RestController public class DemoController { @GetMapping public void demo() { System.out.println(\u0026#34;Hello World\u0026#34;); } } Restart the application and open the browser at http://localhost:8080. You’ll see “Hello World” printed in the console.\nAdding an Endpoint to Respond to Clients Since we’re creating APIs to be used with other applications, we want to send a response to a client. Let’s add a new endpoint:\n@GetMapping(value = \u0026#34;/test\u0026#34;) public ResponseEntity\u0026lt;String\u0026gt; test() { return ResponseEntity.ok(\u0026#34;Hello World\u0026#34;); } Visiting http://localhost:8080/test in the browser, you’ll see the response “Hello World.”\nResponseEntity The ResponseEntity class is Spring’s default class for representing an HTTP response. With ResponseEntity, the response includes a Status Code, Headers, and a Body.\nReceiving Data with APIs An API doesn’t always serve to provide data; it can also receive it. Let’s add an endpoint that accepts a parameter from the request:\n@GetMapping(value = \u0026#34;/test1\u0026#34;) public ResponseEntity\u0026lt;String\u0026gt; test1(@RequestParam(\u0026#34;name\u0026#34;) String name) { String message = \u0026#34;Hello\u0026#34; + \u0026#34; \u0026#34; + name + \u0026#34;!\u0026#34;; return ResponseEntity.ok(message); } Now, if you open http://localhost:8080/test1?name=John in the browser, you’ll see “Hello John!”.\nFor more complex data, it’s necessary to use the request body. Let’s add a new endpoint:\n@PostMapping(value = \u0026#34;/test2\u0026#34;) public ResponseEntity\u0026lt;String\u0026gt; test2(@RequestBody String name) { String message = \u0026#34;Hello\u0026#34; + \u0026#34; \u0026#34; + name + \u0026#34;!\u0026#34;; return ResponseEntity.ok(message); } To test this API, use the terminal:\ncurl --request POST --header \u0026#34;Content-Type: text/plain\u0026#34; --data John http://localhost:8080/test2 You’ll receive the response “Hello John!”.\nIn this example the body is plain text: by declaring the parameter as a String, Spring hands it to us as is. In the second part, we’ll see how to receive structured data in JSON format.\nConclusion In this first part, we’ve seen how to initialize a Spring project for creating a web service. In the second part, we will see how to interface Spring with a database so that we can persist data.\nThe complete code for this example is available at this link.\n","permalink":"https://antoniomontemurro.com/en/posts/spring-framework-part1/","summary":"\u003ch2 id=\"what-is-a-framework\"\u003eWhat is a Framework\u003c/h2\u003e\n\u003cp\u003eA Framework, in simple terms, is a set of predefined classes, libraries, and tools that provide a basic structure for software development. The use of a framework allows developers to avoid implementing basic features from scratch, enabling them to focus on developing specific, customized functionalities for their projects.\u003c/p\u003e\n\u003ch2 id=\"spring\"\u003eSpring\u003c/h2\u003e\n\u003cp\u003e\u003ca href=\"https://spring.io/\"\u003eSpring\u003c/a\u003e is an open-source framework for Java application development. The first version of the framework was released in 2003 by Rod Johnson, and it has been enhanced over the years with a series of \u003ca href=\"https://spring.io/projects/spring-framework\"\u003eextensions\u003c/a\u003e. Over time, Spring has earned a leading role in Java application development, thanks to its highly active community and the vast availability of documentation and practical examples.\u003c/p\u003e","title":"Spring Framework – Part 1"},{"content":"As mentioned in this article, Python is a dynamically-typed language, meaning that types are not declared in the code but determined during program execution, based on the assigned value. However, this does not mean that types do not exist: every value has a well-defined type.\nLet’s take a look at the data types natively present in Python:\nStrings: str Numbers: int, float, complex Sequences: list, tuple Mappings: dict Sets: set, frozenset Boolean: bool Binary: bytes, bytearray, memoryview In Python, it is not necessary to specify the type of a variable when declaring it. This allows a variable to hold any of the types listed above. Moreover, the same variable can be assigned a value of a different type at any time: what changes is not the type of the value, which always stays the same, but the value the variable refers to.\nx = 1 # x refers to an int x = \u0026#34;one\u0026#34; # now x refers to a str For more details on Python data types, we encourage you to check the official documentation.\nSetting the Data Type Here are some examples of how to assign different data types to a variable:\nString: x = \u0026quot;Hello World\u0026quot; Number: Int: x = 1 Float: x = 1.0 Complex: x = 1j Sequences: List: x = [\u0026quot;Monday\u0026quot;, \u0026quot;Tuesday\u0026quot;, ...] Tuple: x = (\u0026quot;Monday\u0026quot;, \u0026quot;Tuesday\u0026quot;, ...) Mappings: x = {\u0026quot;key\u0026quot;: \u0026quot;value\u0026quot;, \u0026quot;key\u0026quot;: \u0026quot;value\u0026quot;, ...} Sets: Set: x = {\u0026quot;Monday\u0026quot;, \u0026quot;Tuesday\u0026quot;, ...} FrozenSet: x = frozenset({\u0026quot;Monday\u0026quot;, \u0026quot;Tuesday\u0026quot;, ...}) Boolean: x = True or x = False Binary: x = b\u0026quot;Hello World\u0026quot; Sequences Vs. Sets Since sequences and sets might seem similar at first glance, let’s outline the main differences between these two data types:\nList: Lists can hold heterogeneous data, allow duplicates, and are mutable. A list can be initialized with x = list() or x = []. Tuple: Tuples can hold heterogeneous data, allow duplicates, and are immutable. A tuple can be initialized with x = tuple() or x = (). Set: Sets can hold heterogeneous data, do not allow duplicates, and are mutable. A set can be initialized with x = set(). There is also an immutable version that can be initialized with x = frozenset(). Mappings: A mapping can hold heterogeneous data, does not allow duplicate keys, and is mutable. A mapping can be initialized with x = dict() or x = {}. Conclusion We’ve covered an overview of the main data types in Python. In the upcoming articles, we will explore practical applications to help you better understand their use and nuances. Stay tuned to continue enhancing your Python skills!\n","permalink":"https://antoniomontemurro.com/en/posts/data-types/","summary":"\u003cp\u003eAs mentioned in \u003ca href=\"/en/posts/python-basic-syntax/\"\u003ethis article\u003c/a\u003e, Python is a dynamically-typed language, meaning that types are not declared in the code but determined during program execution, based on the assigned value. However, this does not mean that types do not exist: every value has a well-defined type.\u003c/p\u003e\n\u003cp\u003eLet’s take a look at the data types natively present in Python:\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003e\u003cstrong\u003eStrings\u003c/strong\u003e: \u003ccode\u003estr\u003c/code\u003e\u003c/li\u003e\n\u003cli\u003e\u003cstrong\u003eNumbers\u003c/strong\u003e: \u003ccode\u003eint\u003c/code\u003e, \u003ccode\u003efloat\u003c/code\u003e, \u003ccode\u003ecomplex\u003c/code\u003e\u003c/li\u003e\n\u003cli\u003e\u003cstrong\u003eSequences\u003c/strong\u003e: \u003ccode\u003elist\u003c/code\u003e, \u003ccode\u003etuple\u003c/code\u003e\u003c/li\u003e\n\u003cli\u003e\u003cstrong\u003eMappings\u003c/strong\u003e: \u003ccode\u003edict\u003c/code\u003e\u003c/li\u003e\n\u003cli\u003e\u003cstrong\u003eSets\u003c/strong\u003e: \u003ccode\u003eset\u003c/code\u003e, \u003ccode\u003efrozenset\u003c/code\u003e\u003c/li\u003e\n\u003cli\u003e\u003cstrong\u003eBoolean\u003c/strong\u003e: \u003ccode\u003ebool\u003c/code\u003e\u003c/li\u003e\n\u003cli\u003e\u003cstrong\u003eBinary\u003c/strong\u003e: \u003ccode\u003ebytes\u003c/code\u003e, \u003ccode\u003ebytearray\u003c/code\u003e, \u003ccode\u003ememoryview\u003c/code\u003e\u003c/li\u003e\n\u003c/ul\u003e\n\u003cp\u003eIn Python, it is not necessary to specify the type of a variable when declaring it. This allows a variable to hold any of the types listed above. Moreover, the same variable can be assigned a value of a different type at any time: what changes is not the type of the value, which always stays the same, but the value the variable refers to.\u003c/p\u003e","title":"Python – Data Types"},{"content":"What is Groovy Apache Groovy is a programming language that positions itself as an alternative to Java, from which it inherits many features.\nGroovy is both a static and dynamic language, meaning it can be used as a traditional programming language (like Java) or as a scripting language (similar to Python).\nAs mentioned, Groovy is inspired by Java: it adopts its syntax and compiles its code into bytecode to be executed by the Java Virtual Machine (JVM).\nTo put it simply, Groovy could be described as a “simplified Java.” However, let’s take a closer look at its features in comparison to Java.\nGroovy Vs Java As already stated, Groovy openly takes inspiration from Java (as noted on the official website’s homepage), but it simplifies some aspects, making the language easier to learn and improving developer efficiency.\nLet’s now review the main syntax differences, with more advanced examples to be covered in later sections:\nDefault Access: In Groovy, the default access level for methods and attributes is public, whereas in Java, it is private. Getters and Setters: Unlike Java, there is no need to explicitly define accessor methods for attributes, as they are automatically generated by the language. String Interpolation: Groovy allows variables to be inserted directly into strings, something not possible in Java. Typing: Groovy allows for optional typing, with the type of each variable inferred at runtime. In Java, it is mandatory to specify the type of every variable. // In Groovy def name = \u0026#34;John Doe\u0026#34; // In Java String name = \u0026#34;John Doe\u0026#34; Semicolons: It is not necessary to use a semicolon (;) to indicate the end of a statement. Program Execution: Unlike Java, Groovy does not require the definition of a main class for the program to run, as every class is automatically wrapped in a class called Script. // Java public class Main { public static void main(String[] args) { System.out.println(\u0026#34;Ciao, mondo!\u0026#34;); } } // In Groovy println \u0026#34;Ciao, mondo!\u0026#34; Internally, Groovy translates the above script into:\n// Traduzione Groovy class ScriptName extends groovy.lang.Script { @Override Object run() { println \u0026#34;Ciao, mondo!\u0026#34; } } Performance Groovy is generally less performant than Java, though it has significantly improved in this area over the years. The main difference stems from the “convenience” Groovy offers, which simplifies the developer’s job but introduces some overhead.\nSome factors contributing to Groovy’s lower performance compared to Java include:\nDynamic Typing: The type of variables is determined at runtime. Dynamic Compilation: Although Groovy can be statically compiled (like Java), some features can only be interpreted at runtime, adding overhead. String Interpolation: The final content of a string can only be determined at runtime. Syntax: Features such as the lack of explicit getters and setters introduce additional overhead. Program Startup: Starting the application takes more time because Groovy needs to manage various dynamic language features, such as string interpolation and dynamic typing. Examples For a complete example, a simplified program is available at this link, highlighting some of the key differences, both basic and advanced, between the two languages.\nConclusion In conclusion, Groovy can be considered an excellent tool to improve developer efficiency, provided that code performance is not the primary concern. With Groovy, it is possible to write high-quality code in less time than with Java, at the cost of slightly lower performance.\nOn the other hand, if performance is critical, Java should be the preferred choice.\n","permalink":"https://antoniomontemurro.com/en/posts/groovy/","summary":"\u003ch2 id=\"what-is-groovy\"\u003eWhat is Groovy\u003c/h2\u003e\n\u003cp\u003eApache Groovy is a programming language that positions itself as an alternative to Java, from which it inherits many features.\u003cbr\u003e\nGroovy is both a static and dynamic language, meaning it can be used as a traditional programming language (like Java) or as a scripting language (similar to Python).\u003c/p\u003e\n\u003cp\u003eAs mentioned, Groovy is inspired by Java: it adopts its syntax and compiles its code into bytecode to be executed by the Java Virtual Machine (JVM).\u003cbr\u003e\nTo put it simply, Groovy could be described as a “simplified Java.” However, let’s take a closer look at its features in comparison to Java.\u003c/p\u003e","title":"Groovy"},{"content":"In any activity that involves creating something, there is always the possibility of wanting to make changes to your work, only to realize that you’ve made a mistake and can’t go back. And this is precisely where version control systems come to the rescue!\nVersion Control System One of the first challenges faced during professional growth in the field of computing is managing code and its changes.\nImagine writing a function, and after hours of work, you decide to modify some parts, only to realize that the new changes not only don’t work but weren’t even necessary. Moreover, the classic CTRL+Z might not be enough to go back far enough.\nIt’s in situations like this that using a version control tool becomes essential.\nA version control system is software that allows you to manage the source code. With a version control system, you can:\nHave multiple versions of the same source code Switch between versions Track the history of changes and restore the code to a certain point in the past Among the various version control systems, probably the most famous and widely used is GIT.\nCreated by Linus Torvalds in 2005, GIT has become one of the essential tools for every developer, right after the IDE.\nInstalling GIT To install GIT, simply visit this link and download the version suitable for your operating system.\nMain GIT Commands Although GIT is integrated into almost all major IDEs, which provide convenient graphical interfaces for version control management, GIT was originally designed to be used via the command-line interface.\nBelow are some useful commands for daily usage via the command line:\nConfigure your name: git config --global user.name \u0026quot;NAME\u0026quot; View the configured name: git config --global user.name Configure your email: git config --global user.email \u0026quot;EMAIL\u0026quot; View the configured email: git config --global user.email Initialize GIT in the current directory: git init View the repository status: git status If there are already files in the current directory, the command will display a result similar to this:\nAt this point, you can add one or more files to the repository:\nAdd a specific file: git add FILE1.EXT FILE2.EXT ... Add all files in the current directory: git add . COMMIT After adding the files to GIT, it’s time to make a commit, which means recording the changes in the repository:\nCommit: git commit -m \u0026quot;COMMENT\u0026quot; View the most recent commit: git log View the commit in a single line: git log --oneline At this point, you may realize you forgot to add a file. To fix this, simply add the file and run the following command to amend the previous commit:\nAmend commit: git commit --amend -a -m \u0026quot;COMMENT\u0026quot; BRANCH Suppose you want to implement a variant of the code, which develops in parallel to the main version. In these cases, branches are used.\nCreate a new branch: git branch \u0026quot;BRANCH_NAME_WITHOUT_SPACES\u0026quot; View existing branches: git branch As mentioned earlier, it is possible to switch between branches. This process is called “switch,” and it can be done by switching to an existing branch or creating a new branch during the switch:\nSwitch branches: git switch \u0026quot;BRANCH_NAME\u0026quot; Create a new branch and switch: git switch -c \u0026quot;BRANCH_NAME\u0026quot; Rename the current branch: git branch -m \u0026quot;NEW_NAME\u0026quot; Delete a branch: git branch -d \u0026quot;NAME\u0026quot; Merge a branch into the current branch: git merge \u0026quot;BRANCH_NAME\u0026quot; In previous versions of GIT, the command checkout was used instead of switch, and the option -b instead of -c.\nSTASH Now, suppose you have some changes in progress, but you need to work on another branch. Since it’s good practice not to commit incomplete and untested code, you can save your work in the stash and retrieve it later.\nSave current work: git stash Restore from stash: git stash pop List stash entries: git stash list Restore a specific stash entry: git stash apply stash@{ID} Remove a stash entry: git stash drop stash@{ID} Clear all stash entries: git stash clear RESTORE Another important feature is the ability to restore a file to a specific state, provided the changes have not yet been committed:\nRestore a file to its state in the last commit: git restore FILE-NAME.EXT Restore a file to its state at a specific commit: git restore --source BRANCH_CODE FILE_NAME.EXT If you want to remove a file from staging, you can use:\ngit restore --staged FILE_NAME.EXT RESET \u0026amp; REVERT If you want to remove a commit and all associated work, there are two options:\nRemove the commit while keeping the local files: git reset BRANCH_CODE Remove the commit and the local files: git reset --hard BRANCH_CODE Undo committed work by creating a new commit: git revert BRANCH_CODE REBASE It is possible to manipulate the commit history to hide, rename, merge, or delete one or more commits. These operations are delicate and should only be performed in exceptional cases:\nBasic command that opens an editor displaying recent commits: git rebase -i HEAD~x (x is the number of commits to display) If no changes are needed (default behavior): pick COMMIT_CODE ORIGINAL_MESSAGE To edit a commit message: reword COMMIT_CODE NEW_MESSAGE To edit a commit: edit COMMIT_CODE NEW_MESSAGE; at this point, proceed with the following commands before continuing with the rebase: git add FILE.EXT FILE.EXT .. git commit --amend git rebase --continue Merge a commit with the previous one (the final message will be that of the previous commit): fixup COMMIT_CODE Delete a commit: drop COMMIT_CODE Suppose you have the following commits to edit:\nabcd – Added JWT authentication efgh – Added refresh token JWT ilmn – Added README.md file If you realize that the third commit was unnecessary and there’s a typo in the second commit message, the steps are:\nOpen the commit editor: git rebase -i HEAD~3 pick abcd Added JWT authentication pick efgh Added refresh token JWT pick ilmn Added README.md file Modify the situation as follows: pick abcd Added JWT authentication reword efgh Added refresh token JWT drop ilmn Added README.md file At this point, after saving the file, Git will ask you to enter a new message for the modified commit. Once you do that, the rebase will be complete.\nTAG A tag is additional information associated with a commit and is generally used to identify a particularly important version, such as a milestone or a version released to production. There are two types of tags: lightweight tags and annotated tags.\nLightweight tag: git tag v1.0.0 Annotated tag: git tag -a v1.0.0 -m \u0026quot;TAG MESSAGE\u0026quot; As with anything, you can list existing tags or delete one or more:\nList tags: git tag Delete a tag: git tag -d v1.0.0 Tags can be pushed to the repository either individually or all at once:\nPush a single tag: git push origin v1.0.0 Push all available tags: git push origin --tags Conclusions What we’ve seen here is just a small part of the available commands and options for Git. If you want to delve deeper into the topic, I recommend visiting the official site and consulting the documentation, which you can find here.\n","permalink":"https://antoniomontemurro.com/en/posts/version-control/","summary":"\u003cp\u003eIn any activity that involves creating something, there is always the possibility of wanting to make changes to your work, only to realize that you’ve made a mistake and can’t go back. And this is precisely where version control systems come to the rescue!\u003c/p\u003e\n\u003ch2 id=\"version-control-system\"\u003eVersion Control System\u003c/h2\u003e\n\u003cp\u003eOne of the first challenges faced during professional growth in the field of computing is managing code and its changes.\u003c/p\u003e\n\u003cp\u003eImagine writing a function, and after hours of work, you decide to modify some parts, only to realize that the new changes not only don’t work but weren’t even necessary. Moreover, the classic CTRL+Z might not be enough to go back far enough.\u003c/p\u003e","title":"Version Control"},{"content":"Indentation In Python, code blocks are identified through the use of indentation. Indentation involves leaving a specific number of spaces before starting to write code. As the number of spaces changes, so does the block to which the code belongs.\nPython doesn’t enforce a fixed number of spaces, but it does require consistency in your choice: once you decide on a certain number of spaces for indentation, you must maintain that throughout the file.\nTypically, either a single tab (TAB key) or 4 consecutive spaces are used, with the latter generally recommended by the community.\nComments As with any programming language, Python allows you to use comments.\nComments are very useful for adding information to the code, making it more understandable to other developers (or even to your future self). A comment is essentially code that is not executed during the program’s runtime.\nSingle-line comments are introduced with the character #, followed by a space. For multi-line comments, three pairs of quotes \u0026quot;\u0026quot;\u0026quot; are used.\nprint(\u0026#34;Ciao Mondo\u0026#34;) # Questo è un commento breve # Anche questo è un commento breve \u0026#34;\u0026#34;\u0026#34; Questo è un commento più lungo ed articolato che può stare su più righe \u0026#34;\u0026#34;\u0026#34; Variables Python is a dynamically typed language, meaning that you don’t need to specify the type of a variable when declaring it. The variable’s type is determined automatically during runtime based on the assigned value.\nx = 0 # Questa è una variabile con valore iniziale 0 Input and Output Now that we’ve seen how to declare a variable, let’s see how to assign it a value and how to print its content.\nx = 0 y = 0 input(\u0026#34;Inserisci il valore di x: \u0026#34;) input(\u0026#34;Inserisci il valore di y: \u0026#34;) print(f\u0026#34;Hai inserito {x} come valore di x e {y} come valore di y!\u0026#34;) At this link, you’ll find a very simple script that demonstrates how to use what we’ve just learned.\nSummary Now that we understand what Python is, why it’s a powerful and versatile tool, and why learning (at least) the basics can be extremely useful, we’ve also seen how to declare variables, assign values to them, and read their contents. In the next article, we will delve deeper into the various implicit types of variables, explore different data types, and learn how to manipulate them to take full advantage of Python’s capabilities.\n","permalink":"https://antoniomontemurro.com/en/posts/python-basic-syntax/","summary":"\u003ch2 id=\"indentation\"\u003eIndentation\u003c/h2\u003e\n\u003cp\u003eIn Python, code blocks are identified through the use of indentation. Indentation involves leaving a specific number of spaces before starting to write code. As the number of spaces changes, so does the block to which the code belongs.\u003c/p\u003e\n\u003cp\u003e\u003cimg alt=\"comments.jpg\" loading=\"lazy\" src=\"/img/python-basic-syntax/comments.jpg\"\u003e\u003c/p\u003e\n\u003cp\u003ePython doesn’t enforce a fixed number of spaces, but it does require consistency in your choice: once you decide on a certain number of spaces for indentation, you must maintain that throughout the file.\u003c/p\u003e","title":"Python – Basic Syntax"},{"content":"If you’re reading this article, it’s probably your first experience with Python and, in general, with programming. In this article, we’ll go over how to install Python, choose an IDE, and write a simple program to make sure everything is working correctly.\nAfter discussing why Python can be a great choice for both beginners and experienced programmers, let’s now look at how to set up Python and choose the right IDE.\nInstalling Python Installing Python is very easy. Go to the official website and download the latest version, which you’ll find highlighted at the top in the Downloads section. The system will automatically select the version compatible with your operating system.\nAt this point, proceed with the installation (on Windows) by double-clicking on the downloaded file. To verify that Python has been installed correctly, open the command prompt and type the following command:\npython --version If the terminal shows the version of Python you’ve just installed, you’re done. However, if the terminal doesn’t recognize the command, you’ll need to manually add Python to the environment variables. I suggest following this guide for that.\nWhich IDE to use? Now that we’ve installed Python, the next question is: which tool should we use to write and run the code?\nYou don’t need any specific tool (in the worst-case scenario, you could even use the basic “Notepad” on Windows or any other text editor), but to write code in a more professional way, we need a proper IDE.\nWhat is an IDE? IDE stands for Integrated Development Environment, which is an application that provides various tools useful for software development.\nThe two tools we are most interested in are the debugger and IntelliSense.\nDebugger: The debugger is a tool for analyzing code, essential for finding and fixing bugs, which are programming errors that prevent our code from functioning correctly. IntelliSense: is a feature integrated into most IDEs and for the majority of programming languages. Its function is to provide auto-completion for instructions, saving time and preventing simple typing errors. PyCharm There are several IDEs that support Python, many of which are completely free, while others offer a basic set of features for free.\nThe one we’ll use in the following articles is PyCharm in its free version. Once downloaded, double-click the file, and a typical Windows installation wizard will appear. At one point, you’ll be asked to select some options; in my opinion, it’s best to select all of them.\nOnce PyCharm is installed, we’re ready to write our first Python program.\nHello World As every experienced developer knows, there’s nothing more classic than writing a “Hello World” as your first program. So why break tradition?\nFirst, open the IDE and accept the terms presented to you upon first launch. If you have other IDEs installed, PyCharm may ask if you want to import their configurations. Feel free to do so, but the important thing is to reach the next step.\nNow click on “New Project”, give your project a name, for example, “helloWorld”, choose a location to save it, and, leaving the rest unchanged, click on “Create”.\nAfter a brief process, the IDE will present you with a new window where you can manage your project.\nLet’s immediately create our first file where we’ll write the code, and name it “main”. Then, write the following:\nprint(\u0026#34;Hello World\u0026#34;) Now, by clicking on the “Play” button at the top, you’ll see the text appear in the console.\n","permalink":"https://antoniomontemurro.com/en/posts/python-setup-and-choosing-an-ide/","summary":"\u003cp\u003eIf you’re reading this article, it’s probably your first experience with Python and, in general, with programming. In this article, we’ll go over how to install Python, choose an IDE, and write a simple program to make sure everything is working correctly.\u003c/p\u003e\n\u003cp\u003eAfter \u003ca href=\"/en/posts/why-learn-python/\"\u003ediscussing why Python can be a great choice\u003c/a\u003e for both beginners and experienced programmers, let’s now look at how to set up Python and choose the right IDE.\u003c/p\u003e","title":"Python Setup and Choosing an IDE"},{"content":"\nPython is a high-level programming language, created by mathematician and computer scientist Guido Van Rossum in 1991. According to Van Rossum, Python was designed to be simple, easy to understand, and easy for anyone to learn.\nThese aspects have allowed Python to become one of the most popular programming languages in the world, especially thanks to its applications in modern fields like artificial intelligence.\nAdvantages and Features The main features of Python are:\nEase of learning: It is considered one of the easiest programming languages to learn, even for beginners. Libraries: It has a vast range of libraries that extend its functionality, from image manipulation to the creation of GUIs and video games. Object-Oriented: Python supports object-oriented programming, with concepts like classes, objects, inheritance, etc. Precompiled code: Although it is interpreted, its code is precompiled into bytecode to improve performance. Dynamic typing: Variables are not statically typed; the type is determined at runtime, based on the assigned value. Cross-platform: Python code can run on Windows, macOS, and Unix, although some libraries might not be compatible across all platforms. Use Cases Due to its simplicity and versatility, Python is used in various contexts, such as:\nSoftware development (web and desktop), thanks to its many libraries and frameworks. Machine learning and Artificial Intelligence. Data Science and Web Scraping. Video game development. Why Learn Python? The simplest and most obvious answer would be: “Why not?”\nIn recent years, Python has become one of the most widely used programming languages, as confirmed by data from GitHub. Regardless of your experience, learning Python can enrich your skillset and make you more competitive in the job market.\nThis means that whether you’re a beginner or an experienced programmer, if your goal is to stay competitive, Python is a valuable skill worth investing your time in.\nIf you want to learn more, visit the official Python website or explore our dedicated section in the top menu.\n","permalink":"https://antoniomontemurro.com/en/posts/why-learn-python/","summary":"\u003cp\u003e\u003cimg alt=\"Logo-della-Python-1024x576.png\" loading=\"lazy\" src=\"/img/why-learn-python/Logo-della-Python-1024x576.png\"\u003e\u003c/p\u003e\n\u003cp\u003ePython is a high-level programming language, created by mathematician and computer scientist Guido Van Rossum in 1991. According to Van Rossum, Python was designed to be simple, easy to understand, and easy for anyone to learn.\u003c/p\u003e\n\u003cp\u003eThese aspects have allowed Python to become one of the most popular programming languages in the world, especially thanks to its applications in modern fields like artificial intelligence.\u003c/p\u003e\n\u003ch2 id=\"advantages-and-features\"\u003eAdvantages and Features\u003c/h2\u003e\n\u003cp\u003eThe main features of Python are:\u003c/p\u003e","title":"Python: What it is and Why Use it"},{"content":"My name is Antonio Montemurro and I have been working as a software developer since 2018.\nI mainly work on backend development in Java, almost always with Spring, and lately I have been looking into Vert.x. Over the years I have also worked with other technologies: native apps for both Android and iOS, Flutter, React, Python and .NET. These experiences reflect a curiosity for trying different tools.\nThis blog sits halfway between a personal journal and an account of my professional path. It collects the projects I develop on my own and notes on what I learn.\nYou can find me on GitHub and LinkedIn.\n","permalink":"https://antoniomontemurro.com/en/about/","summary":"\u003cp\u003eMy name is Antonio Montemurro and I have been working as a software developer since 2018.\u003c/p\u003e\n\u003cp\u003eI mainly work on backend development in Java, almost always with Spring, and lately I have been looking into Vert.x. Over the years I have also worked with other technologies: native apps for both Android and iOS, Flutter, React, Python and .NET. These experiences reflect a curiosity for trying different tools.\u003c/p\u003e\n\u003cp\u003eThis blog sits halfway between a personal journal and an account of my professional path. It collects the \u003ca href=\"/en/categories/projects/\"\u003eprojects\u003c/a\u003e I develop on my own and \u003ca href=\"/en/posts/\"\u003enotes\u003c/a\u003e on what I learn.\u003c/p\u003e","title":"About"}]