<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Zeki</title>
    <description>The latest articles on DEV Community by Zeki (@jusufoski).</description>
    <link>https://dev.to/jusufoski</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1475895%2Fca55080c-acb1-4935-9e39-a5a22eb780cc.jpg</url>
      <title>DEV Community: Zeki</title>
      <link>https://dev.to/jusufoski</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jusufoski"/>
    <language>en</language>
    <item>
      <title>Project Loom: New Java Virtual Threads</title>
      <dc:creator>Zeki</dc:creator>
      <pubDate>Thu, 20 Jun 2024 12:23:52 +0000</pubDate>
      <link>https://dev.to/jusufoski/project-loom-new-java-virtual-threads-39m2</link>
      <guid>https://dev.to/jusufoski/project-loom-new-java-virtual-threads-39m2</guid>
      <description>&lt;p&gt;Project Loom: New Java Virtual Threads&lt;br&gt;
By using Java 21 lightweight threads, developers can create high-throughput concurrent applications with less code, easier maintenance, and improved observability.&lt;/p&gt;

&lt;p&gt;For many years, the primary way to propose changes to the Java language and the JVM has been through documents called JDK Enhancement Proposals (JEPs). These documents follow a specific format and are submitted to the OpenJDK website.&lt;/p&gt;

&lt;p&gt;While JEPs represent individual proposals, they are frequently adopted as groups of related enhancements that form what the Java team refers to as projects. These projects are named rather randomly, sometimes after things (Loom, where threads are turned into cloth) or places (Valhalla, the fabled hall of Norse mythology) or the technology itself (Lambda).&lt;/p&gt;

&lt;p&gt;Project Loom’s main objective is to enhance the capabilities of Java for concurrent programming by offering two key features: efficient virtual threads and support for structured concurrency.&lt;/p&gt;
&lt;h2&gt;
  
  
  Java Platform Threads
&lt;/h2&gt;

&lt;p&gt;Every Java program starts with a single thread, called the main thread. This thread is responsible for executing the code within the main method of your program.&lt;/p&gt;

&lt;p&gt;Tasks are executed one after another. The program waits for each task to complete before moving on to the next. This can lead to a less responsive user experience if tasks take a long time (e.g., network requests)&lt;/p&gt;

&lt;p&gt;Both asynchronous programming and multithreading are techniques used to achieve some level of concurrency in your code, but they work in fundamentally different ways:&lt;/p&gt;

&lt;p&gt;Asynchronous Programming focuses on non-blocking execution of tasks. It initiates tasks without waiting for them to finish and allows the program to continue with other work. This doesn’t necessarily involve multiple threads. It can be implemented even in a single-threaded environment using mechanisms like callbacks and event loops.&lt;/p&gt;

&lt;p&gt;While asynchronous programming offers advantages, it can also be challenging. Asynchronous calls disrupt the natural flow of execution, potentially requiring simple 20-line tasks to be split across multiple files and threads. This complexity can significantly increase development time and make it harder to understand the actual program behavior.&lt;/p&gt;

&lt;p&gt;Multithreading focuses on concurrent execution of tasks. It creates multiple threads, each running its own instructions, allowing them to potentially execute at the same time (depending on available resources). involves multiple threads running concurrently and focuses on dividing and executing tasks truly in parallel. &lt;/p&gt;

&lt;p&gt;While Java Virtual Machine (JVM) plays a crucial role in their creation, execution, and scheduling, Java threads are primarily managed by the underlying operating system’s scheduler.&lt;/p&gt;

&lt;p&gt;As a result, Creating and managing threads introduces some overhead due to startup (around 1ms), memory overhead(2MB in stack memory), context switching between different threads when the OS scheduler switches execution. If a system spawns thousands of threads, we are speaking of significant slowdown here. &lt;/p&gt;

&lt;p&gt;Multithreading offers potential performance benefits, it introduces additional complexity due to thread management and synchronization.&lt;/p&gt;

&lt;p&gt;The question that arises is: how to get the simplicity of synchronous operations with the performance of asynchronous calls?&lt;/p&gt;
&lt;h2&gt;
  
  
  Why Virtual Threads?
&lt;/h2&gt;

&lt;p&gt;Platform threads are  expensive to create because the operating system needs a big chunk of memory just for each thread. &lt;/p&gt;

&lt;p&gt;This is because the memory can’t be adjusted, and it all gets used up for the thread’s information and instructions. On top of that, whenever the system needs to switch between threads, it has to move all this memory around, which can be slow.&lt;/p&gt;

&lt;p&gt;In addition to above, we have complexity that multiple threads can access and modify the same data (shared resources) simultaneously. This can lead to race conditions, where the outcome depends on unpredictable timing of thread execution.&lt;/p&gt;

&lt;p&gt;To simplify things, the easiest way to handle multiple tasks at once in Java seems like assigning each task its own worker. This approach is called “one task per thread”.&lt;/p&gt;

&lt;p&gt;However, using such an approach, we can easily reach the limit of the number of threads we can create.&lt;/p&gt;

&lt;p&gt;As an example, let’s create a simple maven module in  IntelliJ IDEA IDE, called PlatformThreads.&lt;/p&gt;

&lt;p&gt;We create a class MyThread creating simple platform thread:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package org.example;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.time.Duration;

public class MyThread extends Thread {
   Logger logger = LoggerFactory.getLogger(MyThread.class);

   public void run(){
       logger.info("{} ", Thread.currentThread());
       try {
           Thread.sleep(Duration.ofSeconds(1L));
       } catch (InterruptedException e) {
           throw new RuntimeException(e);
       }
   }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the Main class we have a method Create_10_000_Threads&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package org.example;
public class Main {
   public static void main(String[] args) {
       Create_10_000_Threads();
   }
   private static void Create_10_000_Threads() {
       for (int i = 0; i &amp;lt; 10_000; i++) {
           MyThread myThread = new MyThread();
           myThread.start();
       }
   }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we run this program, very quickly we get following console output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[0.854s][warning][os,thread] Failed to start the native thread for java.lang.Thread "Thread-4063"
Exception in thread "main" java.lang.OutOfMemoryError: unable to create native thread: possibly out of memory or process/resource limits reached
    at java.base/java.lang.Thread.start0(Native Method)
    at java.base/java.lang.Thread.start(Thread.java:1526)
    at org.example.Main.Create_10_000_Threads(Main.java:9)
    at org.example.Main.main(Main.java:4)
[ERROR] Command execution failed.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This simple example shows how difficult it is to achieve “one task per thread” using traditional multithreading.&lt;/p&gt;

&lt;h2&gt;
  
  
  Java Virtual Threads
&lt;/h2&gt;

&lt;p&gt;Enter Java Virtual Threads(&lt;a href="https://openjdk.org/jeps/425"&gt;JEP 425&lt;/a&gt;). Introduced in Java 17 with Project Loom, aim to reduce this overhead by being managed within the JVM itself, potentially offering better performance for certain scenarios.&lt;/p&gt;

&lt;p&gt;Lets see for example how we can create virtual threads. We created a module in the same project named VirtualThreads.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;MyThread class implementing Runnable interface:

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.time.Duration;
public class MyThread implements Runnable{
   Logger logger = LoggerFactory.getLogger(MyThread.class);
   @Override
   public void run() {
       logger.info("{} ", Thread.currentThread());
       try {
           Thread.sleep(Duration.ofSeconds(1L));
       } catch (InterruptedException e) {
           throw new RuntimeException(e);
       }
   }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the main class we have a method that again creates 10 thousand threads, this time virtual ones.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package org.example;

public class Main {
   public static void main(String[] args) {

       Create_10_000_Threads();
   }

   private static void Create_10_000_Threads() {
       for (int i = 0; i &amp;lt; 10_000; i++) {
           Runnable runnable = new MyThread();
           Thread vThread = Thread.ofVirtual().start(runnable);
       }
   }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Creating a new virtual thread in Java is as simple as using the Thread.ofVirtual() factory method, passing an implementation of the Runnable interface that defines the code the thread will execute.&lt;/p&gt;

&lt;p&gt;This time the program successfully executes with no error.&lt;/p&gt;

&lt;p&gt;Unlike Platform Threads, Virtual Threads are created in Heap memory, and assigned to a Carrier Thread (Platform) only if there is work to be done.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F40lw3fva750ebdosf3t2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F40lw3fva750ebdosf3t2.png" alt="Image description" width="411" height="288"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;              **Virtual threads Architecture**
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This way we can create many virtual threads with very low memory footprint and at the same time ensure backward compatibility.&lt;/p&gt;

&lt;p&gt;It’s important to note that Project Loom’s virtual threads are designed to be backward compatible with existing Java code. This means your existing threading code will continue to work seamlessly even if you choose to use virtual threads.&lt;/p&gt;

&lt;p&gt;In traditional java threads, when a server was waiting for a request, the operating system was also waiting.&lt;/p&gt;

&lt;p&gt;Since virtual threads are controlled by JVM and detached from the operation system, JVM is able to assign compute resources when virtual threads are waiting for response.&lt;/p&gt;

&lt;p&gt;This significantly improves the efficiency of computing resource usage.&lt;/p&gt;

&lt;p&gt;This new approach to concurrency is possible by introducing something called continuations and structured concurrency.&lt;/p&gt;

&lt;p&gt;Continuation is a programming technique that allows a program to pause its execution at a specific point and later resume at the same point, carrying the necessary context.&lt;/p&gt;

&lt;p&gt;The continuation object is used to restore the thread’s state, allowing it to pick up exactly where it left off without losing any information or progress&lt;/p&gt;

&lt;p&gt;Structured concurrency(&lt;a href="https://openjdk.org/jeps/453"&gt;JEP 453&lt;/a&gt;) aims to provide a synchronous-style syntax for working with asynchronous tasks. This approach simplifies writing basic concurrent tasks, making them easier to understand and express for Java developers.&lt;/p&gt;

&lt;p&gt;Structured concurrency simplifies managing concurrent tasks by treating groups of related tasks across different threads as a single unit. This approach makes error handling, cancellation, reliability, and observability all easier to manage.&lt;/p&gt;

&lt;p&gt;Project Loom’s innovations hold promise for various applications. The potential for vastly improved thread efficiency and reduced resource needs when handling multiple tasks translates to significantly higher throughput for servers. This translates to better response times and improved performance, ultimately benefiting a wide range of existing and future Java applications.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Types of Computer Security Threats</title>
      <dc:creator>Zeki</dc:creator>
      <pubDate>Sat, 15 Jun 2024 12:40:26 +0000</pubDate>
      <link>https://dev.to/jusufoski/types-of-computer-security-threats-dc8</link>
      <guid>https://dev.to/jusufoski/types-of-computer-security-threats-dc8</guid>
      <description>&lt;p&gt;From mobile banking to online shopping, from healthcare systems to smart devices, software applications facilitate communication and enhance productivity.&lt;br&gt;
However, this pervasive reliance on software also exposes individuals, businesses, and institutions to a myriad of security threats.&lt;/p&gt;

&lt;p&gt;In this article, we delve into the intricate web of security threats that loom over software applications, exploring their nature, impact, and mitigation strategies.&lt;/p&gt;

&lt;p&gt;Read also: &lt;a href="https://infosafe24.com/posts/11-Ways-to-Improve-Security-of-Your-Online-Presence"&gt;Transformation of Privacy in the Digital Age&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Software security threats encompass a broad spectrum of malicious activities aimed at exploiting vulnerabilities in software applications. &lt;br&gt;
These threats pose significant risks to the confidentiality, integrity, and availability of data and systems. &lt;br&gt;
Understanding the various types of security threats is crucial for developers, businesses, and users to implement effective countermeasures and safeguard against potential breaches.&lt;/p&gt;

&lt;h2&gt;
  
  
  Malware
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Malware&lt;/em&gt;, short for malicious software, represents one of the most pervasive and insidious threats to software applications. &lt;br&gt;&lt;br&gt;&lt;br&gt;
&lt;em&gt;viruses&lt;/em&gt;, self-replicating programs that spread from one device to another,&lt;br&gt;
worms, viruses exploiting network vulnerabilities to spread,&lt;br&gt;  &lt;/p&gt;

&lt;p&gt;&lt;em&gt;trojans&lt;/em&gt;, disguised as legitimate software to trick you into installing them,&lt;br&gt;
 ransomware, Locks your files or system and demands a ransom payment to unlock them, and &lt;br&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;spyware&lt;/em&gt;, stealing your personal information without your knowledge,&lt;br&gt;
are among the diverse array of malware that can infiltrate systems, compromise data, and disrupt operations. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phishing&lt;/strong&gt; emails are one of the most prevalent methods of malware infiltration,  attackers craft emails that appear to be from legitimate sources like banks, credit card companies, or even familiar people. &lt;br&gt;
These emails typically urge you to click on malicious links or download infected attachments. &lt;br&gt;
Once clicked, the links can download malware directly, or they might take you to a compromised website booby-trapped with malware.&lt;br&gt;
Unsecured downloads, software vulnerabilities, visiting compromised websites are some other methods for infiltration.&lt;br&gt;
By being aware of these methods and practicing safe computing habits, you can significantly reduce the risk of malware infecting your computer system.&lt;/p&gt;

&lt;p&gt;Read also: &lt;a href="https://infosafe24.com/posts/How-to-Detect-Phishing-Attacks"&gt;How to Detect Phishing Attacks&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With evolving techniques and distribution methods, malware continues to evolve, posing a persistent challenge to cybersecurity professionals worldwide.&lt;/p&gt;

&lt;h2&gt;
  
  
  Web Application Vulnerabilities
&lt;/h2&gt;

&lt;p&gt;Web applications, with their ubiquitous presence and dynamic functionality, introduce unique security challenges. &lt;br&gt;
SQL injection, cross-site scripting (XSS), cross-site request forgery (CSRF), and other vulnerabilities expose web applications to exploitation, data breaches, and unauthorized access. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SQL injection&lt;/strong&gt; (SQLi) is a cyberattack that targets applications connected to databases. It exploits vulnerabilities in how the application handles user input. Attackers can inject malicious SQL code into forms, queries, or other data entry points to manipulate the database.&lt;br&gt;
XSS, which stands for Cross-Site Scripting, is a type of security vulnerability  exploited by attackers to inject malicious scripts into websites. &lt;br&gt;
These scripts then run in the victim's web browser, potentially compromising their data or hijacking their session.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CSRF&lt;/strong&gt;, also known as Cross-Site Request Forgery, is a web security vulnerability that allows attackers to trick users into performing unintended actions on a web application they're already authenticated to.&lt;br&gt;
Imagine you're logged into your bank account (authenticated). An attacker tricks you into visiting a malicious website (crafted to trigger a CSRF attack). &lt;br&gt;
In the background, without your knowledge or consent, this malicious website submits a request to your bank account (using your already authenticated session) -  possibly a transfer request to the attacker's account!&lt;/p&gt;

&lt;p&gt;Thes attacks exploit website vulnerabilities in the way it handles user input, such as data from comments sections, search bars, or user profiles. This flaw allows the attacker to inject malicious code without the website properly recognizing it.&lt;br&gt;
The attacker also can insert malicious script disguised as regular user input into a vulnerable field on the website. This script could be written in JavaScript, HTML, or other languages that web browsers can understand.&lt;br&gt;
When the victim visits the compromised webpage, their browser unknowingly executes the attacker's script. This can lead to various consequences depending on the attacker's goals.&lt;br&gt;
As the primary interface for user interaction, securing web applications is paramount for protecting sensitive data and preserving user trust.&lt;/p&gt;

&lt;h2&gt;
  
  
  Network-Based Threats
&lt;/h2&gt;

&lt;p&gt;Network-based threats, such as Denial of service (DoS) and distributed denial of service (DDoS) attacks, target the availability of software applications by overwhelming network resources with malicious traffic. &lt;br&gt;
DDoS stands for Distributed Denial-of-Service. It's a cyberattack that aims to disrupt the normal traffic of a website, service, or network by overwhelming it with a flood of internet requests. &lt;br&gt;
Imagine a traffic jam so severe that no regular traffic can reach its destination. That's what a DDoS attack attempts to do in the digital world.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;There are various ways of execution:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Botnet Army&lt;/strong&gt;, attackers build an army of compromised devices, often called a botnet. These devices can be personal computers, smartphones, or even Internet-of-Things (IoT) gadgets that have been unknowingly infected with malware, giving the attacker control.&lt;br&gt;
Command and Control, attacker remotely controls the botnet, issuing commands to launch the attack.&lt;br&gt;
Flooding the Target, each infected device in the botnet sends a massive amount of fake traffic requests to the target website or service. This can be pings, HTTP requests, or other types of traffic.&lt;/p&gt;

&lt;p&gt;A &lt;strong&gt;man-in-the-middle&lt;/strong&gt; (MITM) attack is a cyberattack where the attacker secretly inserts themselves into the communication between two parties, allowing them to eavesdrop on the conversation or even alter the messages being exchanged. It's like a hidden listener on a phone call, able to hear both sides and potentially tamper with what's being said.&lt;/p&gt;

&lt;p&gt;The attacker positions themself between the victim and the legitimate website or service they are trying to communicate with. &lt;br&gt;
This can be achieved through various methods like:&lt;br&gt;
Unsecured Wi-Fi Networks, attackers can set up fake Wi-Fi hotspots that appear legitimate, tricking users into connecting. Once connected, the attacker can intercept traffic between the user's device and the internet.&lt;br&gt;
DNS Spoofing,  the attacker redirects the victim's traffic to a malicious website that impersonates the real one.&lt;br&gt;
ARP Spoofing, in a local network, the attacker tricks other devices into believing their machine is the intended recipient, allowing them to intercept communication.&lt;/p&gt;

&lt;h2&gt;
  
  
  Insider Threats
&lt;/h2&gt;

&lt;p&gt;Insider threats emanate from individuals within organizations who misuse their access privileges to compromise security. Whether through malicious intent, negligence, or coercion, insiders can steal sensitive data, sabotage systems, or facilitate external attacks. &lt;br&gt;
Detecting and mitigating insider threats requires a combination of technical controls, policy enforcement, and employee education to safeguard against internal risks.&lt;br&gt;
Turncoats: These individuals intentionally steal data, sabotage systems, or commit fraud for personal gain, revenge, or to benefit a competitor.&lt;br&gt;
Disgruntled Employees: Employees who are unhappy with the company, facing termination, or have personal grievances might resort to malicious actions as a form of retaliation.&lt;br&gt;
Careless Users: Employees who lack proper cybersecurity awareness or training might accidentally expose sensitive data through phishing attacks, weak passwords, or sharing information with unauthorized individuals.&lt;br&gt;
Bypassing Security Controls: Intentionally or unintentionally circumventing security measures due to convenience or a lack of understanding about their importance.&lt;/p&gt;

&lt;p&gt;These insiders can misuse their access intentionally (malicious) or unintentionally (negligent) to harm the organization. &lt;/p&gt;

&lt;h2&gt;
  
  
  Internet of Things (IoT)
&lt;/h2&gt;

&lt;p&gt;The proliferation of Internet-connected devices in the IoT ecosystem introduces new avenues for security threats. &lt;br&gt;
Insecure IoT devices, lacking robust authentication, encryption, and update mechanisms, are susceptible to exploitation by malicious actors. &lt;br&gt;
Internet of Things (IoT) devices, while bringing convenience and automation to our lives, introduce new security challenges. &lt;br&gt;
These devices are often vulnerable due to several factors:&lt;br&gt;
Limited Resources: Many IoT devices are designed with low power consumption and minimal cost in mind. This often leads to limited processing power, memory, and storage which can restrict robust security features.&lt;br&gt;
Pre-configured Software and Firmware: Manufacturers sometimes pre-install software and firmware with default settings or weak passwords, making them easy targets for attackers to exploit known vulnerabilities.&lt;br&gt;
Neglecting Updates: Unlike traditional computers, IoT devices may not have easy-to-use update mechanisms or automatic update functionality. Users might neglect to install critical security patches, leaving devices vulnerable to new threats.&lt;br&gt;
Insecure Communication Protocols: Some IoT devices rely on outdated or unencrypted communication protocols, allowing attackers to intercept or manipulate data transmissions.&lt;br&gt;
Lack of Device Management: Organizations might struggle to keep track of all their IoT devices, making it difficult to enforce security policies, deploy updates, or monitor for suspicious activity.&lt;/p&gt;

&lt;p&gt;Compromised IoT devices can not only jeopardize user privacy and safety but also pose broader risks to critical infrastructure and public safety. Securing the IoT requires collaboration among manufacturers, regulators, and consumers to establish baseline security standards and best practices.&lt;/p&gt;

&lt;h2&gt;
  
  
  Social Engineering
&lt;/h2&gt;

&lt;p&gt;Despite advancements in cybersecurity awareness and education, social engineering remains a potent threat vector.&lt;br&gt;
Social engineering is a deceptive technique used by attackers to manipulate individuals into divulging sensitive information, performing actions, or bypassing security measures. Unlike traditional hacking methods that rely on exploiting technical vulnerabilities, social engineering exploits human psychology and trust to achieve malicious objectives. It preys on emotions such as curiosity, fear, urgency, or greed to persuade targets to comply with the attacker's requests.&lt;br&gt;
Phishing, pretexting, baiting, and other social engineering tactics prey on trust, curiosity, and ignorance to deceive users into divulging sensitive information or performing actions that compromise security. &lt;br&gt;
Phishing is a technique when attackers send fraudulent emails, messages, or websites that mimic legitimate entities to trick recipients into disclosing personal information such as login credentials, credit card numbers, or account details.&lt;br&gt;
Pretexting is creating a fabricated scenario or pretext to manipulate targets into providing information or performing actions. This may involve impersonating authority figures, such as IT support personnel or company executives, to gain trust and elicit sensitive information.&lt;/p&gt;

&lt;p&gt;Attackers may impersonate trusted individuals or organizations, such as coworkers, IT staff, or service providers, to deceive targets into complying with their requests.&lt;/p&gt;

&lt;p&gt;Attackers may offer enticing incentives, such as free downloads, prizes, or rewards, to lure targets into clicking on malicious links or downloading malware-infected files in a technique called baiting.&lt;br&gt;
Social engineering attacks can have serious consequences, including data breaches, identity theft, financial loss, and reputational damage. To mitigate the risks of social engineering, organizations should invest in employee training and awareness programs to recognize and resist manipulation tactics. Additionally, implementing multi-factor authentication, establishing clear communication protocols, and maintaining a culture of skepticism can help defend against social engineering attacks.&lt;/p&gt;

&lt;h2&gt;
  
  
  Emerging Threats
&lt;/h2&gt;

&lt;p&gt;Emerging threats, such as zero-day exploits and advanced persistent threats (APTs), exploit unknown vulnerabilities to evade detection and bypass traditional security measures. &lt;br&gt;
Zero-day exploits, also written as 0-day exploits, are a serious cybersecurity threat. They exploit vulnerabilities in software, hardware, or firmware that are unknown to the vendor or developer. This  means there's no patch or security fix available yet, leaving systems vulnerable until a solution is developed.&lt;br&gt;
Advanced persistent threats (APTs) are sophisticated cyberattacks unlike your typical hit-and-run malware infections.  APT actors are well-funded and highly skilled groups (often state-sponsored) who target specific organizations for long-term strategic goals, such as stealing intellectual property, disrupting operations, or conducting espionage.&lt;br&gt;
A proactive approach to threat intelligence, vulnerability management, and patching is essential for mitigating emerging security risks.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In conclusion, the landscape of security threats to software applications is dynamic, multifaceted, and constantly evolving. From traditional malware to emerging zero-day exploits, the breadth and complexity of security challenges demand vigilance, collaboration, and innovation. &lt;br&gt;
By adopting a holistic approach to cybersecurity, integrating robust technical controls, proactive threat intelligence, and user awareness, organizations can mitigate risks and fortify their defenses against evolving threats. Ultimately, safeguarding software applications is not merely a technological endeavor but a shared responsibility to protect digital assets, preserve trust, and uphold the integrity of the interconnected world we inhabit.&lt;/p&gt;

</description>
      <category>cybersecurity</category>
      <category>infosec</category>
      <category>security</category>
      <category>informationsecurity</category>
    </item>
    <item>
      <title>How to secure your mobile device?</title>
      <dc:creator>Zeki</dc:creator>
      <pubDate>Thu, 23 May 2024 11:30:53 +0000</pubDate>
      <link>https://dev.to/jusufoski/how-to-secure-your-mobile-device-5d93</link>
      <guid>https://dev.to/jusufoski/how-to-secure-your-mobile-device-5d93</guid>
      <description>&lt;p&gt;Our mobile devices have become an indispensable part of our lives. From communication and entertainment to banking and work tasks, these pocket-sized powerhouses hold a wealth of personal information.&lt;/p&gt;

&lt;p&gt;However, this convenience comes with a cost — the vulnerability of our data to cyberattacks.&lt;/p&gt;

&lt;p&gt;Actions can be taken to fortify the security of our mobile devices and those actions can be divided into three broad categories: various actions to make our device more immune to attacks, protect our data, and be mindful when online.&lt;/p&gt;

&lt;h2&gt;
  
  
  Fortify the Defense of your Device:
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Lock it down:&lt;/strong&gt;&lt;br&gt;
Opt for longer, complex passwords or PINs with a mix of uppercase and lowercase letters, numbers, and symbols, fingerprint, or facial recognition to secure your device’s lock screen.&lt;/p&gt;

&lt;p&gt;This prevents unauthorized access to your data and apps.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Keep software updated:&lt;/strong&gt;&lt;br&gt;
Regularly update your operating system and app software to patch vulnerabilities and security holes. Outdated software is more susceptible to attacks.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Consider a mobile security app:&lt;/strong&gt;&lt;br&gt;
These apps scan your device for malicious software (malware) like viruses, spyware, and ransomware. They can quarantine or remove threats detected on your device.&lt;/p&gt;

&lt;p&gt;Anti theft features help you locate, lock, or wipe your device remotely in case of loss or theft. Some apps can even trigger an alarm on your missing device.&lt;/p&gt;

&lt;p&gt;Certain mobile security apps offer secure web browsing capabilities. This can involve features like blocking malicious websites, preventing phishing attempts, and protecting your online privacy.&lt;/p&gt;

&lt;p&gt;Some apps monitor for data breaches that might expose your login credentials leaked from other online services. They can alert you if your information is compromised.&lt;/p&gt;

&lt;p&gt;Security apps can offer additional features like malware scanning, anti-theft protection, and secure browsing.&lt;/p&gt;

&lt;p&gt;By using a reputable app alongside other security practices like strong passwords and keeping your software updated, you can significantly improve your mobile device’s security posture.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Be cautious with downloads:&lt;/strong&gt;&lt;br&gt;
Only download apps from trusted sources like official app stores (Google Play Store, Apple App Store).&lt;/p&gt;

&lt;p&gt;Avoid downloading apps from untrusted third-party app stores or websites. These sources may harbor malware-laden apps disguised as legitimate ones.&lt;/p&gt;

&lt;p&gt;Take time to read the app description to understand its purpose and functionalities. Look for reviews from other users to gauge the app’s legitimacy and user experience. Negative reviews mentioning security concerns or suspicious behavior are red flags.&lt;/p&gt;

&lt;p&gt;Before downloading an app, pay close attention to the permissions it requests. Does a photo editing app need access to your location or microphone? If an app requests permissions that seem unrelated to its core functionality, be cautious. Only grant permissions genuinely necessary for the app to work.&lt;/p&gt;

&lt;p&gt;Generally, apps with fewer permission requests pose a lower security risk.&lt;/p&gt;

&lt;h2&gt;
  
  
  Protect your Data:
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Turn off file sharing:&lt;/strong&gt;&lt;br&gt;
Bluetooth file sharing and Wi-Fi Direct features allow file sharing between devices in close proximity.&lt;/p&gt;

&lt;p&gt;However, leaving them enabled creates open doors for unauthorized access, especially on unsecure public Wi-Fi networks. Disable them when not actively sharing files.&lt;/p&gt;

&lt;p&gt;Before sharing any file, ask yourself if the information it contains is sensitive. Financial documents, personal photos, or confidential work documents require extra caution.&lt;/p&gt;

&lt;p&gt;Limit file sharing to trusted individuals or recipients. Avoid sharing files with people you don’t know well or on unreliable platforms.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Encrypt your data:&lt;/strong&gt;&lt;br&gt;
Consider encrypting your device’s storage if your device offers this option. Encryption scrambles your data, making it unreadable if stolen.&lt;/p&gt;

&lt;p&gt;While full-device encryption is ideal, some mobile devices might not offer it, or you might only want to encrypt specific files for additional protection.&lt;/p&gt;

&lt;p&gt;Several third-party apps offer file encryption functionalities. These apps allow you to create password-protected vaults for your sensitive files.&lt;/p&gt;

&lt;p&gt;Research reputable apps with good reviews before installing them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Beware of phishing scams:&lt;/strong&gt;&lt;br&gt;
Don’t click on suspicious links or attachments in text messages or emails. These scams can be used to steal your personal information or infect your device with malware.&lt;/p&gt;

&lt;p&gt;Phishing messages often contain links or attachments that appear legitimate but can lead to malicious websites or download malware. Be wary of clicking on anything in unsolicited messages, even if they seem to come from familiar sources like banks or social media platforms.&lt;/p&gt;

&lt;p&gt;Use strong passwords and enable two-factor authentication (2FA):&lt;br&gt;
This adds an extra layer of security by requiring a second verification code when logging into accounts. Avoid using the same password for multiple accounts.&lt;/p&gt;

&lt;h2&gt;
  
  
  Online Vigilance:
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Use secure Wi-Fi&lt;/strong&gt;&lt;br&gt;
Avoid using public Wi-Fi networks for sensitive activities like online banking or entering passwords. If you must use public Wi-Fi, consider using a VPN (Virtual Private Network) to encrypt your internet traffic.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Review privacy settings&lt;/strong&gt;&lt;br&gt;
Review and adjust privacy settings for your apps and social media accounts. Limit the amount of information shared publicly and be mindful of the permissions granted to apps.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Backup your data:&lt;/strong&gt;&lt;br&gt;
Regularly back up your data to a secure cloud storage service or an external hard drive. This ensures you don’t lose your important information if your device is lost, stolen, or damaged.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Be mindful of what you share:&lt;/strong&gt;&lt;br&gt;
Think before you share anything online, especially sensitive information. Once something is online, it can be difficult to completely erase it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bonus Security Tips:
&lt;/h2&gt;

&lt;p&gt;Enable “Find My Device” (Android) or “Find My iPhone” (Apple) to locate your lost or stolen device remotely, and even erase data if necessary.&lt;br&gt;
Disable autofill features for usernames and passwords on browsers and apps. This reduces the risk of someone else accessing your login credentials.&lt;br&gt;
Review downloaded permissions: When downloading a new app, scrutinize the permissions it requests. Only grant access to features the app genuinely needs to function.&lt;br&gt;
By understanding the risks and adopting responsible practices, we can transform our mobile devices from potential vulnerabilities into secure fortresses in the digital age.&lt;/p&gt;

</description>
      <category>infosec</category>
      <category>privacy</category>
      <category>socialengineering</category>
      <category>cyberattacks</category>
    </item>
    <item>
      <title>Transformation of Privacy in the Digital Age</title>
      <dc:creator>Zeki</dc:creator>
      <pubDate>Thu, 23 May 2024 11:17:33 +0000</pubDate>
      <link>https://dev.to/jusufoski/transformation-of-privacy-in-the-digital-age-1idf</link>
      <guid>https://dev.to/jusufoski/transformation-of-privacy-in-the-digital-age-1idf</guid>
      <description>&lt;p&gt;Privacy, once a concept centered around physical space and control over personal information, has undergone a dramatic transformation in the digital age.&lt;/p&gt;

&lt;p&gt;Historically, privacy was primarily concerned with protecting physical space and belongings. This included the right to be free from unwarranted physical intrusion, the ability to control who has access to our physical possessions, and the expectation of privacy in our homes and personal communications (like sealed letters).&lt;/p&gt;

&lt;p&gt;The digital age has revolutionized communication, access to information, and the way we conduct business and socialize.&lt;/p&gt;

&lt;p&gt;Yet, this interconnectedness comes at a cost — gradual chipping away of our privacy.&lt;/p&gt;

&lt;p&gt;Our personal data, from social media interactions to geolocation information, creates a digital footprint, and is constantly being collected, analyzed, and used in ways that were unimaginable in the pre-digital era.&lt;/p&gt;

&lt;p&gt;The digital age transforms our lives, improves our communication, accelerates technology development and has many other positive effects.&lt;/p&gt;

&lt;p&gt;All these positive effects taken into account, we need to strike a balance between privacy protection and technological advancements.&lt;/p&gt;

&lt;p&gt;This article delves into the intricate relationship between privacy and technology in the digital age, exploring the challenges we face, potential solutions, and the need for a nuanced approach to navigate this ever-evolving landscape.&lt;/p&gt;

&lt;h2&gt;
  
  
  Dataveillance
&lt;/h2&gt;

&lt;p&gt;Being a portmanteau of data and surveillance, dataveillance refers to the monitoring and collection of our personal data through our online activities and interactions. It’s essentially a form of surveillance that happens in the digital world, as opposed to traditional physical surveillance methods.&lt;/p&gt;

&lt;p&gt;Every online interaction we have — from browsing history to emails — leaves a digital trail. This data is collected by a vast network of actors, including social media giants, search engines, online retailers, and even governments.&lt;/p&gt;

&lt;p&gt;The lack of transparency surrounding these practices creates a pervasive sense of unease.&lt;/p&gt;

&lt;p&gt;Dataveillance can be useful for collecting and verifying data in ways that are beneficial. For instance, personal dataveillance can be utilized by financial institutions to track fraudulent purchases on credit card accounts&lt;/p&gt;

&lt;p&gt;While it offers potential benefits for personalization and analytics, it also raises significant concerns about privacy and security.&lt;/p&gt;

&lt;p&gt;By understanding how dataveillance works and the potential risks involved, we can make informed choices about our online activities and advocate for stronger data protection measures.&lt;/p&gt;

&lt;h2&gt;
  
  
  Commoditization of data
&lt;/h2&gt;

&lt;p&gt;A key component of the digital economy is the commoditization of data.&lt;/p&gt;

&lt;p&gt;A valuable asset that is bought and sold to produce targeted advertising revenue is personal information.&lt;/p&gt;

&lt;p&gt;Our personal data is being utilized to forecast and affect our desires, creating a culture of surveillance capitalism and a constant sense of being watched and monitored.&lt;/p&gt;

&lt;p&gt;We commonly refer to the continuous flow of data produced by our internet activities as “datafication.” This data can provide a comprehensive picture of our lives by containing anything from purchase records to location data.&lt;/p&gt;

&lt;p&gt;Companies and governments can now more easily than ever keep an eye on our online activities thanks to cookies, browser fingerprinting, and other tracking technology. This presents questions regarding the possibility of abuse and deception.&lt;/p&gt;

&lt;p&gt;Although data commodification has drawbacks, it might also have some advantages.&lt;/p&gt;

&lt;p&gt;Users can receive more relevant advertisements by using data. Businesses (reaching a better targeted audience) and consumers (seeing adverts for things they might actually be interested in) can both benefit from this.&lt;/p&gt;

&lt;p&gt;Online experiences can be made more personalized by using data, which can be used to customize search results, news feeds, and product recommendations on shopping websites. Online conversations may become more productive and pleasurable as a result.&lt;/p&gt;

&lt;p&gt;Innovation and the creation of new goods and services can result from data analysis. For instance, examining user data from fitness trackers might help develop more individualized workout regimens and wellness guidelines.&lt;/p&gt;

&lt;p&gt;Data can be used for research and development in various fields, leading to breakthroughs in healthcare, education, and other sectors.&lt;/p&gt;

&lt;h2&gt;
  
  
  Shifting Expectations
&lt;/h2&gt;

&lt;p&gt;Social media platforms and online services thrive on user data.&lt;/p&gt;

&lt;p&gt;While users often seek convenient and personalized online experiences, these conveniences often come at the cost of reduced privacy.&lt;/p&gt;

&lt;p&gt;Unfortunately, many platforms capitalize on a culture of oversharing, blurring the lines between public and private spheres. This makes it increasingly difficult for individuals to maintain a sense of personal privacy — especially for younger generations who have grown up in a hyper-connected world.&lt;/p&gt;

&lt;p&gt;In today’s digital world, having a strong online presence is often seen as advantageous. This can create pressure to curate a public persona and share personal information to build a following or establish credibility.&lt;/p&gt;

&lt;p&gt;In the digital realm, privacy encompasses a broad spectrum. It includes control over our personal information, the right to be forgotten, the ability to exist online anonymously, and the right to dictate how our online personas are portrayed.&lt;/p&gt;

&lt;p&gt;Constant surveillance and data collection can have a chilling effect on free speech and self-expression, as individuals fear judgment or ostracization for their online activities. Additionally, data breaches and identity theft pose a growing threat, exposing us to financial loss and emotional distress.&lt;/p&gt;

&lt;p&gt;While existing anonymously is seen as a fundamental human right, it can also pose significant dangers.&lt;/p&gt;

&lt;p&gt;Anonymity can embolden individuals to engage in cyberbullying, harassment, and online abuse. They may feel less accountable for their actions and be more likely to target others with offensive or threatening messages.&lt;/p&gt;

&lt;p&gt;It can make it easier to spread misinformation and hate speech online without facing consequences. It allows individuals to hide behind fake profiles, making it difficult to track down the source of the information.&lt;/p&gt;

&lt;p&gt;The ability to operate anonymously online can facilitate criminal activity such as online fraud, hacking, and identity theft. Criminals can hide their identities and evade detection more easily.&lt;/p&gt;

&lt;h2&gt;
  
  
  Taking control
&lt;/h2&gt;

&lt;p&gt;However, there is no need to resign ourselves to a dystopian future devoid of privacy. Fortunately, there are steps we can take to reclaim some control over our digital footprints.&lt;/p&gt;

&lt;p&gt;One approach is to be more mindful of the information we share online. This includes reviewing privacy settings on social media platforms and other online services, limiting what information is publicly visible, and using privacy-focused tools like browser extensions that block tracking cookies.&lt;/p&gt;

&lt;p&gt;Security hygiene is also crucial. We can protect ourselves by using strong, unique passwords and enabling two-factor authentication to add an extra layer of security to our accounts.&lt;/p&gt;

&lt;p&gt;Additionally, being cautious about what information we share on public Wi-Fi networks and refraining from downloading files from untrusted sources can significantly reduce our risk of exposure to malware or data breaches.&lt;/p&gt;

&lt;p&gt;Supporting legislation that promotes data privacy rights and empowers individuals to control their information is essential. The European Union’s General Data Protection Regulation (GDPR) is a prime example, granting individuals the right to access, rectify, or erase their personal data.&lt;/p&gt;

&lt;p&gt;Advocating for similar regulations in other parts of the world can provide users with a much-needed legal framework to protect their privacy in the digital age.&lt;/p&gt;

&lt;p&gt;Technology companies also have a responsibility to be more transparent about their data collection practices and provide users with meaningful control over their information.&lt;/p&gt;

&lt;p&gt;Privacy-focused features, such as the ability to easily delete data or opt out of targeted advertising, should be readily available and user-friendly. Additionally, investing in robust security measures and adhering to ethical data practices can build trust and foster a more responsible data ecosystem.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Future of Privacy
&lt;/h2&gt;

&lt;p&gt;Data protection regulations like the EU’s GDPR are a step towards empowering individuals to control their data. These regulations are likely to evolve and shape the way online platforms handle user privacy in the future.&lt;/p&gt;

&lt;p&gt;Technologies like blockchain and secure enclaves are being developed to give users more control over their data. These technologies have the potential to reshape the way personal information is stored and accessed in the digital world.&lt;/p&gt;

&lt;p&gt;The transformation of privacy in the digital age is an ongoing process. As technology continues to evolve, we need to find ways to balance innovation with the right to privacy. This requires collaboration between individuals, policymakers, and technology companies to create a digital ecosystem that respects our right to control our personal information.&lt;/p&gt;

&lt;p&gt;Finding a balance between innovation and privacy is critical.&lt;/p&gt;

&lt;p&gt;We must strive for a digital future where advancements in technology coexist with a healthy respect for personal privacy. This can be achieved through a multi-pronged approach involving individual vigilance, robust legal frameworks, and ethical corporate practices.&lt;/p&gt;

&lt;p&gt;Ultimately, safeguarding privacy in the digital age requires ongoing dialogue and collaboration between policymakers, technology companies, and users themselves.&lt;/p&gt;

&lt;p&gt;We must recognize that privacy is not a luxury, but a fundamental human right that needs to be protected in the digital realm.&lt;/p&gt;

</description>
      <category>infosec</category>
      <category>socialengineering</category>
      <category>cyberattacks</category>
      <category>privacy</category>
    </item>
    <item>
      <title>Understanding Java: Pass by Value vs. Pass by Reference</title>
      <dc:creator>Zeki</dc:creator>
      <pubDate>Sun, 19 May 2024 20:50:35 +0000</pubDate>
      <link>https://dev.to/jusufoski/understanding-java-pass-by-value-vs-pass-by-reference-20me</link>
      <guid>https://dev.to/jusufoski/understanding-java-pass-by-value-vs-pass-by-reference-20me</guid>
      <description>&lt;p&gt;In the realm of Java programming, the debate surrounding whether Java is pass-by-reference or pass-by-value often sparks confusion among developers.&lt;/p&gt;

&lt;p&gt;At first glance, it might seem straightforward, but delving deeper reveals nuances that can reshape one’s understanding of how Java handles data passing. In this article, we’ll unravel the intricacies of Java’s pass-by-reference and pass-by-value mechanisms, exploring what they mean, how they function in Java, and the implications they carry for writing robust and efficient code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Java Value Types
&lt;/h2&gt;

&lt;p&gt;Value types represent data that is stored directly in memory. When you declare a variable of a value type, the variable contains the actual data itself, not a reference to the data stored elsewhere in memory. Java’s primitive data types, such as int, double, char, boolean, etc., are examples of value types.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;value types are&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;Stored Directly: The actual value is stored directly in memory.&lt;br&gt;
Fast Access: Accessing and manipulating value types is typically faster because the data is stored inline with the variable.&lt;br&gt;
Immutable: Primitive types in Java are immutable, meaning their values cannot be changed once they are assigned.&lt;br&gt;
Pass by Value: When passed as arguments to methods, copies of the value are passed, rather than references.&lt;/p&gt;

&lt;h2&gt;
  
  
  Java Reference Types
&lt;/h2&gt;

&lt;p&gt;Reference types, on the other hand, represent data that is stored elsewhere in memory, and variables of reference types hold references (memory addresses) to that data. Reference types include objects, arrays, and instances of classes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Characteristics of Reference Types&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;Stored Indirectly: Variables store references to the data, not the data itself.&lt;br&gt;
Slower Access: Accessing and manipulating reference types typically involves an extra level of indirection, which can be slower than accessing value types directly.&lt;br&gt;
Mutable: Objects and arrays are mutable, meaning their contents can be changed after creation.&lt;br&gt;
Pass by Value (of Reference): When passed as arguments to methods, copies of the reference (memory address) are passed, not the actual object.&lt;br&gt;
Demystifying Pass-by-Value&lt;br&gt;
In Java, it’s important to understand that primitive types (such as int, double, char, etc.) are passed by value, meaning a copy of the value is passed to the method. However, when it comes to objects, what’s passed by value is the reference to the object, not the object itself.&lt;/p&gt;

&lt;p&gt;This can sometimes lead to confusion, as it might appear that objects are passed by reference. However, in reality, Java strictly passes references by value.&lt;/p&gt;

&lt;p&gt;Let’s start by clarifying the concept of pass-by-value. In Java, when you pass a variable to a method, you’re not passing the actual object itself.&lt;/p&gt;

&lt;p&gt;Instead, you’re passing a copy of the value of the variable. This means that any modifications made to the parameter inside the method do not affect the original variable outside the method’s scope.&lt;/p&gt;

&lt;p&gt;Consider the following snippet:&lt;/p&gt;

&lt;p&gt;`public class Main {&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public static void main(String[] args) {

    int x = 10;

    modifyValue(x);

    System.out.println(x); // Output: 10

}

public static void modifyValue(int num) {

    num = 20;

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}`&lt;/p&gt;

&lt;p&gt;In above example, even though the value of x is modified within the modifyValue method, it doesn’t alter the original value of x outside the method.&lt;/p&gt;

&lt;p&gt;This behavior exemplifies the pass-by-value nature of primitive types in Java.&lt;/p&gt;

&lt;p&gt;In the following example, a StringBuilder object sb is created in the main method and passed to the manipulateStringBuilder method.&lt;/p&gt;

&lt;p&gt;However, what’s passed to the method is the reference to the StringBuilder object, not the object itself.&lt;/p&gt;

&lt;p&gt;This reference is passed by value, meaning a copy of the reference is made and passed to the method. Inside the manipulateStringBuilder method, modifications are made to the same StringBuilder object that sb references, and these modifications are reflected outside the method.&lt;/p&gt;

&lt;p&gt;public class Main {&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public static void main(String[] args) {

    StringBuilder sb = new StringBuilder("Hello");

    manipulateStringBuilder(sb);

    System.out.println(sb); // Output: Hello World

}

public static void manipulateStringBuilder(StringBuilder builder) {

    builder.append(" World");

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;br&gt;
Above example demonstrates the pass-by-value nature of object references in Java.&lt;/p&gt;

&lt;p&gt;Navigating Pass-by-Reference Illusion&lt;br&gt;
Now, let’s address the common misconception of Java being pass-by-reference.&lt;/p&gt;

&lt;p&gt;While it’s true that when you pass an object to a method, you’re passing a reference to that object, it’s crucial to understand that this reference itself is passed by value.&lt;/p&gt;

&lt;p&gt;Consider the following scenario involving an object:&lt;/p&gt;

&lt;p&gt;public class Main {&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public static void main(String[] args) {

    StringBuilder sb = new StringBuilder("Hello");

    manipulateStringBuilder(sb);

    System.out.println(sb); // Output: Hello World

}

public static void manipulateStringBuilder(StringBuilder builder) {

    builder.append(" World");

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;br&gt;
Here, manipulateStringBuilder receives a copy of the reference to the StringBuilder object sb. Any modifications made to the object through this reference are reflected outside the method.&lt;/p&gt;

&lt;p&gt;However, if the method were to assign a new object to the parameter, it wouldn’t affect the original object.&lt;/p&gt;

&lt;p&gt;public class Main {&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public static void main(String[] args) {

    StringBuilder sb = new StringBuilder("Hello");

    manipulateStringBuilder(sb);

    System.out.println(sb); // Output: Hello

}

public static void manipulateStringBuilder(StringBuilder builder) {

    builder = new StringBuilder("New StringBuilder");

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;br&gt;
In this scenario, reassigning builder to a new StringBuilder object doesn’t alter the original object sb.&lt;/p&gt;

&lt;p&gt;This behavior aligns with Java’s pass-by-value principle, where only the value of the reference is copied and passed, not the object itself.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to Pass by Reference in Java?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you want to modify the reference itself, such as assigning a new object to it, you can’t achieve this using standard Java mechanisms.&lt;/p&gt;

&lt;p&gt;Java strictly passes references by value, so reassigning the reference inside a method does not affect the original reference outside the method.&lt;/p&gt;

&lt;p&gt;To achieve a behavior closer to pass by reference, you can wrap the object inside a container object (like an array or a single-element array) or use Java’s AtomicReference class.&lt;/p&gt;

&lt;p&gt;import java.util.concurrent.atomic.AtomicReference;&lt;/p&gt;

&lt;p&gt;public class Main {&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public static void main(String[] args) {

    AtomicReference&amp;lt;StringBuilder&amp;gt; atomicSb = new AtomicReference&amp;lt;&amp;gt;(new StringBuilder("Hello"));

    // Pass the AtomicReference to a method

    manipulateStringBuilder(atomicSb);

    // Get the modified StringBuilder

    StringBuilder sb = atomicSb.get();

    System.out.println(sb); // Output: Hello World

}

public static void manipulateStringBuilder(AtomicReference&amp;lt;StringBuilder&amp;gt; atomicSb) {

    // Retrieve the StringBuilder from the AtomicReference

    StringBuilder sb = atomicSb.get();

    // Modify the StringBuilder

    sb.append(" World");

    // Update the AtomicReference with the modified StringBuilder

    atomicSb.set(sb);

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;br&gt;
In the above example, an AtomicReference object atomicSb is created with an initial value of a StringBuilder containing “Hello”.&lt;/p&gt;

&lt;p&gt;The manipulateStringBuilder method is then called, passing atomicSb as an argument. Inside the method, the StringBuilder object is retrieved from the AtomicReference, modified by appending ” World” to it, and then set back into the AtomicReference.&lt;/p&gt;

&lt;p&gt;These approaches often introduce complexity and are not commonly used in everyday Java programming. In most cases, leveraging Java’s pass-by-value semantics and manipulating object state through references suffices for achieving the desired behavior.&lt;/p&gt;

&lt;p&gt;Implications for Java Development&lt;br&gt;
Understanding the nuances of pass-by-value and pass-by-reference in Java is crucial for writing efficient and bug-free code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Here are some implications to consider&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Immutable Objects&lt;/strong&gt;: Immutable objects, such as Strings, behave differently when passed to methods. Since their values cannot be changed, any modifications result in a new object being created. This behavior aligns perfectly with Java’s pass-by-value mechanism.&lt;br&gt;
&lt;strong&gt;Mutable Objects&lt;/strong&gt;: When dealing with mutable objects, developers must be mindful of unintended side effects. Since modifications to mutable objects within methods affect the original objects, it’s essential to document and manage such changes carefully to maintain code clarity and predictability.&lt;br&gt;
&lt;strong&gt;Performance Considerations&lt;/strong&gt;: Java’s pass-by-value approach can have performance implications, especially when dealing with large objects. Passing objects by value means that copies of the reference are made, but the underlying object remains unchanged. This can lead to increased memory consumption and potential performance overhead, particularly in scenarios involving frequent method calls with large objects.&lt;br&gt;
&lt;strong&gt;Functional Programming Paradigm&lt;/strong&gt;: In functional programming, immutability is a key concept. Java’s pass-by-value nature aligns well with this paradigm, as it discourages in-place modifications and encourages a more functional style of programming, where objects are treated as immutable entities.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In conclusion, while the debate over whether Java is pass-by-reference or pass-by-value may seem trivial at first, understanding the nuances of these mechanisms is crucial for writing robust and efficient code.&lt;/p&gt;

&lt;p&gt;Java’s pass-by-value approach, where copies of variable values are passed to methods, ensures predictability and clarity in code behavior.&lt;/p&gt;

&lt;p&gt;The reference nature of objects can sometimes lead to confusion, emphasizing the importance of grasping the distinction between passing by value and passing by reference. By embracing these concepts and their implications, developers can leverage Java’s strengths to write cleaner, more maintainable code that stands the test of time.&lt;/p&gt;

&lt;p&gt;What are your thoughts for this debate? you can write in the comments below.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Previously published &lt;a href="https://codeline24.com"&gt;On My Blog&lt;/a&gt; where you can find more articles about Java and Spring Framework&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;For more in-depth discussions follow me on: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.linkedin.com/in/zeki-jusufoski-bsc-5b525385/"&gt;LinkedIn&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://x.com/jzeki"&gt;Twitter/X&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>java</category>
    </item>
    <item>
      <title>Spring Security with Oauth 2.0</title>
      <dc:creator>Zeki</dc:creator>
      <pubDate>Wed, 15 May 2024 15:41:35 +0000</pubDate>
      <link>https://dev.to/jusufoski/spring-security-with-oauth-20-2782</link>
      <guid>https://dev.to/jusufoski/spring-security-with-oauth-20-2782</guid>
      <description>&lt;p&gt;Spring Security, a popular security framework for Java applications, integrates seamlessly with OAuth 2.0, an industry-standard authorization protocol. This combination empowers developers to implement secure and user-friendly login experiences in their web applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Oauth 2.0?
&lt;/h2&gt;

&lt;p&gt;OAuth 2.0 is an authorization framework that enables third-party applications to access a user’s resources without divulging the user’s credentials.&lt;/p&gt;

&lt;p&gt;It provides a standardized way for users to grant limited access to their resources stored on one site (the resource server) to another site (the client application), without sharing their credentials.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr5dm558pkfefynk90bx6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr5dm558pkfefynk90bx6.png" alt="Image description" width="769" height="165"&gt;&lt;/a&gt;&lt;br&gt;
OAuth 2.0 works by facilitating the exchange of tokens between the client application, the resource server, and an authorization server.&lt;/p&gt;

&lt;p&gt;The main components of OAuth 2.0 are:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Resource Owner&lt;/strong&gt;: The user who owns the resources being accessed. For example, a user’s photos on a photo-sharing website.&lt;br&gt;
&lt;strong&gt;Client&lt;/strong&gt;: The application that wants to access the user’s resources. This could be a web application, mobile app, or desktop application.&lt;br&gt;
&lt;strong&gt;Resource Server&lt;/strong&gt;: The server hosting the user’s resources. It verifies and provides access to the requested resources based on the tokens provided by the client.&lt;br&gt;
&lt;strong&gt;Authorization Server&lt;/strong&gt;: The server responsible for authenticating the user and issuing access tokens to the client after the user grants consent.&lt;br&gt;
OAuth 2.0 operates using different grant types(permissions), each suited for specific use cases, including:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Authorization Code Grant&lt;/strong&gt;: Suitable for web applications where the client can securely store a client secret.&lt;br&gt;
&lt;strong&gt;Implicit Grant&lt;/strong&gt;: Designed for client-side applications, such as JavaScript apps running in a web browser.&lt;br&gt;
&lt;strong&gt;Client Credentials Grant&lt;/strong&gt;: Used when the client application is the resource owner and doesn’t need user consent.&lt;br&gt;
&lt;strong&gt;Resource Owner Password Credentials Grant&lt;/strong&gt;: Allows the client to authenticate with the resource owner’s credentials directly.&lt;br&gt;
OAuth 2.0 is widely adopted across various platforms and services, including social media platforms, cloud services, and APIs, enabling secure and controlled access to user data while maintaining user privacy and security.&lt;/p&gt;

&lt;h2&gt;
  
  
  Oauth 2.0 Practical Example
&lt;/h2&gt;

&lt;p&gt;Imagine you’re building a fitness app that wants to access a user’s workout data stored on a separate fitness tracker platform.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv6di6bttgnmqaghwp8iz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv6di6bttgnmqaghwp8iz.png" alt="Image description" width="721" height="399"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;User Initiates Login&lt;/strong&gt;: The user wants to connect your fitness app to their fitness tracker account. They click a “Connect with Fitness Tracker” button within your app.&lt;br&gt;
&lt;strong&gt;Authorization Request&lt;/strong&gt;: The authorization server displays a login page to the user. Once the user logs in successfully, the server presents a consent screen asking the user if they want to grant your app access to their workout data.&lt;br&gt;
&lt;strong&gt;User Grants Consent&lt;/strong&gt;: If the user agrees, they click “Allow” on the consent screen. This indicates their approval for your app to access their data.&lt;br&gt;
&lt;strong&gt;Authorization Code Issued&lt;/strong&gt;: Upon user consent, the authorization server generates a unique authorization code and redirects the user’s browser back to your app. This code is like a temporary key that your app can exchange for an access token.&lt;br&gt;
&lt;strong&gt;Token Request to Token Endpoint&lt;/strong&gt;: Your app sends a request to the fitness tracker platform’s token endpoint.&lt;br&gt;
&lt;strong&gt;Access Token Granted&lt;/strong&gt;: The token endpoint verifies the authorization code and your app’s credentials. If everything is valid, it generates an access token and (optionally) a refresh token and sends them back to your app.&lt;br&gt;
&lt;strong&gt;Request Resources&lt;/strong&gt;: Your app stores the access token securely and uses it to make API calls to the fitness tracker platform to retrieve the user’s workout data.&lt;br&gt;
Token Validated: Resource Server validate access token again Auth. Server.&lt;br&gt;
&lt;strong&gt;Resources Returned&lt;/strong&gt;: With the access token, your app can now access the user’s workout data from the fitness tracker platform and display it within your app.&lt;/p&gt;

&lt;h2&gt;
  
  
  Spring Security
&lt;/h2&gt;

&lt;p&gt;Spring Security is a powerful and customizable authentication and access control framework for Java applications, particularly those built using the Spring Framework.&lt;/p&gt;

&lt;p&gt;It provides comprehensive security features to address authentication, authorization, session management, and protection against common security threats.&lt;/p&gt;

&lt;p&gt;The main requirement to run Spring Security is a &lt;strong&gt;Java 8 or higher Runtime Environment (JRE)&lt;/strong&gt;. Spring Security is designed to be self-contained within your application, so you don’t need any additional configuration on the JRE itself.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1wgnx7a52495i8hrcb1c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1wgnx7a52495i8hrcb1c.png" alt="Image description" width="731" height="176"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Spring Security utilizes a &lt;strong&gt;filter chain&lt;/strong&gt;, a series of filters, to intercept and process incoming HTTP requests in a web application.&lt;/p&gt;

&lt;p&gt;This chain acts like a security assembly line, with each filter performing a specific task related to authentication and authorization.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;AuthenticationManager&lt;/strong&gt; serves as the heart of authentication in Spring Security. It acts as a central coordinator, delegating the verification process to specific providers while maintaining a clean separation of concerns. This approach offers flexibility and simplifies managing authentication logic within your secure Spring applications.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;UserDetailsService&lt;/strong&gt; is a core interface that acts as the bridge between your application and the source of user authentication information. It’s responsible for loading a user’s details (username, password, authorities) when presented with a username during the authentication process&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Spring Security Context&lt;/strong&gt;, in the context of Spring Security, is a fundamental component that holds information about the currently authenticated user. It acts like a temporary storage unit for security details specific to the current thread or request.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Authentication&lt;/strong&gt;&lt;br&gt;
Spring Security provides comprehensive support for authentication. Authentication refers to the process of verifying someone’s claimed identity. Spring Security offers robust support for various authentication mechanisms, including form-based authentication, HTTP basic authentication, OAuth, OpenID, and more.&lt;/p&gt;

&lt;p&gt;It integrates seamlessly with user databases, LDAP servers, and third-party authentication providers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Authorization&lt;/strong&gt;&lt;br&gt;
Spring Security provides comprehensive support for authorization. Authorization is determining who is allowed to access a particular resource. With Spring Security, you can define fine-grained access control rules to restrict or permit access to different parts of your application based on roles, privileges, or other criteria.&lt;/p&gt;

&lt;p&gt;It supports role-based access control (RBAC), expression-based access control, and method-level security.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Session Management&lt;/strong&gt;&lt;br&gt;
Spring Security provides features for managing user sessions securely, including session fixation protection, session concurrency control, and session timeout handling. It ensures that sessions are managed securely to prevent session-related attacks.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Security Threats Protection&lt;/strong&gt;&lt;br&gt;
Spring Security includes built-in protection against common security vulnerabilities, such as cross-site request forgery (CSRF), cross-site scripting (XSS), clickjacking, and session fixation attacks. It helps developers build applications that are resilient to security threats.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Spring Framework Integration&lt;/strong&gt;&lt;br&gt;
Spring Security seamlessly integrates with other components of the Spring ecosystem, such as Spring MVC, Spring Boot, and Spring Data. This integration simplifies the implementation of security features and enables developers to leverage the power of both Spring Security and other Spring modules.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Customization&lt;/strong&gt;&lt;br&gt;
Spring Security is highly customizable and extensible, allowing developers to tailor security configurations to meet the specific requirements of their applications. It provides extension points for integrating custom authentication providers, access decision voters, and security filters.&lt;/p&gt;

&lt;p&gt;Overall, Spring Security is a comprehensive and flexible security framework that empowers developers to build secure, resilient, and compliant Java applications with ease. Whether you’re developing a web application, a RESTful API, or a microservices architecture, Spring Security provides the necessary tools and capabilities to ensure the security of your application and protect your users’ data.&lt;/p&gt;

&lt;h2&gt;
  
  
  Spring Boot Oauth 2.0 Google Login
&lt;/h2&gt;

&lt;p&gt;In this section, we’ll create a minimal application that uses Google for authentication. Spring Boot’s auto configuration capabilities significantly simplify this step.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Setup the Project&lt;/strong&gt;&lt;br&gt;
Visit &lt;a href="https://start.spring.io/"&gt;start.spring.io&lt;/a&gt; to create a new Spring Boot project.&lt;br&gt;
Select Maven as your build tool and Java as your language.&lt;br&gt;
Name your project, like Google Login.&lt;br&gt;
Choose JDK 21 (or the latest available).&lt;br&gt;
Add dependencies: web and oauth2-client. Spring Security will be added as a transitive dependency.&lt;br&gt;
Generate and download the project. This will provide a zip file.&lt;br&gt;
To make the application secure, you can simply add Spring Security as a dependency. Since you’re wanting to do a “social” login (delegate to Google), you include the Spring Security OAuth 2.0 Client starter.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Create google oauth credentials&lt;/strong&gt;&lt;br&gt;
Firstly, follow this &lt;a href="https://support.google.com/cloud/answer/6158849?hl=en"&gt;Google Help&lt;/a&gt; to create Google OAuth Client ID in order to get the access keys of Google single sign on API (Client ID and Client Secret).&lt;/p&gt;

&lt;p&gt;Provide a descriptive name and a brief explanation of what your app does.&lt;/p&gt;

&lt;p&gt;Enter the URL of your application’s main page (e.g., &lt;a href="http://localhost:8080"&gt;http://localhost:8080&lt;/a&gt; in this example).&lt;/p&gt;

&lt;p&gt;Redirect URL is where users will be redirected after logging in with Google. Enter the specific path for your application’s login callback, for example, &lt;a href="http://localhost:8080/login/oauth2/code/google"&gt;http://localhost:8080/login/oauth2/code/google&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This URL is a handshake between your app and Google. After users log in with Google credentials, they’ll be sent back to this specific URL within your application to confirm their login and grant access.&lt;/p&gt;

&lt;p&gt;Then, to make the link to Google, add the following to your application.yml:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;spring:&lt;br&gt;
  security:&lt;br&gt;
    oauth2:&lt;br&gt;
      client:&lt;br&gt;
        registration:&lt;br&gt;
         google:&lt;br&gt;
          clientId: google-client-id&lt;br&gt;
          clientSecret: google-client-secret&lt;br&gt;
          scope:&lt;br&gt;
           - email&lt;br&gt;
           - profile&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Simply use the OAuth 2.0 credentials you created in previous step, replacing google-client-id with the client id and google-client-secret with the client secret.&lt;/p&gt;

&lt;p&gt;Save the changes you made to your app and restart your application.&lt;/p&gt;

&lt;p&gt;Now, when you visit your app’s home page at &lt;a href="http://localhost:8080"&gt;http://localhost:8080&lt;/a&gt;, you should see a login screen for Google account.&lt;/p&gt;

&lt;p&gt;Go through the Google login process, granting any permissions your app needs.&lt;/p&gt;

&lt;p&gt;After successfully logging in, you’ll be automatically directed back to your app’s home page, and you should be logged in!&lt;/p&gt;

&lt;h2&gt;
  
  
  How Does it Work?
&lt;/h2&gt;

&lt;p&gt;Following the OAuth 2.0 standard, your app functions as a &lt;strong&gt;client application&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;It uses the “authorization code grant” flow to obtain an access token from Google Console, which acts as the &lt;strong&gt;authorization server&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Once you’ve logged in with Google account, your app receives a special &lt;strong&gt;access token&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;This access token facilitates secure communication between your app and Google Console, acting also as a &lt;strong&gt;resource server&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The app can then use the token to request specific user information authorized during the login process. It can only access the specific details you approved during login, such as your email and profile.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Spring Security OAuth2.0 empowers developers to implement secure and user-friendly login experiences in their applications.&lt;/p&gt;

&lt;p&gt;It leverages the OAuth2.0 standard, enabling users to sign in with existing credentials from various providers like Google, GitHub, or Facebook. This not only simplifies the login process but also eliminates the need to manage user passwords within your application, enhancing overall security.&lt;/p&gt;

&lt;p&gt;OAuth2.0’s token-based approach facilitates secure access control between different microservices. Secure communication and authorization between microservices within a larger application.&lt;/p&gt;

&lt;p&gt;An OAuth2-based microservices architecture can be structured with a single client application for user interaction.&lt;/p&gt;

&lt;p&gt;This client communicates with multiple backend resource servers offering RESTful APIs. A separate authorization server, managed by a third party, handles user authentication and authorization for secure access to resources.&lt;/p&gt;

&lt;p&gt;Furthermore, Spring Boot’s autoconfiguration features make setting up Spring Security OAuth2.0 a breeze. Developers can focus on core application functionalities, while the framework handles the complexities of OAuth2.0 communication.&lt;/p&gt;

&lt;p&gt;In conclusion, Spring Security OAuth2.0 offers a compelling solution for integrating secure and efficient user login into your web applications.&lt;/p&gt;

&lt;p&gt;It simplifies the process, strengthens security, and provides a flexible solution for a variety of authentication providers.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Previously published &lt;a href="https://codeline24.com"&gt;On My Blog&lt;/a&gt; where you can find more articles about Java and Spring Framework&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;For more in-depth discussions follow me on: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.linkedin.com/in/zeki-jusufoski-bsc-5b525385/"&gt;LinkedIn&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://x.com/jzeki"&gt;Twitter/X&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>springboot</category>
      <category>springsecurity</category>
      <category>programming</category>
      <category>oauth</category>
    </item>
    <item>
      <title>Java vs. Kotlin – A Guide for Modern Developers</title>
      <dc:creator>Zeki</dc:creator>
      <pubDate>Mon, 13 May 2024 10:46:59 +0000</pubDate>
      <link>https://dev.to/jusufoski/enrich-your-toolset-java-vs-kotlin-a-guide-for-modern-developers-2p4d</link>
      <guid>https://dev.to/jusufoski/enrich-your-toolset-java-vs-kotlin-a-guide-for-modern-developers-2p4d</guid>
      <description>&lt;p&gt;&lt;strong&gt;Debate&lt;/strong&gt;&lt;br&gt;
In the world of Android development, a heated debate often arises: Java vs. Kotlin.&lt;/p&gt;

&lt;p&gt;While both languages compile to run on the Java Virtual Machine, their strengths differ. Choosing between Java and Kotlin hinges on your project’s needs.&lt;/p&gt;

&lt;p&gt;Java, the long-standing champion, boasts an extensive library collection and mature ecosystem. Kotlin, the energetic challenger, brings a modern twist with its concise syntax and focus on developer experience.&lt;/p&gt;

&lt;p&gt;This article explores the advantages and disadvantages of different programming languages to help you choose the best fit&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;History of Kotlin&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In 2010, JetBrains, a software development company known for creating IntelliJ IDEA, started developing Kotlin under the name Project Kotlin.&lt;/p&gt;

&lt;p&gt;Kotlin aimed to be easier to write and read than Java while integrate seamlessly with existing Java projects.&lt;/p&gt;

&lt;p&gt;In February 2012, JetBrains open-sourced Kotlin under the Apache 2 license, allowing for wider community involvement and development.&lt;/p&gt;

&lt;p&gt;Early on, Kotlin started gaining traction among developers who appreciated its concise syntax, null safety features, and interoperability with Java.&lt;/p&gt;

&lt;p&gt;The first official stable release of Kotlin arrived in February 2016(Kotlin 1.0). This marked a significant milestone and ensured backwards compatibility for future versions.&lt;/p&gt;

&lt;p&gt;In 2017, Google announced Kotlin as a first-class language for Android app development alongside Java. This significantly boosted Kotlin’s adoption within the Android development community.&lt;/p&gt;

&lt;p&gt;Since then, Kotlin has seen continuous growth in popularity across various development domains beyond Android, including web development, server-side development, and data analysis.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Kotlin’s Syntax&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Kotlin’s “static sugar” refers to features in the language that make code more concise, readable, and easier to maintain, without fundamentally changing its functionality. These features don’t alter the underlying behavior of the program but improve the developer experience by reducing boilerplate code and making the logic more explicit.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Type Inference&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Type mismatches can lead to runtime errors that can be challenging to identify and fix. Type inference helps catch these errors early in the development process, during compilation. This improves code quality and prevents potential issues in production environments.&lt;/p&gt;

&lt;p&gt;While both Java and Kotlin offer some level of type inference, Kotlin’s type inference is generally considered more powerful and flexible. &lt;/p&gt;

&lt;p&gt;When variable and expression types are explicit in the code, it becomes easier for developers to understand the purpose of each piece of code and make modifications when needed&lt;/p&gt;

&lt;p&gt;Kotlin can often infer the data type of a variable based on its initialization value. This eliminates the need for explicit type declarations in many cases, making code less verbose.&lt;/p&gt;

&lt;p&gt;Java’s type inference is primarily limited to local variable declarations where the compiler can determine the type based on the assigned value.&lt;/p&gt;

&lt;p&gt;Kotlin uses type inference extensively for various scenarios, including local variables, function return types, complex expressions, collections, and even lambdas.&lt;/p&gt;

&lt;p&gt;Let’s take an example of Kotlins when{} block is essentially an advanced form of the switch-case statement known from Java.&lt;/p&gt;

&lt;p&gt;val grade = when (score) {&lt;/p&gt;

&lt;p&gt;in 90..100 -&amp;gt; "A"&lt;/p&gt;

&lt;p&gt;in 80..89 -&amp;gt; "B"&lt;/p&gt;

&lt;p&gt;else -&amp;gt; "C"&lt;/p&gt;

&lt;p&gt;}&lt;br&gt;
Type is inferred as String based on the possible outcomes within the when expression (all String literals).&lt;/p&gt;

&lt;p&gt;Lambda Expressions with Collections:&lt;/p&gt;

&lt;p&gt;val numbers = listOf(1, 2, 3, 4, 5)&lt;/p&gt;

&lt;p&gt;val doubledNumbers = numbers.map { number -&amp;gt; number * 2 }&lt;br&gt;
Type inference considers the lambda parameter (number) as Int and the return value as the result of the multiplication (also Int)&lt;/p&gt;

&lt;p&gt;val evenNumbers = numbers.filter { it % 2 == 0 }&lt;br&gt;
Type inference considers the lambda parameter (it) as Int based on the collection content (numbers) and the operation involving Ints&lt;/p&gt;

&lt;p&gt;In these examples, the compiler analyzes the entire expression, including nested structures and conditional logic, to infer the most appropriate type for the final result. This allows for concise and expressive code without the need for explicit type declarations in many cases.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Default Parameters&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Kotlin allows functions to have default parameter values. This reduces the need for extensive conditional checks within functions to handle cases where specific parameters might be omitted during the call.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;p&gt;fun greet(name: String, title: String = "Mr./Ms.") {&lt;/p&gt;

&lt;p&gt;println("Hello, $title $name!")&lt;/p&gt;

&lt;p&gt;}&lt;br&gt;
&lt;strong&gt;Null Safety&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Kotlin enforces null safety by design. This means variables must be explicitly declared as nullable if they might hold no value. This eliminates the need for frequent null checks and conditional statements typically used in Java to avoid null pointer exceptions. &lt;/p&gt;

&lt;p&gt;Java does offer Optional as a way to handle null values, but it’s not quite the same as Kotlin’s enforced null safety. &lt;/p&gt;

&lt;p&gt;While Optional helps manage null values, it requires developers to explicitly handle the empty state using methods like isPresent() and get(). This can add boilerplate code and still requires checking for null within these methods.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;p&gt;Java (using Optional)&lt;/p&gt;

&lt;p&gt;Optional name = getCustomerName();&lt;/p&gt;

&lt;p&gt;if (name.isPresent()) {&lt;/p&gt;

&lt;p&gt;System.out.println("Hello, " + name.get() + "!");&lt;/p&gt;

&lt;p&gt;} else {&lt;/p&gt;

&lt;p&gt;System.out.println("Customer name is unknown.");&lt;/p&gt;

&lt;p&gt;}&lt;br&gt;
Kotlin Only executes if name is not null &lt;/p&gt;

&lt;p&gt;val name: String? = getCustomerName()&lt;/p&gt;

&lt;p&gt;name?.let { println("Hello, $it!") }&lt;br&gt;
Data Classes&lt;/p&gt;

&lt;p&gt;Data classes in Kotlin are a special type of class designed to hold data and provide a concise way to represent them. They are particularly useful for situations where you need to create classes that primarily focus on storing and manipulating data. Here are some key characteristics of data classes in Kotlin:&lt;/p&gt;

&lt;p&gt;When you define a data class, the Kotlin compiler automatically generates several methods for you, eliminating the need to write them yourself&lt;/p&gt;

&lt;p&gt;These methods include:&lt;/p&gt;

&lt;p&gt;toString(): Returns a human-readable string representation of the object, including its class name and property values.&lt;br&gt;
equals(): Compares two objects for equality based on their property values.&lt;br&gt;
hashCode(): Generates a hash code for the object, which is useful for storing data in collections that use hash-based algorithms.&lt;br&gt;
copy(): Creates a new copy of the object with potentially modified properties.&lt;br&gt;
Data classes are declared using the data keyword followed by the class name and its properties within curly braces.&lt;/p&gt;

&lt;p&gt;data class Person(val name: String, val age: Int)&lt;br&gt;
Java records (introduced in Java 16) offer a way to define classes that primarily focus on holding data. But there are differences:&lt;/p&gt;

&lt;p&gt;Kotlin Data Classes: Mutable by default, but can be made immutable by declaring properties as val (read-only) or using copy constructors.&lt;br&gt;
Java Records: All fields are final and immutable by design.&lt;br&gt;
Kotlin Data Classes: Enforces null safety by design. Variables must be explicitly declared as nullable (String?) if they might hold no value.&lt;br&gt;
Java Records: No built-in null safety. Variables can be null without explicit declaration.&lt;br&gt;
Kotlin Data Classes: Allow defining default values for properties within the class constructor.&lt;br&gt;
Java Records: Don’t support default parameter values.&lt;br&gt;
Modern Features&lt;/p&gt;

&lt;p&gt;Kotlin extension functions are a powerful feature that allows you to add new functionality to existing classes without modifying the original class itself. &lt;/p&gt;

&lt;p&gt;You can extend functionality without altering the original class definition, which is beneficial for working with third-party libraries or frameworks.&lt;/p&gt;

&lt;p&gt;fun String.reversed(): String {&lt;/p&gt;

&lt;p&gt;return this.reversed()  // Using the built-in reversed function on the String receiver&lt;/p&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;val message = "Hello, world!"&lt;/p&gt;

&lt;p&gt;val reversedMessage = message.reversed()&lt;/p&gt;

&lt;p&gt;println(reversedMessage)  // Output: !dlrow ,olleH&lt;br&gt;
Kotlin extension functions are a versatile tool for extending the capabilities of existing classes and promoting clean, maintainable, and expressive code.&lt;/p&gt;

&lt;p&gt;Kotlin lambdas, also known as anonymous functions, are a powerful feature that allows you to define concise blocks of code that can be passed around like values. &lt;/p&gt;

&lt;p&gt;While both Java and Kotlin support lambdas, Kotlin lambdas offer a more concise, readable, and potentially more powerful approach due to their additional features.&lt;/p&gt;

&lt;p&gt;Here are some key characteristics of Kotlin lambdas:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Improved Code Readability: Lambdas can make code more concise and readable, especially when dealing with short, well-defined functions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Higher-Order Functions: Kotlin allows functions to take other functions as arguments (higher-order functions). Lambdas are perfect for implementing this concept and expressing logic in a more functional style.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Collections and Iterations: Lambdas are heavily used with collections in Kotlin for filtering, mapping, and other operations. They provide a clean way to define the logic for these operations within the context of the collection.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Receiver functions: Can directly access the object they’re operating on.&lt;br&gt;
Example:&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;val sum = { x: Int, y: Int -&amp;gt; x + y }  // Lambda with two arguments and a return statement&lt;/p&gt;

&lt;p&gt;val result = sum(5, 3)  // Calling the lambda and passing arguments&lt;/p&gt;

&lt;p&gt;println(result)  // Output: 8&lt;br&gt;
Java does offer lambdas (anonymous functions), but there are some key differences in their syntax, features, and usage:&lt;/p&gt;

&lt;p&gt;A lambda with a receiver function is similar to a regular lambda, but with an additional object specified before the curly braces using an arrow -&amp;gt;. This object becomes the receiver for the lambda body.&lt;/p&gt;

&lt;p&gt;Kotlin&lt;/p&gt;

&lt;p&gt;objectName.methodName { receiver -&amp;gt;&lt;/p&gt;

&lt;p&gt;// Lambda body with access to "receiver"&lt;/p&gt;

&lt;p&gt;}&lt;br&gt;
In contrast, Java lambdas don’t have built-in receiver support. &lt;/p&gt;

&lt;p&gt;You might need to pass the object as an argument explicitly within the lambda, making the code less concise and potentially less readable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Kotlin offers a more concise syntax compared to Java. This means you can write the same functionality with fewer lines of code in Kotlin, making it easier to read and maintain.&lt;/p&gt;

&lt;p&gt;Java is notorious for NullPointerException errors, which can cause crashes. Kotlin enforces null safety at compile time, preventing these errors and making your code more robust.&lt;/p&gt;

&lt;p&gt;Kotlin code can seamlessly integrate with existing Java code, making it easy to adopt Kotlin gradually within a project.&lt;/p&gt;

&lt;p&gt;On the other side, if you’re working on a massive Java codebase, transitioning entirely to Kotlin might be a significant undertaking. &lt;/p&gt;

&lt;p&gt;Java’s maturity and vast ecosystem of libraries and frameworks can be advantageous in such cases.Overall, both Java and Kotlin are powerful languages. The choice between them depends on your specific project requirements, team expertise, and desired level of code conciseness and safety features.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Previously published &lt;a href="https://codeline24.com"&gt;On My Blog&lt;/a&gt; where you can find more articles about Java and Spring Framework&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;For more in-depth discussions follow me on: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.linkedin.com/in/zeki-jusufoski-bsc-5b525385/"&gt;LinkedIn&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://x.com/jzeki"&gt;Twitter/X&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>java</category>
      <category>kotlin</category>
      <category>programming</category>
    </item>
    <item>
      <title>Java 21: Path to Generational ZGC</title>
      <dc:creator>Zeki</dc:creator>
      <pubDate>Thu, 09 May 2024 09:51:13 +0000</pubDate>
      <link>https://dev.to/jusufoski/java-21-path-to-generational-zgc-2bj</link>
      <guid>https://dev.to/jusufoski/java-21-path-to-generational-zgc-2bj</guid>
      <description>&lt;p&gt;ZGC, or the Z Garbage Collector, is a relatively new option in the world of Java garbage collection.&lt;/p&gt;

&lt;p&gt;The garbage collector (GC) cleans up unused objects, freeing up memory for new ones. But just keeping track of free space isn’t enough. Over time, memory becomes fragmented (scattered) as objects are created and deleted. To prevent this, the JVM might also compact memory, rearranging things to create larger contiguous blocks of free space for future allocations.&lt;/p&gt;

&lt;p&gt;While the details can get technical, garbage collection (GC) boils down to three key tasks: finding unused objects, freeing their memory, and organizing that free memory. &lt;/p&gt;

&lt;p&gt;Different GC algorithms handle these tasks in unique ways, especially when it comes to organizing memory. Some wait until absolutely necessary to reorganize, while others tackle it in larger chunks or by moving small bits at a time. These different approaches are what make some GC algorithms faster or slower for specific situations.&lt;/p&gt;

&lt;p&gt;One tricky aspect of GC is that sometimes it needs to move objects around in memory. This can be a problem because if an application thread is trying to use an object at the same time it’s being moved, things can go wrong. To prevent this, GC pauses all application threads for a short moment while it relocates objects. &lt;/p&gt;

&lt;p&gt;This is known as stop-the-world pauses.&lt;/p&gt;

&lt;p&gt;Most garbage collectors organize memory in a similar way, even though the specifics might vary slightly. &lt;/p&gt;

&lt;p&gt;They typically split the memory area used by objects (called the heap) into different sections based on how long objects have typically lived. These sections are called generations.These are called the old (or tenured) generation and the young generation. The young generation is further divided into sections known as eden and the survivor spaces The rationale for having separate generations is that many objects are used for a very short period of time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The CMS collector&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The CMS collector was the first concurrent collector. Like other algorithms, CMS stops all application threads during a minor GC, which it performs with multiple Threads.&lt;/p&gt;

&lt;p&gt;The Concurrent Mark Sweep (CMS) collector (also referred to as the concurrent low pause collector) collects the tenured generation. It attempts to minimize the pauses due to garbage collection by doing most of the garbage collection work concurrently with the application threads. Normally the concurrent low pause collector does not copy or compact  the live objects. A garbage collection is done without moving the live objects. If fragmentation becomes a problem, we need to allocate a larger heap.&lt;/p&gt;

&lt;p&gt;It aimed to minimize pauses during garbage collection cycles, making it suitable for applications that require low latency (minimal lag or delay). Instead of stopping all application threads CMS attempted to run concurrently with application threads. It identified unused objects (marking) while the application continued to run. Later, in a separate stop-the-world pause (sweeping), it reclaimed the memory occupied by those unused objects.&lt;/p&gt;

&lt;p&gt;One of the limitations of CMS was so called “floating garbage”, namely, marking and sweeping happened at different times, some objects might become unreachable during the application’s execution but still be marked as reachable during the initial marking phase, which weren’t reclaimed until the next collection cycle.&lt;/p&gt;

&lt;p&gt;In addition to this, running garbage collection concurrently with application threads could consume more processing power.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Garbage First(G1) Garbage Collector&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;G1 GC, or Garbage-First Garbage Collector, is a relatively new type of garbage collector introduced in Java 7 Update 4 and became the default collector in Java 9. It’s designed to address some limitations of previous collectors and offer several advantages:&lt;/p&gt;

&lt;p&gt;The memory area used by objects (called the heap) is divided into smaller regions. Each region can be part of the young generation (for new objects) or the old generation (for long-lived objects).&lt;/p&gt;

&lt;p&gt;G1 prioritizes collecting regions in the young generation first, as they tend to have more garbage. However, it can also collect parts of the old generation if necessary. This allows G1 to focus on collecting only the regions that are most likely to contain garbage, improving efficiency.&lt;/p&gt;

&lt;p&gt;While G1 primarily works concurrently with application threads (meaning it can run garbage collection tasks while your program is still running), it might use brief stop-the-world pauses in specific situations. These pauses are typically much shorter than with older collectors.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Z Garbage Collector&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;ZGC, or Z Garbage Collector, is a relatively new and experimental collector introduced in Java 11 (JEP 333), as an optional feature. It became production-ready in Java 15 and boasts some impressive capabilities:&lt;/p&gt;

&lt;p&gt;ZGC is built for applications that need lightning-fast performance. It keeps pauses below 10 milliseconds and can handle massive amounts of memory, making it ideal for real-time systems and big data processing.&lt;/p&gt;

&lt;p&gt;ZGC is not the default collector in Java and needs to be explicitly enabled (-XX:+UseZGC.). The most important tuning option for ZGC is setting the max heap size (-Xmx)&lt;/p&gt;

&lt;p&gt;ZGC generally performs better with more memory. However, it’s important to strike a balance and avoid wasting resources.&lt;/p&gt;

&lt;p&gt;Beyond setting the memory size, ZGC gives you some control over its cleaning process. You can adjust the number of concurrent garbage collection threads (using the -XX:ConcGCThreads option) to potentially fine-tune performance.&lt;/p&gt;

&lt;p&gt;You can adjust how much processing power the GC uses. Too much CPU time for the GC can slow down your application, while too little can lead to a buildup of unused data. It’s about finding the right balance.&lt;/p&gt;

&lt;p&gt;With Java 21, it has evolved into a generational GC (JEP 439).&lt;/p&gt;

&lt;p&gt;To use GenZGC requires passing two VM arguments&lt;/p&gt;

&lt;p&gt;-XX:+UseZGC -XX:+ZGenerational&lt;/p&gt;

&lt;p&gt;The Generational ZGC aims to improve application performance, extending the existing ZGC by maintaining separate generations for young and old objects.&lt;/p&gt;

&lt;p&gt;The goal is to add these benefits on top of what the non-generational approach already offers: lightning-fast pauses (less than a millisecond!), support for incredibly large heaps (think terabytes!), and minimal setup required.&lt;/p&gt;

&lt;p&gt;Important design concepts that distinguish Generational ZGC from non-generational ZGC, and from other garbage collectors:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;No multi-mapped memory&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Classic ZGC employs a technique called multi-mapping where multiple virtual memory ranges map to the same physical memory range.&lt;/p&gt;

&lt;p&gt;Generational ZGC relied on a traditional approach where each virtual memory range in the heap had a one-to-one correspondence with a physical memory range.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Optimized barriers&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Store barriers are a fundamental concept in garbage collection (GC). They are small pieces of code inserted by the compiler or the runtime system during program execution. Their purpose is to ensure that the garbage collector has a consistent view of the memory used by your program’s objects.&lt;/p&gt;

&lt;p&gt;Generational ZGC (ZGC) employs several techniques to optimize store barriers, aiming to minimize their performance impact while maintaining accurate garbage collection. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Double-buffered remembered sets&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Double-buffered remembered sets are a specific optimization technique used in garbage collection, particularly within Z Garbage Collector (ZGC) introduced in Java. They play a crucial role in efficiently tracking references between generations of objects and minimizing the overhead associated with store barriers.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Relocations without additional heap memory&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This refers to a technique that allows the GC to move (or relocate) objects within the existing heap space during a collection cycle without needing to allocate additional memory. This is particularly beneficial for improving efficiency and reducing pauses in low-latency garbage collection scenarios.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Dense heap regions&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These are regions in the heap that contain a high proportion of live objects (objects that are still being used by the program). They are essentially “packed” with objects that haven’t been garbage collected yet.&lt;/p&gt;

&lt;p&gt;During garbage collection cycles, ZGC analyzes the density of each heap region. This analysis helps ZGC decide the most efficient way to handle each region.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Large objects&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;ZGC already handles large objects well.In Generational ZGC takes this a step further by allowing large objects to be allocated in the young generation. Given that regions can be aged without relocating them, there is no need to allocate large objects in the old generation just to prevent expensive relocations. Instead, they can be collected in the young generation if they are short-lived or be cheaply promoted to the old generation if they are long-lived.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;References between generations&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Generational ZGC avoids constantly tracking young-to-old references by piggybacking on young generation collections. This combined approach efficiently identifies and preserves objects still needed by the program across generations.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to Choose Your JVM GC&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Choosing the right garbage collector (GC) for your Java application involves understanding your specific needs and the characteristics of different GC algorithms offered by the JVM. &lt;/p&gt;

&lt;p&gt;In most cases, G1GC is a good starting point as it offers a balance between performance and pause times.&lt;/p&gt;

&lt;p&gt;If your primary concern is high memory throughput, and pauses are acceptable, Parallel GC might be a good choice. For ultra-low latency requirements, explore ZGC (consider its experimental nature).&lt;/p&gt;

&lt;p&gt;You can fine-tune the behavior of some GC algorithms using JVM flags. However, it’s generally recommended to start with default settings and adjust only if necessary&lt;/p&gt;

&lt;p&gt;Use profiling tools to analyze your application’s memory usage patterns and GC behavior. &lt;/p&gt;

&lt;p&gt;This can help you identify potential bottlenecks and refine your GC selection.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Previously published &lt;a href="https://codeline24.com"&gt;On My Blog&lt;/a&gt; where you can find more articles about Java and Spring Framework&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;For more in-depth discussions follow me on: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.linkedin.com/in/zeki-jusufoski-bsc-5b525385/"&gt;LinkedIn&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://x.com/jzeki"&gt;Twitter/X&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>java</category>
      <category>programming</category>
      <category>developers</category>
    </item>
    <item>
      <title>JAVA: Past and Present</title>
      <dc:creator>Zeki</dc:creator>
      <pubDate>Thu, 09 May 2024 09:43:56 +0000</pubDate>
      <link>https://dev.to/jusufoski/java-past-and-present-58pp</link>
      <guid>https://dev.to/jusufoski/java-past-and-present-58pp</guid>
      <description>&lt;p&gt;James Gosling, Mike Sheridan, and Patrick Naughton initiated the Java language project in June 1991. They envisioned a language that was portable, object-oriented, and could be used to develop a wide range of applications&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Previously published &lt;a href="https://codeline24.com"&gt;On My Blog&lt;/a&gt; where you can find more articles about Java and Spring Framework&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The language needed to use the principle of a virtual machine to make it compact and portable. It needed to be based on the current object-oriented language, C++.&lt;/p&gt;

&lt;p&gt;The project went ahead under the name “green” and the language was based on an old model of USCD Pascal, which makes it possible to generate interpretive code.&lt;/p&gt;

&lt;p&gt;In 1993, the language was renamed “Oak” and was oriented towards the object model that more closely matched the culture of in-house developers than the Pascal procedural model.&lt;/p&gt;

&lt;p&gt;The portability and compact nature of Oak made it the perfect candidate for use on the Internet, which was well known for its slow speed and heterogeneity on connected machines. It took nearly two years to adapt Oak, and in January 1995, after long brainstorming sessions and coffee breaks, Sun renamed Oak Java. &lt;/p&gt;

&lt;p&gt;On May 23, 1995, during the SunWorld Exposition, the technological achievements of Java language were presented to the public and brought quick success.&lt;/p&gt;

&lt;p&gt;Created with the slogan Write once, run anywhere (WORA), meant that a Java program could be developed on any device, compiled into a standard called bytecode, and be expected to run on any device equipped with a Java Runtime Environment (JRE).&lt;/p&gt;

&lt;p&gt;JRE is a concrete platform implementation of a set of specifications that formally define what is required to run Java applications. &lt;/p&gt;

&lt;p&gt;This set of specifications is called a Java virtual machine (JVM).&lt;/p&gt;

&lt;p&gt;This meant that engineers could develop programs written in Java language that would run on every platform that implements, platform specific JRE i.e. JVM.&lt;/p&gt;

&lt;p&gt;The way allowed Java to solve portability problems is that output of Java compiler is not platform specific compile code, it is a set of instructions called bytecode executed by Java Virtual Machine (JVM) which is part of Java Runtime Environment installed on a specific platform.&lt;/p&gt;

&lt;p&gt;In general, when a program is compiled to an intermediate form and then interpreted by a virtual machine, it runs slower than it would run if compiled to executable code. To provide a performance boost, HotSpot technology was introduced. HotSpot provides a Just-In-Time (JIT) compiler for bytecode. JIT compiler, compiles parts of bytecode into native code, as it is needed, during execution.&lt;/p&gt;

&lt;p&gt;Java almost immediately captivated the hearts of developers due to its portability and large set of built-in libraries and became popular for mainstream programming. Java evolved to three core technology packages (JVM, JRE and JDK, a superset of JRE) that represented both the platform and the programming language.&lt;/p&gt;

&lt;p&gt;The JVM provided the foundation for executing Java bytecode, the JRE provided the runtime environment for Java applications, and the JDK provided the tools for developing Java applications. This modular architecture made Java highly adaptable to various development environments and deployment scenarios.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Java: The Platform&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Besides JVM implementation, JRE contains other supporting tools to get most of your java applications, such as: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Development toolkits &lt;br&gt;
Frameworks for Graphical User Interface (GUI) called Abstract Windowing Toolkit (AWT) and Swing.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Integration libraries&lt;br&gt;
Java IDL, to support distributed objects written in Java Programming language, Java Database Connectivity (JDBC), tool for applications to access remote databases&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Java Naming and Directory Interface (JNDI), a directory service that lets clients create portable applications that fetch information from external databases using naming rules.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Language and utility libraries&lt;br&gt;
Set of packages that are fundamental for designing Java applications (such as collections and concurrency framework), management and monitoring.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Deployment solutions&lt;br&gt;
Technologies that simplify release changes and updates to user applications.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;JRE Implementation of JVM runs on top of the operating system and takes user compiled code, links it with above mentioned libraries and starts the JVM to run it.&lt;/p&gt;

&lt;p&gt;The JRE uses three core components to work&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;ClassLoader&lt;br&gt;
The Java ClassLoader dynamically loads all class files necessary into the Java Virtual Machine (JVM)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Bytecode Verifier&lt;br&gt;
They bytecode verifier checks the format and accuracy of the Java code before loading it into the JVM&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Interpreter&lt;br&gt;
Creates the JVM instance that runs the program&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Java Development Kit (JDK) is a superset of JRE(tool for running Java code) that provides tools necessary to write and develop Java applications.&lt;/p&gt;

&lt;p&gt;We can say that JDK is a concrete implementation of Java platform specifications and contains all that is needed to develop and run Java applications.&lt;/p&gt;

&lt;p&gt;Product name for JDK is Java Standard Edition (JSE).&lt;/p&gt;

&lt;p&gt;Java Enterprise Edition (JEE) is extending JSE with a set of specifications for enterprise functionalities such as web services, distributed computing, reading and writing to databases in a transactional way.&lt;/p&gt;

&lt;p&gt;Oracle Corporation is the current owner of the official implementation of the Java SE platform, following their acquisition of Sun Microsystems on January 27, 2010. &lt;/p&gt;

&lt;p&gt;On September 12, 2017 Oracle announced that it would submit the JEE to Eclipse Foundation.&lt;/p&gt;

&lt;p&gt;The platform was renamed from JEE to JakartaEE.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Java: The Language&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Sun Microsystems released the first public implementation as Java 1.0 in 1996.&lt;/p&gt;

&lt;p&gt;Since the first release of Java, there have been many additional features added to the language. Now Java is being used in Windows applications, Web applications, enterprise applications, mobile applications, cards, etc, Each new version adds new features.&lt;/p&gt;

&lt;p&gt;The Java Programming Language is a general-purpose, concurrent, strongly typed, class-based object-oriented language. It is normally compiled to the bytecode instruction set and binary format defined in the Java Virtual Machine Specification. &lt;/p&gt;

&lt;p&gt;Although fundamental principles of java are portability and security, other factors played important role also in invention and development of java, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Robustness&lt;br&gt;
There are two main reasons for program failure: memory management mistakes and run time errors. Java addresses these problems by providing automatic memory cleaning of unused objects, called garbage collection and object oriented exception handling for runtime errors. In a Java application all runtime errors should be managed by the program.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Familiarity and Simplicity&lt;br&gt;
Java was designed to be easy to learn, assuming that you have some programming experience. It was easy to move to java if you have some previous experience in C++.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Object Orientation&lt;br&gt;
Java strongly supports Object-Oriented Programming concepts such as encapsulation, abstraction, and inheritance.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All the instructions and data in a Java program have to be added inside a class or object.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Multithreading&lt;br&gt;
Java was written to be able to deal with multiple things simultaneously by defining multiple threads. Java runtime system implements multi process synchronization thas enables you to focus on behavior of your program instead of multitasking system&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Distributedness&lt;br&gt;
Java was designed to be able run in a distributed environment like the internet. Java also supports Remote method invocation(RMI) to be able invoke methods across networks.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Dynamicity&lt;br&gt;
With runtime type information java is able dynamically link new class libraries, objects and methods. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the past, major Java releases were typically separated by two or more years. However, subsequent to the release of JDK 9, the time between major Java releases has decreased. Today, the expected time between releases is just six months. &lt;/p&gt;

&lt;p&gt;At the heart of Java development is Java Community Processes (JCP), established in 1998,  a formalized mechanism that allows interested parties to develop standard technical specifications for Java technology.&lt;/p&gt;

&lt;p&gt;The JCP formalizes how new features and changes to Java are proposed via Java Specification Requests (JSRs). It contains proposed changes, additions, or improvements to the Java technology platform. The JCP itself is described by a JSR. As of 2020, JSR 387 describes the current version (2.11) of the JCP.&lt;/p&gt;

&lt;p&gt;Every JSR enters a review process. This is a multistage process wherein the changes proposed in the JSR are gradually considered more seriously, modified, anguished over, and eventually adopted.&lt;/p&gt;

&lt;p&gt;JEP is a JDK Enhancement Proposal. JEP proposes experimental ideas that are channeled into becoming JSR.&lt;/p&gt;

&lt;p&gt;New features of Java are delivered via JDK projects. When a proposal is mature it is considered for implementation in a JDK project.&lt;/p&gt;

&lt;p&gt;A JDK project is a broad range of implemented JEPs, including one or more groups responsible for various areas of the Java platform.&lt;/p&gt;

&lt;p&gt;The most important active JDK projects are: Amber, Loom, Panama and Valhalla&lt;/p&gt;

&lt;p&gt;Project Amber is incubator of smaller Java features intended to be part of future Java releases&lt;br&gt;
Project Loom is an effort to replace the old Java threading model that relies on underlying OS threads by creating virtual threads.&lt;br&gt;
Project Panama is an effort to improve Java communication with non-Java APIs through Java Native Interface(JNI) by introducing some foundational components.&lt;br&gt;
Project Valhalla’s aim is bringing between primitive and custom types. By unifying Java’s types it will be possible to apply generics to both classes and primitives gaining performance benefits.&lt;br&gt;
There have been many releases of Java language since 1995.&lt;/p&gt;

&lt;p&gt;We can say that Java 8 released in 2014 was the most significant release of Java that put it on the track of one of the  most important programming languages.&lt;/p&gt;

&lt;p&gt;Its main new features were Lambda expressions and stream API  putting it closer to the functional programming paradigm.&lt;/p&gt;

&lt;p&gt;Since Java 9, there have been new releases of Java every six months. However not every release of java gets Long Time Support (LTS).&lt;/p&gt;

&lt;p&gt;Currently Long time supported versions of Java are 11, 17 and 21, the last version released on September 21st 2023.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Java: Perspectives&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Java’s strict specifications and standardized development practices ensure consistency and interoperability across different development teams and environments. This consistency is crucial for building and maintaining complex microservices architectures.&lt;/p&gt;

&lt;p&gt;Because of its well defined JVM, with the advent of cloud computing, containerised development using technologies such as Docker and Kubernetes, is well suited for microservices architectures and various serverless approaches.&lt;/p&gt;

&lt;p&gt;Java  is used for mobile application development for building Android applications, which are used by billions of people worldwide. Java is also used in the development of cross-platform mobile applications using tools such as Xamarin and PhoneGap.&lt;/p&gt;

&lt;p&gt;Mobile and desktop game development is an area where Java is a popular choice.&lt;/p&gt;

&lt;p&gt;With the popular Spring framework’s implementation of JEE specifications, we can say that Java is the language of choice when it comes to development of enterprise applications and microservices architecture.&lt;/p&gt;

&lt;p&gt;In 1995, Java introduced two revolutionary concepts that became inevitable principles of modern software development: portability and memory management.&lt;/p&gt;

&lt;p&gt;Those two principles still play a fundamental role in the invention of new technologies and ways of software development.&lt;/p&gt;

&lt;p&gt;What do you think about Java Language prospects? You can write your thoughts in comments below.&lt;/p&gt;

&lt;p&gt;For more in-depth discussions follow me on: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.linkedin.com/in/zeki-jusufoski-bsc-5b525385/"&gt;LinkedIn&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://x.com/jzeki"&gt;Twitter/X&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>java</category>
      <category>programming</category>
      <category>development</category>
    </item>
  </channel>
</rss>
