Menu BAR

FEEL FREE TO ASK ANY PROGRAM and please mention any error if you find it

10 Feb 2024

JAVA PROGRAM - PYRAMID STAR PATTERN


## Write a Java program to print the PYRAMID STAR PATTERN? 



                                                                    *
                                                                *  *  *
                                                            *  *  *  *  *
                                                        *  *  *  *  *  *  *
                                                    *  *  *  *  *  *  *  *  *


public class PyramidStarPattern { 

                        public static void main(String[] args) { 
                                        int rows = 5; 

                                        for (int i = 1; i <= rows; i++) { 
                                                            for (int j = 1; j <= rows - i; j++) { 
                                                                            System.out.print("  "); 
                                                            
                                                            for (int k = 1; k <= 2 * i - 1; k++) { 
                                                                            System.out.print("* "); 
                                                            
                                                            System.out.println(); 
                                        
                      
}

JAVA PROGRAM - LEAP YEAR OR NOT


 ## Write a Java Program to check if the year is LEAP YEAR or NOT



 public class CheckLeapYear { 

                    public static void main(String[] args) { 
                                        int year = 2024; 

                                        if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
                                                             System.out.println("The year " + year + " is a leap year."); 
                                        
                                        else { 
                                                             System.out.println("The year " year + " is not a leap year."); 
                                        
                    
}

JAVA PROGRAM - LARGEST VALUE AMONG THREE NUMBERS


 ## Write a Java program to find the largest value among three variables



public class LargestAmongThreeNumbers { 

            public static void main(String[] args) { 
                            int num1 = 20; 
                            int num2 = 50; 
                            int num3 = 55; 

                            int largest = num1; 

                            if (num2 > largest) { 
                                            largest = num2; 
                            
                            if (num3 > largest) { 
                                            largest = num3; 
                            
        
                            System.out.println("The largest number among " + num1 + ", " + num2 + ", and " + num3 + " is: " + largest); 
            
}

JAVA PROGRAM - LARGEST VALUE AMONG TWO NUMBERS


## Write a Java Program to find the largest value among two numbers 



public class LargestOfTwoNumbers { 

          public static void main(String[] args) { 
                    int num1 = 10; 
                    int num2 = 20; 

                    if (num1 > num2) { 
                                    System.out.println("The largest number is: " + num1); 
                    
                    else { 
                                    System.out.println("The largest number is: " + num2); 
                    }
        
}

8 Feb 2024

JAVA TUTORIAL PART 1 - INTRODUCTION TO JAVA


1) WHAT IS JAVA?



1) Java is a multi-platformhigh-level, object-oriented programming language developed by Sun Microsystems (now owned by Oracle Corporation).

2) It is a fast, secure, reliable programming language for coding.

2) The main principle of Java is - "WRITE ONCE, RUN ANYWHERE"

3) Java programs can be compiled into Bytecode, which can then be executed on any platform that has a Java Virtual Machine (JVM).

4) Due to the ByteCode, there is no need to recompile the code for each platform.



2) Key Features of Java



1) Platform Independence - Java programs can run on any platform that has a JVM, making them very highly profitable.

2) Object-Oriented - Java is an OO language and hence it emphasizes the use of Classes and Objects for better code organization.

3) Simple and Familiar Syntax - It is similar to C and C++.

4) Memory Management - Java has a built-in garbage collector that manages memory allocation and deallocation automatically.

5) Robust and Secure - Java's strong type system, exception handling, and security features make it robust and secure. 

6) Multithreading - Java supports multithreading to perform concurrent tasks easily.


3) Common Applications of Java


1) Web Development

2) Mobile Development

3) Desktop Applications

4) Enterprise Applications

5) Embedded Systems


4) Download Java



Download Java from the official website https://www.oracle.com/java/technologies/downloads/



JAVA - SUBTRACT TWO NUMBERS


 Write a JAVA program to subtract two numbers?




public class SubtractTwoNumbers { 

                public static void main(String[] args) {
                                int num1 = 10; int num2 = 5; 
                                int difference = num1 - num2; 

                                System.out.println("Difference of " + num1 + " and " + num2 + " is: " + difference);
                 

}

7 Feb 2024

JAVA - ADD TWO NUMBERS


 ## Write a Java program to add two numbers




public class AddTwoNumbers { 

    public static void main(String[] args) {
                
                int num1 = 5; int num2 = 10; 
                int sum = num1 + num2; 

                System.out.println("Sum of " + num1 + " and " + num2 + " is: " + sum); 
                
}

NODE JS - ASYNCHRONOUS PROGRAMMING


 1) What is Asynchronous Programming?



Asynchronous programming allows tasks to be executed concurrently without blocking the execution of other tasks and this can be achieved through callbacks, promises, and async/await.

Note that JavaScript is single-threaded. It carries out asynchronous operations via the callback queue and event loop.


2) Benefits of Asynchronous Programming?



1) Improved Performance - By avoiding blocking operations, asynchronous programming allows the application to continue executing other tasks while waiting for I/O operations to complete.
(Faster response times and better resource utilization).

2) Scalability - Asynchronous programming enables Node.Js applications to handle many concurrent requests without significant performance degradation.
(High-Performance web servers and real-time applications)

3) Responsive User Interfaces - Asynchronous programming ensures the user interface remains responsive even when performing time-consuming operations.
(Enhances the overall user experience and prevents applications from freezing)


3) Callbacks


Callbacks are a fundamental mechanism in Node Js for handling asynchronous operations.
Callbacks are functions passed as arguments to other functions and they are called once the operation is completed.

Example - 

const fs = require('fs'); 

fs.readFile('example.txt', 'utf8', (err, data) => { 
            if (err) { 
                        console.error(err); 
                        return; 
            
            console.log(data); 
});


4) Promises


Promises represent a value that may be available now, in the future, or never.
They allow chaining of asynchronous operations and handling of errors more elegantly.
Promises improve code readability and make error handling easier.

Example - 

const fs = require('fs').promises; 

fs.readFile('example.txt', 'utf8').
        then((data) => { 
        console.log(data); 
        }) 
        .catch((err) => { 
                console.error(err); 
        });

5) Async/ Await


Async functions enable writing asynchronous code in a synchronous-like manner using the 'async' and 'await'.
'async' - define an asynchronous function and 'await' - waits for promises to resolve.

Example - 

const fs = require('fs').promises; 

async function testingAsync() { 
        try { 
                const data = await fs.readFile('example.txt', 'utf8'); 
                console.log(data); 
        } catch (err) { 
                console.error(err); 
         

testingAsync();

6 Feb 2024

NODE JS - NPM


 1) What is NPM?


- Node Js npm (Node Package Manager) is a package manager for JavaScript, which is used for managing dependencies in Node.js applications.

- With npm, we can easily install, manage, and update packages (Libraries/ Modules) that you can use in your applications.

- www.npmjs.com hosts thousands of packages to download and use

- To install a package using npm - 
npm install package-name

   This will download the package and add it to your node_modules directory, along with dependencies.

- Example - 
                    To install Express, you can run the below command - 
  npm install express
or
npm i express

- Always include the installed package in your package.json file by adding them to the dependencies section.