Posts

Showing posts from August, 2024
To check the port number association with Process id C:\Windows\System32>netstat -ano | findstr 8080   TCP    0.0.0.0:8080           0.0.0.0:0              LISTENING       4984   TCP    [::]:8080              [::]:0                 LISTENING       4984 takkill cannot kill the process with simple command C:\Windows\System32>taskkill /PID 4984 ERROR: The process with PID 4984 could not be terminated. Reason: This process can only be terminated forcefully (with /F option). taskkill is successful when /f option is included. C:\Windows\System32>taskkill /f /PID 4984 SUCCESS: The process with PID 4984 has been terminated. C:\Windows\System32>netstat -ano | findstr 8080   TCP    [::1]:53730            [::1]:8080    ...

Creating a professional networking site with Spring Boot and Angular ( AI generated code)

Creating a professional networking site with Spring Boot and Angular involves setting up both a backend server with Spring Boot and a frontend client with Angular. This guide outlines the main steps needed to build such a project. ### 1. **Set Up the Backend with Spring Boot** #### 1.1. **Create a Spring Boot Project** You can create a Spring Boot project using Spring Initializr or your IDE. **Using Spring Initializr:** - Go to [Spring Initializr](https://start.spring.io/). - Set the project metadata (e.g., group: `com.example`, artifact: `networking-site`). - Choose the dependencies:   - Spring Web   - Spring Data JPA   - Spring Security   - H2 Database (for development)   - MySQL Driver (for production)   - Lombok (optional, for reducing boilerplate code) **Generate the project and extract it.** #### 1.2. **Set Up the Database** In `src/main/resources/application.properties`, configure the H2 database for development and MySQL for production. ```propertie...

Java 8 new Date and Time API

 Java 8 introduced a new Date and Time API that addresses many of the problems of the older `java.util.Date` and `java.util.Calendar` classes. The new API is part of the `java.time` package and provides a more comprehensive and consistent approach to handling dates and times. ### Key Classes in the Java 8 Date and Time API: 1. **`LocalDate`**:    - Represents a date without time (e.g., `2024-08-12`).    - Immutable and thread-safe.    ```java    LocalDate date = LocalDate.now(); // Current date    LocalDate specificDate = LocalDate.of(2024, Month.AUGUST, 12); // Specific date    ``` 2. **`LocalTime`**:    - Represents a time without a date (e.g., `14:30:00`).    - Immutable and thread-safe.    ```java    LocalTime time = LocalTime.now(); // Current time    LocalTime specificTime = LocalTime.of(14, 30); // Specific time    ``` 3. **`LocalDateTime`**:    -...

**JSON** (JavaScript Object Notation) Summary (AI generated)

 **JSON** (JavaScript Object Notation) is a lightweight data interchange format that's easy for humans to read and write, and easy for machines to parse and generate. It is widely used in web applications to transmit data between a server and a client. ### Key Characteristics of JSON: 1. **Textual Format**:    - JSON is a text-based format, making it easy to send over the internet and store in files. 2. **Language Independent**:    - While JSON is derived from JavaScript, it is language-independent and can be used by many programming languages, including Python, Java, C#, and PHP. 3. **Human-Readable**:    - JSON's syntax is simple and human-readable, resembling the way objects are defined in JavaScript. 4. **Structure**:    - JSON represents data as key-value pairs, where keys are strings and values can be strings, numbers, objects, arrays, booleans, or `null`. ### JSON Syntax: A JSON object is an unordered set of key-value pairs, and a JSON...

Topics in Java Programming which should be studies by every Java Programmer ( AI generated)

 When learning Java programming, there are several fundamental and advanced topics that are essential to master. Here’s a breakdown of the must-know topics: **1. Basics of Java Programming Syntax and Structure : Understanding the basic structure of a Java program, including how to write a simple Hello World program. Data Types and Variables : Primitive data types (int, char, float, etc.), reference types, and how to declare and initialize variables. Operators : Arithmetic, relational, logical, bitwise, and assignment operators. Control Flow Statements : If-else, switch-case, loops (for, while, do-while), and branching statements (break, continue, return). **2. Object-Oriented Programming (OOP) Concepts Classes and Objects : How to define classes, create objects, and understand the relationship between classes and objects. Inheritance : Understanding how classes can inherit properties and methods from other classes. Polymorphism : Compile-time (method overloading) and runtime polym...

Java - Sample Exercise of testing the objects..

   Sample Exercise Create an encapsulated class with 4 fields and the respective methods to access and edit those fields. Then go ahead and create a test class to verify. Class Name : Student Field Names : studentId, studentName, collegeName, address Test Class Name : TestStudent

Java Thread

 Java threads are an essential part of concurrent programming in Java, enabling you to execute multiple tasks simultaneously within a program. Here's a detailed explanation: What is a Thread? A thread is a lightweight process that can run independently. Within a Java program, multiple threads can run concurrently, sharing the same memory space. This allows a program to perform multiple operations at the same time, such as handling user input while processing data in the background. Creating Threads in Java There are two primary ways to create a thread in Java: Extending the Thread class: You can create a new thread by extending the Thread class and overriding its run() method. Example: java Copy code class MyThread extends Thread { public void run () { System.out.println( "Thread is running" ); } } public class Main { public static void main (String[] args) { MyThread thread = new MyThread (); thread.start(); // Th...

Java Collection interview question and answers

 If you're preparing for a Java interview with a focus on collections, here are some common questions you might encounter, along with detailed answers to help you prepare: 1. What is the Java Collections Framework? Answer: The Java Collections Framework (JCF) is a set of classes and interfaces that implement commonly reusable collection data structures. It provides several classes like ArrayList , LinkedList , HashSet , HashMap , and interfaces like List , Set , Map , and Queue . It is designed to manage groups of objects, known as collections. 2. What is the difference between ArrayList and LinkedList ? Answer: ArrayList : Uses a dynamic array to store elements. Provides fast random access (O(1)) but slow insertions and deletions (O(n)) in the middle of the list. Better when you need frequent access to elements by index. LinkedList : Uses a doubly-linked list to store elements. Provides constant-time insertions and deletions (O(1)) at the start or end, but slower access (O(n)) fo...

Output formatter

 import java.io.*; import java.util.*; public class Solution {     public static void main(String[] args) {         /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */         Scanner sc=new Scanner(System.in);             System.out.println("================================");             for(int i=0;i<3;i++)             {                 String s1=sc.next();                 int x=sc.nextInt();                 System.out.format("%-15s%03d\n",s1,x);             }             System.out.println("================================");                     ...

print the input for Integer, Double and String

print the input for Integer, Double and String  --------------------------------------------------------------------------------------------------------------------- import java.util.Scanner; public class Solution {     public static void main(String[] args) {         Scanner scan = new Scanner(System.in);         int i = scan.nextInt();         double d = scan.nextDouble();         scan.nextLine();         String s = scan.nextLine();         // Write your code here.         System.out.println("String: "+ s);         System.out.println("Double: "+d);         System.out.println("Int: "+i);     } }

java persistent API , JPA ( AI generated)

Java Persistence API (JPA) is a Java specification for managing relational data in Java applications. JPA provides a framework to map Java objects to database tables and manage the interactions between them. It’s part of the Java EE (Enterprise Edition) and is a standard for ORM (Object-Relational Mapping). ### Key Concepts of JPA 1. **Entity**: An entity represents a table in a relational database and each entity instance corresponds to a row in that table. 2. **Entity Manager**: The EntityManager is the interface used to interact with the persistence context. It provides methods for CRUD (Create, Read, Update, Delete) operations. 3. **Persistence Context**: This is a set of managed entity instances that exist in a particular EntityManager session. 4. **Persistence Unit**: Defines the set of all entity classes that are managed by EntityManager in an application. ### Basic Example of JPA #### 1. Define an Entity An entity is defined using the `@Entity` annotation and usually correspond...

Check java version in runtime

 Check java version in runtime:  1) System.out.println (System.getProperty("java.version")); 2)  System.out.println ( Runtime.version() );

Windows : check and kill the port # process

C:\Windows\System32> netstat -ano | findstr :8080   TCP    0.0.0.0:8080           0.0.0.0:0              LISTENING       6184   TCP    [::]:8080              [::]:0                 LISTENING       6184   TCP    [::1]:8080             [::1]:62420            ESTABLISHED     6184   TCP    [::1]:62419            [::1]:8080             TIME_WAIT       0   TCP    [::1]:62420            [::1]:8080             ESTABLISHED     5300 C:\Windows\System32>taskkill /F /PID 5300 SUCCESS: The process ...