<?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: Afi0125</title>
    <description>The latest articles on DEV Community by Afi0125 (@afii).</description>
    <link>https://dev.to/afii</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%2F1162409%2F40971f53-dec5-4e01-8350-56bbb1ccaf15.png</url>
      <title>DEV Community: Afi0125</title>
      <link>https://dev.to/afii</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/afii"/>
    <language>en</language>
    <item>
      <title>Creating a react component</title>
      <dc:creator>Afi0125</dc:creator>
      <pubDate>Mon, 02 Oct 2023 16:00:40 +0000</pubDate>
      <link>https://dev.to/afii/creating-a-react-component-f5l</link>
      <guid>https://dev.to/afii/creating-a-react-component-f5l</guid>
      <description>&lt;p&gt;Note: we use .ts for plain typescript file and .tsx for react component&lt;/p&gt;

&lt;p&gt;There are two ways to create REACT component : JavaScript class or function , these days function based component  are widely used because of they are concise and easier to write.&lt;/p&gt;

&lt;h2&gt;
  
  
  So the below code is under your .tsx file (mine is : Message.tsx)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Message() {
  return &amp;lt;h1&amp;gt;Hello World&amp;lt;/h1&amp;gt;;
}

export default Message; // this helps to import Message file in other files
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The below code is under App.tsx file , in order to use the Message.tsx file under the App.tsx file you need to import the Message.tsx file.
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import Message from './Message'; //here period(.)means the current folder

function App(){
  return &amp;lt;div&amp;gt;&amp;lt;Message&amp;gt;&amp;lt;/Message&amp;gt;&amp;lt;/div&amp;gt;;//you can also use &amp;lt;Message/&amp;gt; instead of &amp;lt;Message&amp;gt;&amp;lt;/Message&amp;gt;

export default App; //export App component to use it somewhere else


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

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0XUNBVxi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hj7r2lmstcvtrl11qcfv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0XUNBVxi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hj7r2lmstcvtrl11qcfv.png" alt="output" width="800" height="446"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>react</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Need of React ?</title>
      <dc:creator>Afi0125</dc:creator>
      <pubDate>Mon, 02 Oct 2023 14:56:30 +0000</pubDate>
      <link>https://dev.to/afii/need-of-react--5fcm</link>
      <guid>https://dev.to/afii/need-of-react--5fcm</guid>
      <description>&lt;p&gt;We have a tree with app being the root or top level component and message being a child component when a application starts, react takes this component tree and builds &lt;br&gt;
a JavaScript data structure called the virtual DOM (this virtual DOM is different from the actual DOM in the browser, it is a lightweight in memory representation) of our component tree where each node represents a component and its properties, when data of component tree changes react updates the corresponding node in the virtual DOM to reflect the new state then it compares the current version of virtual DOM to the previous version of DOM and identify the node that should be updated and then update the nodes in the actual DOM.&lt;/p&gt;

&lt;p&gt;React was created to make it easier to build user interfaces for web applications. It simplifies the process of updating and managing the parts of a web page that change as a user interacts with it.&lt;/p&gt;

&lt;p&gt;Imagine you're building a web page like a to-do list app. When a user adds a new item to their to-do list, you want the page to instantly show the new item without having to refresh the whole page. React helps you do this efficiently.&lt;/p&gt;

&lt;p&gt;Before React, developers had to manually update the web page's HTML whenever something changed. With React, you describe how your user interface should look for different states, and React takes care of updating the page when those states change.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--b-dREQbw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g7fhpj0wmwf4a166zr2e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--b-dREQbw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g7fhpj0wmwf4a166zr2e.png" alt="React image" width="800" height="456"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>programming</category>
      <category>beginners</category>
      <category>javascript</category>
    </item>
    <item>
      <title>How Java code executes for beginners</title>
      <dc:creator>Afi0125</dc:creator>
      <pubDate>Wed, 27 Sep 2023 05:04:07 +0000</pubDate>
      <link>https://dev.to/afii/how-java-code-executes-for-beginners-3bgp</link>
      <guid>https://dev.to/afii/how-java-code-executes-for-beginners-3bgp</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0iA4aQwU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yymr8ay0utl986vchccm.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0iA4aQwU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yymr8ay0utl986vchccm.jpg" alt="How java exectues for beginners" width="800" height="533"&gt;&lt;/a&gt;Java is a high-level programming language that uses a combination of compilation and interpretation to run your code.&lt;/p&gt;

&lt;p&gt;Let's deep dive into the procedure:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Writing java code;&lt;br&gt;
You start by writing your Java code in a text editor or an Integrated Development Environment (IDE). Java code is typically saved with a &lt;strong&gt;.java&lt;/strong&gt; extension.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Compilation:&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Java Compiler: Once you've written your code, you use the Java compiler (javac) to translate your human-readable code into an intermediate form known as bytecode.Bytecode is a set of instructions that can be executed by the Java Virtual Machine (JVM).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Bytecode File: The compiler generates a .class file for each class defined in your Java code. This file contains the bytecode and is platform-independent, meaning it can be executed on any system with a compatible JVM.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;Java Virtual Machine (JVM):&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Loading: When you want to run a Java program, you use the java command, followed by the name of the class containing the main method (the entry point of your program). For example, java MyProgram.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Class Loading: Once you specify the class to run, the JVM begins by loading the necessary .class files into its memory.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;These .class files contain the compiled bytecode of your Java classes (the instructions for your program).&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;ol&gt;
&lt;li&gt;Class-Loading Hierarchy:&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;

&lt;p&gt;The JVM follows a specific order or hierarchy when loading classes into memory. This hierarchy ensures that classes are loaded in a controlled and organized manner. There are typically three main stages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Bootstrap Classloader: This is the first step in the hierarchy. It loads core Java classes that are essential for the JVM's operation, like classes from the java.lang package. These classes are critical for the JVM to function properly.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Extension Classloader: After the bootstrap classloader, the extension classloader loads classes from Java's standard extension libraries. These libraries provide additional functionality beyond the core Java features. For example, if you use Java's cryptography tools or database connectors, those classes are loaded by the extension classloader.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Application Classloader: The final step in the hierarchy is the application classloader. It loads classes specific to your Java application, including the class that contains the main method. This classloader is responsible for loading your program's custom classes and any third-party libraries or JAR files you include.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I'll explain the concept of class loading and the class-loading hierarchy in the Java Virtual Machine (JVM) in a simpler way.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Loading:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;When you want to run a Java program, you use the java command, followed by the name of the class containing the main method (the entry point of your program). For example, java MyProgram.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Class Loading:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Once you specify the class to run, the JVM begins by loading the necessary .class files into its memory.&lt;br&gt;
These .class files contain the compiled bytecode of your Java classes (the instructions for your program).&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Class-Loading Hierarchy:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The JVM follows a specific order or hierarchy when loading classes into memory. This hierarchy ensures that classes are loaded in a controlled and organized manner. There are typically three main stages:&lt;/p&gt;

&lt;p&gt;Bootstrap Classloader: This is the first step in the hierarchy. It loads core Java classes that are essential for the JVM's operation, like classes from the java.lang package. These classes are critical for the JVM to function properly.&lt;/p&gt;

&lt;p&gt;Extension Classloader: After the bootstrap classloader, the extension classloader loads classes from Java's standard extension libraries. These libraries provide additional functionality beyond the core Java features. For example, if you use Java's cryptography tools or database connectors, those classes are loaded by the extension classloader.&lt;/p&gt;

&lt;p&gt;Application Classloader: The final step in the hierarchy is the application classloader. It loads classes specific to your Java application, including the class that contains the main method. This classloader is responsible for loading your program's custom classes and any third-party libraries or JAR files you include.&lt;/p&gt;

&lt;p&gt;In summary, class loading is the process of bringing the necessary Java classes into memory when you run a Java program. The JVM follows a hierarchy to load core classes, extension libraries, and your application-specific classes in a structured and controlled manner to ensure proper program execution.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Bytecode Verification: &lt;/li&gt;
&lt;li&gt;&lt;p&gt;Verification: Before executing any bytecode, the JVM performs a verification process to ensure the bytecode is valid and doesn't violate security constraints. This step helps prevent things like buffer overflows and type mismatches.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Just-In-Time (JIT) Compilation: &lt;br&gt;
Compilation to Native Code: The JVM may employ a Just-In-Time compiler to convert bytecode into native machine code specific to the host system. This step improves execution speed.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Caching: The native code is often cached to avoid recompilation of frequently executed code segments.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Execution:&lt;/li&gt;
&lt;li&gt;Execution of main Method: The JVM starts executing your Java program by invoking the main method in your specified class.&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;Execution Flow: As your program runs, the JVM follows the flow of your Java code, executing instructions one by one.&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;Memory Management:

&lt;ul&gt;
&lt;li&gt;Heap: The JVM manages memory using a heap, which is where objects are allocated and deallocated. The garbage collector periodically frees up memory by reclaiming objects no longer in use.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Stack: The JVM uses a stack for method calls and local variables. Each method call creates a new stack frame, which is popped off when the method returns.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Exception Handling:
Java programs can throw exceptions when errors or unexpected conditions occur. The JVM handles these exceptions and can propagate them up the call stack until they are caught and handled by appropriate exception-handling code.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Termination:When your main method finishes executing or an unhandled exception occurs, the program terminates.&lt;br&gt;
The JVM performs cleanup tasks, like finalizing objects, before exiting.&lt;/p&gt;

&lt;p&gt;Output and Result:&lt;/p&gt;

&lt;p&gt;If your program produces output (e.g., printing to the console), you'll see it on the screen.&lt;br&gt;
If your program returns a value, that value can be used by other programs or scripts calling your Java program.&lt;/p&gt;

</description>
      <category>java</category>
      <category>beginners</category>
      <category>programming</category>
      <category>learning</category>
    </item>
    <item>
      <title>Async and Await function in JavaScript Promises</title>
      <dc:creator>Afi0125</dc:creator>
      <pubDate>Sat, 23 Sep 2023 11:17:38 +0000</pubDate>
      <link>https://dev.to/afii/async-and-await-function-in-javascript-promises-1jln</link>
      <guid>https://dev.to/afii/async-and-await-function-in-javascript-promises-1jln</guid>
      <description>&lt;p&gt;&lt;strong&gt;This async/await&lt;/strong&gt; syntax makes working with promises more straightforward and readable, especially for handling asynchronous operations in a more synchronous-looking way.&lt;/p&gt;

&lt;p&gt;Promises are a way in JavaScript to handle asynchronous tasks, like fetching data from a server or reading files. They help you work with code that doesn't run in a predictable order. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A promise is like ordering food ,it represents something that will be delivered in the present , future or never/cancelled.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const fetchuserData = new Promise(function(resolve,reject){
  setTimeout(() =&amp;gt;{
    const data = {username :"maktub", password:"football"};
    resolve(data);
  }, 2000);
});

// Now, we can use the async/await syntax to work with promises more easily.

async function getUserData() {
    try {
        console.log("fetching user data");
        const user = await fetchuserData;
        console.log("user data", user);
    } catch (error) {
        console.error("Error", error);
    }

}

getUserData();
console.log("request in progress");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--r6h5RUqc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c9d8w6rg45mwvo9eylkb.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--r6h5RUqc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c9d8w6rg45mwvo9eylkb.jpg" alt="Image description" width="800" height="613"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Here's how the code works step by step:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;The fetchUserData function returns a promise. Inside the promise, there's a setTimeout function that simulates a 2-second delay. After the delay, the promise is resolved with a JavaScript object containing user data (in this case, { username: "maktub" , password :"football" }).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The getUserData function is defined as an async function. This allows you to use the await keyword inside it.getUserData is an async function that uses await to wait for the promise to resolve. It makes the code look more like synchronous code, even though it's asynchronous.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;When you call getUserData, it logs "Fetching user data..." and then waits for the promise to resolve before logging the user data.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The last console.log line runs immediately, showing that the code doesn't block while waiting for the promise.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If there were any errors during the promise resolution (for example, if you had used reject instead of resolve), the code would jump to the catch block and log the error message.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>javascript</category>
      <category>programming</category>
      <category>api</category>
      <category>learning</category>
    </item>
    <item>
      <title>Basic Promise in JavaScript</title>
      <dc:creator>Afi0125</dc:creator>
      <pubDate>Sat, 23 Sep 2023 07:32:12 +0000</pubDate>
      <link>https://dev.to/afii/basic-promise-in-javascript-7f7</link>
      <guid>https://dev.to/afii/basic-promise-in-javascript-7f7</guid>
      <description>&lt;p&gt;&lt;strong&gt;Promise in javaScript is a way to handle asynchronous operations, such as fetching data from server ,reading files or making a request from network. Promise helps you to write more readable and organized code when dealing with asynchronous tasks.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here is a simple example: 1. Resolving a promise&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const promiseOne = new Promise(function(resolve, reject) {

//this is the very common way to write promise

setTimeout(() =&amp;gt; {
resolve("async task completed");
}, 1000); 
});

NOTE: 
// .then() block is connected to the resolve part of the promise
// simulate task completed after 1 sec



promiseOne.then((message) =&amp;gt; {
console.log(message);
})

.catch((error) =&amp;gt; {
console.log(error)
});

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

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;In this example, we create a Promise that resolves after 1 seconds, simulating a successful async task. The [.then()] block executes when the promise is resolved and in this case the [.catch] block will not be displayed as we have successfully completed the task.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ol&gt;
&lt;li&gt;Rejecting a Promise
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const promiseReject = new Promise(function(resolve, reject){
    setTimeout(() =&amp;gt; {
        reject("sorry could not complete your task");
    }, 1000);
});

promiseReject
.then((message) =&amp;gt;{
    console.log(message);
})
.catch((error) =&amp;gt; {
console.log(error);
 });

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

&lt;/div&gt;



&lt;p&gt;In this code, when the promise is rejected with the message "sorry could not complete your task" the [.catch() block] will execute, and "sorry could not complete your task" will be logged to the console. The .then() block won't execute because the promise was rejected, not resolved.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NOTE&lt;/strong&gt;&lt;br&gt;
To summarize, the behavior of .then() and .catch() depends on whether the promise is resolved or rejected. If the promise is resolved, the .then() block executes. If the promise is rejected, the .catch() block executes.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>productivity</category>
      <category>javascript</category>
      <category>discuss</category>
    </item>
  </channel>
</rss>
