parent
f953b96d52
commit
bc97fc4c03
54 changed files with 744 additions and 57 deletions
@ -0,0 +1,181 @@ |
||||
import fs from 'node:fs/promises'; |
||||
import path from 'node:path'; |
||||
import { fileURLToPath } from 'node:url'; |
||||
import type { Edge, Node } from 'reactflow'; |
||||
import matter from 'gray-matter'; |
||||
import type { RoadmapFrontmatter } from '../src/lib/roadmap'; |
||||
import { slugify } from '../src/lib/slugger'; |
||||
import { runPromisesInBatchSequentially } from '../src/lib/promise'; |
||||
|
||||
import { createGoogleGenerativeAI } from '@ai-sdk/google'; |
||||
import { generateText } from 'ai'; |
||||
|
||||
// ERROR: `__dirname` is not defined in ES module scope
|
||||
// https://iamwebwiz.medium.com/how-to-fix-dirname-is-not-defined-in-es-module-scope-34d94a86694d
|
||||
const __filename = fileURLToPath(import.meta.url); |
||||
const __dirname = path.dirname(__filename); |
||||
|
||||
// Usage: tsx ./scripts/editor-roadmap-content.ts <roadmapId>
|
||||
const GEMINI_API_KEY = process.env.GEMINI_API_KEY; |
||||
console.log('GEMINI_API_KEY:', GEMINI_API_KEY); |
||||
const ROADMAP_CONTENT_DIR = path.join(__dirname, '../src/data/roadmaps'); |
||||
const roadmapId = process.argv[2]; |
||||
|
||||
const google = createGoogleGenerativeAI({ |
||||
apiKey: process.env.GEMINI_API_KEY, |
||||
}); |
||||
|
||||
const allowedRoadmapIds = await fs.readdir(ROADMAP_CONTENT_DIR); |
||||
if (!roadmapId) { |
||||
console.error('Roadmap Id is required'); |
||||
process.exit(1); |
||||
} |
||||
|
||||
if (!allowedRoadmapIds.includes(roadmapId)) { |
||||
console.error(`Invalid roadmap key ${roadmapId}`); |
||||
console.error(`Allowed keys are ${allowedRoadmapIds.join(', ')}`); |
||||
process.exit(1); |
||||
} |
||||
|
||||
const roadmapFrontmatterDir = path.join( |
||||
ROADMAP_CONTENT_DIR, |
||||
roadmapId, |
||||
`${roadmapId}.md`, |
||||
); |
||||
const roadmapFrontmatterRaw = await fs.readFile(roadmapFrontmatterDir, 'utf-8'); |
||||
const { data } = matter(roadmapFrontmatterRaw); |
||||
|
||||
const roadmapFrontmatter = data as RoadmapFrontmatter; |
||||
if (!roadmapFrontmatter) { |
||||
console.error('Invalid roadmap frontmatter'); |
||||
process.exit(1); |
||||
} |
||||
|
||||
if (roadmapFrontmatter.renderer !== 'editor') { |
||||
console.error('Only Editor Rendered Roadmaps are allowed'); |
||||
process.exit(1); |
||||
} |
||||
|
||||
const roadmapDir = path.join( |
||||
ROADMAP_CONTENT_DIR, |
||||
roadmapId, |
||||
`${roadmapId}.json`, |
||||
); |
||||
const roadmapContent = await fs.readFile(roadmapDir, 'utf-8'); |
||||
let { nodes, edges } = JSON.parse(roadmapContent) as { |
||||
nodes: Node[]; |
||||
edges: Edge[]; |
||||
}; |
||||
const enrichedNodes = nodes |
||||
.filter( |
||||
(node) => |
||||
node?.type && |
||||
['topic', 'subtopic'].includes(node.type) && |
||||
node.data?.label, |
||||
) |
||||
.map((node) => { |
||||
// Because we only need the parent id and title for subtopics
|
||||
if (node.type !== 'subtopic') { |
||||
return node; |
||||
} |
||||
|
||||
const parentNodeId = |
||||
edges.find((edge) => edge.target === node.id)?.source || ''; |
||||
const parentNode = nodes.find((n) => n.id === parentNodeId); |
||||
|
||||
return { |
||||
...node, |
||||
parentId: parentNodeId, |
||||
parentTitle: parentNode?.data?.label || '', |
||||
}; |
||||
}) as (Node & { parentId?: string; parentTitle?: string })[]; |
||||
|
||||
const roadmapContentDir = path.join(ROADMAP_CONTENT_DIR, roadmapId, 'content'); |
||||
const stats = await fs.stat(roadmapContentDir).catch(() => null); |
||||
if (!stats || !stats.isDirectory()) { |
||||
await fs.mkdir(roadmapContentDir, { recursive: true }); |
||||
} |
||||
|
||||
function writeTopicContent( |
||||
roadmapTitle: string, |
||||
childTopic: string, |
||||
parentTopic?: string, |
||||
) { |
||||
const updatedTitle = roadmapTitle.replace('Roadmap', '').trim().replace('Developer', ''); |
||||
let prompt = `I will give you a topic and you need to write a brief introduction for that in "${roadmapTitle}". Your format should be as follows and be in strictly markdown format:
|
||||
|
||||
# (Put a heading for the topic without adding parent "Subtopic in Topic" or "Topic in Roadmap" or "Subtopic under XYZ" etc.) |
||||
|
||||
(Briefly explain the topic in one paragraph using simple english. Don't start with explaining how important the topic is with regard to "${roadmapTitle}". Don't say something along the lines of "XYZ plays a crucial role in ${roadmapTitle}". Don't include anything saying "In the context of ${roadmapTitle}". Instead, start with a simple explanation of the topic itself. For example, if the topic is "React", you can start with "React is a JavaScript library for building user interfaces."".) |
||||
`;
|
||||
|
||||
if (!parentTopic) { |
||||
prompt += `First topic is: ${childTopic}`; |
||||
} else { |
||||
prompt += `First topic is: "${parentTopic} > ${childTopic}"`; |
||||
} |
||||
|
||||
return new Promise((resolve, reject) => { |
||||
generateText({ |
||||
model: google('gemini-2.0-flash'), |
||||
prompt: prompt, |
||||
providerOptions: { |
||||
} |
||||
}) |
||||
.then((response) => { |
||||
const article = response.text; |
||||
|
||||
resolve(article); |
||||
}) |
||||
.catch((err) => { |
||||
reject(err); |
||||
}); |
||||
}); |
||||
} |
||||
|
||||
async function writeNodeContent(node: Node & { parentTitle?: string }) { |
||||
const nodeDirPattern = `${slugify(node.data.label)}@${node.id}.md`; |
||||
if (!roadmapContentFiles.includes(nodeDirPattern)) { |
||||
console.log(`Missing file for: ${nodeDirPattern}`); |
||||
return; |
||||
} |
||||
|
||||
const nodeDir = path.join(roadmapContentDir, nodeDirPattern); |
||||
const nodeContent = await fs.readFile(nodeDir, 'utf-8'); |
||||
const isFileEmpty = !nodeContent.replace(`# ${node.data.label}`, '').trim(); |
||||
if (!isFileEmpty) { |
||||
console.log(`❌ Ignoring ${nodeDirPattern}. Not empty.`); |
||||
return; |
||||
} |
||||
|
||||
const topic = node.data.label; |
||||
const parentTopic = node.parentTitle; |
||||
|
||||
console.log(`⏳ Generating content for ${topic}...`); |
||||
let newContentFile = ''; |
||||
if (GEMINI_API_KEY) { |
||||
newContentFile = (await writeTopicContent( |
||||
roadmapFrontmatter.title, |
||||
topic, |
||||
parentTopic, |
||||
)) as string; |
||||
} else { |
||||
newContentFile = `# ${topic}`; |
||||
} |
||||
|
||||
await fs.writeFile(nodeDir, newContentFile, 'utf-8'); |
||||
console.log(`✅ Content generated for ${topic}`); |
||||
} |
||||
|
||||
let roadmapContentFiles = await fs.readdir(roadmapContentDir, { |
||||
recursive: true, |
||||
}); |
||||
|
||||
if (!GEMINI_API_KEY) { |
||||
console.log('----------------------------------------'); |
||||
console.log('GEMINI_API_KEY not found. Skipping gemini api calls...'); |
||||
console.log('----------------------------------------'); |
||||
} |
||||
const promises = enrichedNodes.map((node) => () => writeNodeContent(node)); |
||||
await runPromisesInBatchSequentially(promises, 20); |
||||
console.log('✅ All content generated'); |
@ -1 +1,8 @@ |
||||
# Abstraction |
||||
# Abstraction |
||||
|
||||
The abstract keyword in Java is used to declare a class or a method that cannot be instantiated directly or must be implemented by subclasses, respectively. It is a key part of Java's abstraction mechanism, allowing developers to define abstract classes and methods that provide a blueprint for other classes. |
||||
|
||||
Visit the following resources to learn more: |
||||
|
||||
- [@article@Java Abstract Classes](https://jenkov.com/tutorials/java/abstract-classes.html) |
||||
- [@article@Java Interfaces vs. Abstract Classes](https://jenkov.com/tutorials/java/interfaces-vs-abstract-classes.html) |
||||
|
@ -1 +1,7 @@ |
||||
# Access Specifiers |
||||
# Access Specifiers |
||||
|
||||
Access specifiers (or access modifiers) in Java are keywords that control the visibility or accessibility of classes, methods, constructors, and other members. They determine from where these members can be accessed. Java provides four access specifiers: `private`, `default` (no keyword), `protected`, and `public`, each offering a different level of access control. |
||||
|
||||
Visit the following resources to learn more: |
||||
|
||||
- [@article@Java Access Modifiers](https://jenkov.com/tutorials/java/access-modifiers.html) |
||||
|
@ -1 +1,7 @@ |
||||
# Annotations |
||||
# Annotations |
||||
|
||||
Annotations are a form of metadata that provide data about a program. They are used to provide supplemental information about the code, but they are not a part of the program itself. Annotations can be used by the compiler to detect errors or suppress warnings, and they can also be used at runtime to modify the behavior of the program. |
||||
|
||||
Visit the following resources to learn more: |
||||
|
||||
- [@article@Java Annotations Tutorial](https://jenkov.com/tutorials/java/annotations.html) |
@ -1 +1,8 @@ |
||||
# Array vs ArrayList |
||||
# Array vs ArrayList |
||||
|
||||
Arrays and ArrayLists are both ways to store collections of elements in Java. An array is a fixed-size, ordered sequence of elements of the same data type. Once you declare its size, you cannot change it. An ArrayList, on the other hand, is a dynamic, resizable array implementation. It can grow or shrink as needed, allowing you to add or remove elements without worrying about the initial size. |
||||
|
||||
Visit the following resources to learn more: |
||||
|
||||
- [@article@Java Arrays](https://jenkov.com/tutorials/java/arrays.html) |
||||
- [@article@Java ArrayLists](https://jenkov.com/tutorials/java-collections/list.html) |
||||
|
@ -1 +1,8 @@ |
||||
# Arrays |
||||
# Arrays |
||||
|
||||
Arrays are fundamental data structures used to store a collection of elements of the same data type in contiguous memory locations. They provide a way to organize and access multiple values using a single variable name and an index. Each element in an array can be accessed directly using its index, starting from 0. |
||||
|
||||
Visit the following resources to learn more: |
||||
|
||||
- [@article@Java Arrays](https://jenkov.com/tutorials/java/arrays.html) |
||||
- [@video@Java Arrays Tutorial](https://www.youtube.com/watch?v=ei_4Nt7XWOw) |
@ -1 +1,9 @@ |
||||
# Attributes and Methods |
||||
# Attributes and Methods |
||||
|
||||
Attributes are variables that hold data about an object, defining its state or characteristics. Methods are functions that define the behavior of an object, allowing it to perform actions or operations. Together, attributes and methods encapsulate the data and behavior of an object within a class. |
||||
|
||||
Visit the following resources to learn more: |
||||
|
||||
- [@article@Java Classes](https://jenkov.com/tutorials/java/classes.html) |
||||
- [@article@Java Methods](https://jenkov.com/tutorials/java/methods.html) |
||||
- [@article@Java Properties](https://jenkov.com/tutorials/java-collections/properties.html) |
||||
|
@ -1 +1,7 @@ |
||||
# Basics of OOP |
||||
# Basics of OOP |
||||
|
||||
Object-Oriented Programming (OOP) is a programming paradigm centered around "objects," which contain data in the form of fields (attributes) and code in the form of procedures (methods). OOP focuses on creating reusable code by grouping related data and behavior into objects, allowing for modularity, abstraction, inheritance, and polymorphism. These concepts help in organizing and structuring code in a way that mirrors real-world entities and their interactions. |
||||
|
||||
Visit the following resources to learn more: |
||||
|
||||
- [@article@Java Classes and Objects](https://jenkov.com/tutorials/java/classes.html) |
||||
|
@ -1 +1,9 @@ |
||||
# Bazel |
||||
# Bazel |
||||
|
||||
Bazel is an open-source build and test tool similar to Make, Maven, and Gradle. It uses a human-readable, high-level build language. Bazel supports projects in multiple languages and builds outputs for multiple platforms. It's designed for fast, reliable, and reproducible builds, making it suitable for large codebases and complex projects. |
||||
|
||||
Visit the following resources to learn more: |
||||
|
||||
- [@article@Getting started with Bazel](https://bazel.build/start) |
||||
- [@article@Build Java Projects with Bazel](https://earthly.dev/blog/build-java-projects-with-bazel/) |
||||
- [@article@Introduction to the Bazel Build Tool](https://www.baeldung.com/bazel-build-tool) |
||||
|
@ -1 +1,8 @@ |
||||
# Classes and Objects |
||||
# Classes and Objects |
||||
|
||||
Classes are blueprints for creating objects, which are instances of those classes. A class defines the characteristics (attributes) and behaviors (methods) that objects of that class will possess. Think of a class as a template and an object as a specific instance created from that template. |
||||
|
||||
Visit the following resources to learn more: |
||||
|
||||
- [@article@Java Class and Objects](https://www.programiz.com/java-programming/class-objects) |
||||
- [@article@Java Classes and Objects](https://www.youtube.com/watch?v=IUqKuGNasdM) |
@ -1 +1,8 @@ |
||||
# Concurrency |
||||
# Concurrency |
||||
|
||||
Concurrency is the ability of a program to execute multiple tasks seemingly simultaneously. This doesn't necessarily mean they are running at the exact same instant, but rather that their execution overlaps in time. This can be achieved through techniques like multithreading, where a single program is divided into multiple threads that can run concurrently, or through asynchronous programming, where tasks can be started and then the program can continue executing other tasks without waiting for the first task to complete. |
||||
|
||||
Visit the following resources to learn more: |
||||
|
||||
- [@article@Java Concurrency and Multithreading Tutorial](https://jenkov.com/tutorials/java-concurrency/index.html) |
||||
- [@article@Java Concurrency in Practice](https://www.baeldung.com/java-concurrency) |
@ -1 +1,8 @@ |
||||
# Cryptography |
||||
# Cryptography |
||||
|
||||
Cryptography is the practice and study of techniques for secure communication in the presence of adversaries. It involves converting readable data (plaintext) into an unreadable format (ciphertext) through encryption, and then converting the ciphertext back into plaintext through decryption. Cryptography uses algorithms and keys to ensure confidentiality, integrity, authentication, and non-repudiation of information. |
||||
|
||||
Visit the following resources to learn more: |
||||
|
||||
- [@article@Java Cryptography Tutorial](https://jenkov.com/tutorials/java-cryptography/index.html) |
||||
|
||||
|
@ -1 +1,9 @@ |
||||
# Dependency Injection |
||||
# Dependency Injection |
||||
|
||||
Dependency Injection (DI) is a design pattern where objects receive their dependencies from external sources rather than creating them themselves. This means a class doesn't have to worry about how to obtain the objects it needs to function; instead, those objects are "injected" into the class, usually through its constructor, setter methods, or interface. This promotes loose coupling and makes code more testable and maintainable. |
||||
|
||||
Visit the following resources to learn more: |
||||
|
||||
- [@article@Dependency Injection Tutorial](https://jenkov.com/tutorials/dependency-injection/index.html) |
||||
- [@article@Java Dependency Injection Design Pattern Example Tutorial](https://www.digitalocean.com/community/tutorials/java-dependency-injection-design-pattern-example-tutorial) |
||||
|
||||
|
@ -1 +1,8 @@ |
||||
# Dequeue |
||||
# Dequeue |
||||
|
||||
A Dequeue (pronounced "dee-queue") is a double-ended queue, a data structure that allows you to add and remove elements from both the front (head) and the back (tail) of the queue. Unlike a regular queue (FIFO - First-In, First-Out), a dequeue provides flexibility for both FIFO and LIFO (Last-In, First-Out) operations. This makes it useful for implementing various algorithms and data management tasks where elements need to be accessed or modified from either end. |
||||
|
||||
Visit the following resources to learn more: |
||||
|
||||
- [@article@Java Deque Tutorial](https://jenkov.com/tutorials/java-collections/deque.html) |
||||
- [@article@Java Deque](https://www.programiz.com/java-programming/deque) |
||||
|
@ -1 +1,8 @@ |
||||
# Encapsulation |
||||
# Encapsulation |
||||
|
||||
Encapsulation is a fundamental concept in object-oriented programming where data and the methods that operate on that data are bundled together as a single unit. This unit, often a class, hides the internal state of the object from the outside world and only exposes a controlled interface for interacting with it. This protects the data from accidental modification and allows for easier maintenance and modification of the code. |
||||
|
||||
Visit the following resources to learn more: |
||||
|
||||
- [@article@Java - Encapsulation](https://www.tutorialspoint.com/java/java_encapsulation.htm) |
||||
|
||||
|
@ -1 +1,8 @@ |
||||
# Enums |
||||
# Enums |
||||
|
||||
Enums, short for enumerations, are a special data type in Java that represent a group of named constants. They allow you to define a type that can only take on a specific set of predefined values. This makes your code more readable and less prone to errors by restricting the possible values a variable can hold. |
||||
|
||||
Visit the following resources to learn more: |
||||
|
||||
- [@article@Java Enums](https://jenkov.com/tutorials/java/enums.html) |
||||
- [@article@Java Enums](https://www.programiz.com/java-programming/enums) |
||||
|
@ -1 +1,9 @@ |
||||
# Final Keyword |
||||
# Final Keyword |
||||
|
||||
The `final` keyword in Java is a non-access modifier used to apply restrictions on a variable, method, or class. When applied to a variable, it makes the variable's value constant after initialization. When applied to a method, it prevents the method from being overridden in a subclass. When applied to a class, it prevents the class from being subclassed (inherited). |
||||
|
||||
Visit the following resources to learn more: |
||||
|
||||
- [@article@Java Final Keyword](https://www.baeldung.com/java-final) |
||||
- [@article@How does the final keyword in Java work? I can still modify an object](https://stackoverflow.com/questions/15655012/how-does-the-final-keyword-in-java-work-i-can-still-modify-an-object) |
||||
|
||||
|
@ -1 +1,8 @@ |
||||
# Functional Composition |
||||
# Functional Composition |
||||
|
||||
Functional composition is the process of combining two or more functions to produce a new function. The resulting function applies each function in order, passing the output of one function as the input to the next. This allows you to build complex operations by chaining together simpler, reusable functions. |
||||
|
||||
Visit the following resources to learn more: |
||||
|
||||
- [@article@Functional Composition in Java](https://jenkov.com/tutorials/java-functional-programming/functional-composition.html) |
||||
- [@article@Java Functional Programming](https://www.baeldung.com/java-functional-programming) |
@ -1 +1,9 @@ |
||||
# Functional Interfaces |
||||
# Functional Interfaces |
||||
|
||||
Functional interfaces are interfaces that contain only one abstract method. They can have multiple default or static methods, but only one method that needs to be implemented. These interfaces can be used with lambda expressions and method references, allowing for concise and readable code when dealing with single-method operations. |
||||
|
||||
Visit the following resources to learn more: |
||||
|
||||
- [@article@Java Functional Interfaces](https://jenkov.com/tutorials/java-functional-programming/functional-interfaces.html) |
||||
- [@article@Java Functional Interfaces](https://www.baeldung.com/java-8-functional-interfaces) |
||||
|
||||
|
@ -1 +1,7 @@ |
||||
# High Order Functions |
||||
# High Order Functions |
||||
|
||||
High Order Functions are functions that can either accept other functions as arguments or return functions as their results. This capability allows for more flexible and reusable code by enabling you to abstract over operations. Essentially, you can pass behavior as data, making your code more dynamic and adaptable to different situations. |
||||
|
||||
Visit the following resources to learn more: |
||||
|
||||
- [@article@Java High Order Functions](https://jenkov.com/tutorials/java-functional-programming/higher-order-functions.html) |
@ -1 +1,8 @@ |
||||
# Inheritance |
||||
# Inheritance |
||||
|
||||
Inheritance is a fundamental concept in object-oriented programming where a new class (called a subclass or derived class) acquires properties and behaviors from an existing class (called a superclass or base class). This allows for code reuse and the creation of hierarchical relationships between classes, promoting a more organized and maintainable codebase. The subclass can extend the superclass by adding new attributes and methods or overriding existing ones. |
||||
|
||||
Visit the following resources to learn more: |
||||
|
||||
- [@article@Java Inheritance](https://jenkov.com/tutorials/java/inheritance.html) |
||||
- [@article@Inheritance in Java with Example](https://www.digitalocean.com/community/tutorials/inheritance-java-example) |
||||
|
@ -1 +1,9 @@ |
||||
# Initializer Block |
||||
# Initializer Block |
||||
|
||||
An initializer block in Java is a block of code, enclosed in curly braces `{}` , that is executed when an instance of a class is created. It's used to initialize instance variables or perform setup tasks before the constructor is called. There are two types: instance initializer blocks, which run every time a new object is created, and static initializer blocks, which run only once when the class is first loaded. |
||||
|
||||
Visit the following resources to learn more: |
||||
|
||||
- [@article@Static and Instance Initializer Blocks in Java](https://www.baeldung.com/java-static-instance-initializer-blocks) |
||||
- [@article@All About Java Instance Initializer Blocks](https://blogs.oracle.com/javamagazine/post/java-instance-initializer-block) |
||||
- [@article@What is an initialization block?](https://stackoverflow.com/questions/3987428/what-is-an-initialization-block) |
||||
|
@ -1 +1,8 @@ |
||||
# Interfaces |
||||
# Interfaces |
||||
|
||||
An interface in Java is a blueprint of a class. It specifies a set of methods that a class must implement if it claims to implement the interface. Think of it as a contract: any class that "signs" the contract (implements the interface) agrees to provide specific behaviors (methods). Interfaces can also contain constants (static final variables). They help achieve abstraction and multiple inheritance in Java. |
||||
|
||||
Visit the following resources to learn more: |
||||
|
||||
- [@article@Interfaces in Java](https://jenkov.com/tutorials/java/interfaces.html) |
||||
- [@article@A Guide to Java Interfaces](https://www.baeldung.com/java-interfaces) |
||||
|
@ -1 +1,7 @@ |
||||
# I/O Operations |
||||
# I/O Operations |
||||
|
||||
I/O Operations, short for Input/Output Operations, deal with how a program interacts with the outside world. This involves reading data from sources like files, network connections, or the keyboard, and writing data to destinations such as files, the console, or network sockets. Essentially, it's the mechanism by which a program receives information and sends results. |
||||
|
||||
Visit the following resources to learn more: |
||||
|
||||
- [@article@Java IO Tutorial](https://jenkov.com/tutorials/java-io/index.html) |
||||
|
@ -1 +1,8 @@ |
||||
# Iterator |
||||
# Iterator |
||||
|
||||
An Iterator is an object that enables you to traverse through a collection (like a List or Set) one element at a time. It provides a standard way to access elements sequentially without needing to know the underlying structure of the collection. You can use methods like `hasNext()` to check if there's a next element and `next()` to retrieve it. |
||||
|
||||
Visit the following resources to learn more: |
||||
|
||||
- [@article@Java Iterator Tutorial](https://jenkov.com/tutorials/java-collections/iterator.html) |
||||
- [@article@Java Iterable Tutorial](https://jenkov.com/tutorials/java-collections/iterable.html) |
||||
|
@ -1 +1,7 @@ |
||||
# Java Memory Model |
||||
# Java Memory Model |
||||
|
||||
The Java Memory Model (JMM) defines how threads in Java interact with memory. It specifies how and when different threads can see writes to shared variables, addressing issues like data visibility and race conditions in concurrent programs. The JMM ensures that multithreaded Java programs behave predictably across different hardware architectures by establishing rules for memory synchronization and ordering. |
||||
|
||||
Visit the following resources to learn more: |
||||
|
||||
- [@article@Java Memory Model](https://jenkov.com/tutorials/java-concurrency/java-memory-model.html) |
||||
|
@ -1 +1,9 @@ |
||||
# Javalin |
||||
# Javalin |
||||
|
||||
Javalin is a lightweight web framework for Java and Kotlin that's designed to be simple, intuitive, and fun to use. It allows developers to quickly build web applications and APIs with minimal boilerplate code. Javalin focuses on providing a straightforward approach to routing, request handling, and response generation, making it a good choice for projects where speed of development and ease of understanding are important. |
||||
|
||||
Visit the following resources to learn more: |
||||
|
||||
- [@official@Javalin Website](https://javalin.io/) |
||||
- [@article@Creating a REST API with Javalin](https://www.baeldung.com/javalin-rest-microservices) |
||||
|
||||
|
@ -1 +1,7 @@ |
||||
# Lambda Expressions |
||||
# Lambda Expressions |
||||
|
||||
Lambda expressions are essentially short blocks of code that you can pass around to be executed. They allow you to treat functionality as a method argument, or code as data. Think of them as anonymous methods – methods without a name – that can be written directly in the place where they are needed, making your code more concise and readable, especially when dealing with functional interfaces. |
||||
|
||||
Visit the following resources to learn more: |
||||
|
||||
- [@article@Java Lambda Expressions](https://jenkov.com/tutorials/java/lambda-expressions.html) |
||||
|
@ -1 +1,8 @@ |
||||
# Lifecycle of a Program |
||||
# Lifecycle of a Program |
||||
|
||||
In Java, the program lifecycle consists of several distinct phases that work together to execute code. The process begins with developers writing Java source code in `.java` files using an IDE or text editor. This code is then compiled by the Java compiler (javac) into bytecode stored in `.class` files, with syntax and type checking performed during compilation. When the program runs, the Java Virtual Machine (JVM) loads these compiled class files into memory through a process involving loading of binary data, linking for verification and preparation, and initialization of class elements. The JVM then verifies the bytecode's security compliance, performs Just-In-Time (JIT) compilation to translate bytecode into native machine code for better performance, and executes the program instructions while managing system resources. Throughout execution, the JVM handles garbage collection by reclaiming memory from unused objects, and finally releases all resources upon program termination. This architecture enables Java's "write once, run anywhere" capability since the bytecode can execute on any device with a compatible JVM. |
||||
|
||||
Visit the following resources to learn more: |
||||
|
||||
- [@article@Life Cycle of a Java Program](https://www.startertutorials.com/corejava/life-cycle-java-program.html) |
||||
- [@article@How the JVM Executes Java Code](https://www.cesarsotovalero.net/blog/how-the-jvm-executes-java-code.html) |
||||
|
@ -1 +1,10 @@ |
||||
# Map |
||||
# Map |
||||
|
||||
A Map is a data structure that stores data in key-value pairs. Each key is unique, and it maps to a specific value. Think of it like a dictionary where you use a word (the key) to look up its definition (the value). Maps allow you to efficiently retrieve, add, or remove values based on their associated keys. |
||||
|
||||
Visit the following resources to learn more: |
||||
|
||||
- [@article@Generic Map in Java](https://jenkov.com/tutorials/java-generics/generic-map.html) |
||||
- [@article@Java Map](https://jenkov.com/tutorials/java-collections/map.html) |
||||
- [@article@Java ConcurrentMap](https://jenkov.com/tutorials/java-util-concurrent/concurrentmap.html) |
||||
- [@article@Java SortedMap](https://jenkov.com/tutorials/java-collections/sortedmap.html) |
||||
|
@ -1 +1,7 @@ |
||||
# Math Operations |
||||
# Math Operations |
||||
|
||||
Math operations involve performing calculations using numbers. These operations include addition, subtraction, multiplication, division, and modulus (finding the remainder). They are fundamental building blocks for solving numerical problems and manipulating data in programming. |
||||
|
||||
Visit the following resources to learn more: |
||||
|
||||
- [@article@Java Math](https://jenkov.com/tutorials/java/math-operators-and-math-class.html) |
||||
|
@ -1 +1,8 @@ |
||||
# Method Chaining |
||||
# Method Chaining |
||||
|
||||
Method chaining is a programming technique where multiple method calls are made sequentially on the same object, one after another, in a single statement. Each method in the chain returns an object, allowing the next method to be called on that returned object. This approach enhances code readability and conciseness by reducing the need for temporary variables and intermediate steps. |
||||
|
||||
Visit the following resources to learn more: |
||||
|
||||
- [@article@Java Method Chaining - Java Explained](https://bito.ai/resources/java-method-chaining-java-explained) |
||||
- [@stackoverflow@How to achieve method chaining in Java](https://stackoverflow.com/questions/21180269/how-to-achieve-method-chaining-in-java) |
||||
|
@ -1 +1,8 @@ |
||||
# Method Overloading / Overriding |
||||
# Method Overloading and Overriding |
||||
|
||||
Method overloading allows you to define multiple methods in the same class with the same name but different parameters (different number, types, or order of parameters). Method overriding, on the other hand, occurs when a subclass provides a specific implementation for a method that is already defined in its superclass. The method signature (name and parameters) must be the same in both the superclass and the subclass for overriding to occur. |
||||
|
||||
Visit the following resources to learn more: |
||||
|
||||
- [@article@Overriding vs Overloading in Java](https://www.digitalocean.com/community/tutorials/overriding-vs-overloading-in-java) |
||||
- [@article@Java Inheritance Tutorial](https://jenkov.com/tutorials/java/inheritance.html) |
||||
|
@ -1 +1,8 @@ |
||||
# Modules |
||||
# Modules |
||||
|
||||
Modules in Java are a way to organize code into reusable and independent units. They provide a higher level of abstraction than packages, allowing you to control which parts of your code are exposed to other modules and which are kept private. This enhances encapsulation, improves security, and simplifies dependency management by explicitly declaring dependencies between modules. |
||||
|
||||
Visit the following resources to learn more: |
||||
|
||||
- [@article@Java Modules](https://jenkov.com/tutorials/java/modules.html) |
||||
- [@article@A Guide to Java 9 Modularity](https://www.baeldung.com/java-modularity) |
||||
|
@ -1 +1,8 @@ |
||||
# Nested Classes |
||||
# Nested Classes |
||||
|
||||
Nested classes are classes defined inside another class. The class that contains the inner class is known as the outer class. Nested classes can access members of the outer class, even if they are declared private. They are a way to logically group classes that are only used in one place, increasing encapsulation and maintainability. |
||||
|
||||
Visit the following resources to learn more: |
||||
|
||||
- [@article@Java Nested Classes](https://jenkov.com/tutorials/java/nested-classes.html) |
||||
- [@article@Guide to Nested Classes in Java](https://www.baeldung.com/java-nested-classes) |
||||
|
@ -1 +1,7 @@ |
||||
# Object Lifecycle |
||||
# Object Lifecycle |
||||
|
||||
The object lifecycle refers to the series of stages an object goes through from its creation (allocation of memory) to its destruction (reclaiming of memory). These stages typically include object creation, initialization, usage, and eventual garbage collection when the object is no longer needed. Understanding this lifecycle is crucial for efficient memory management and preventing resource leaks. |
||||
|
||||
Visit the following resources to learn more: |
||||
|
||||
- [@article@Object Life Cycle in Java](https://www.tpointtech.com/object-life-cycle-in-java) |
||||
|
@ -1 +1,8 @@ |
||||
# Optionals |
||||
# Optionals |
||||
|
||||
Optionals are a container object that may or may not contain a non-null value. They are primarily used to represent the absence of a value, avoiding the need to return null, which can lead to NullPointerExceptions. Optionals provide methods to explicitly check if a value is present and to handle cases where a value is absent in a more controlled and readable manner. |
||||
|
||||
Visit the following resources to learn more: |
||||
|
||||
- [@article@Guide To Optionals](https://www.baeldung.com/java-optional) |
||||
- [@article@Java Optional](https://dzone.com/articles/optional-in-java) |
||||
|
@ -1 +1,8 @@ |
||||
# Pass by Value / Pass by Reference |
||||
# Pass by Value / Pass by Reference |
||||
|
||||
Pass by value and pass by reference are two different ways of passing arguments to a function or method. In pass by value, a copy of the variable's value is passed to the function, so any changes made to the parameter inside the function do not affect the original variable. In pass by reference, a direct reference to the variable is passed, meaning that changes made to the parameter inside the function will directly affect the original variable. |
||||
|
||||
Visit the following resources to learn more: |
||||
|
||||
- [@article@Java is Pass-by-Value, Not Pass-by-Reference](https://www.baeldung.com/java-pass-by-value-or-pass-by-reference) |
||||
- [@article@Is Java "pass-by-reference" or "pass-by-value"?](https://stackoverflow.com/questions/40480/is-java-pass-by-reference-or-pass-by-value) |
@ -1 +1,7 @@ |
||||
# Queue |
||||
# Queue |
||||
|
||||
A queue is a fundamental data structure that follows the First-In, First-Out (FIFO) principle. Think of it like a line at a store: the first person to join the line is the first person to be served. Elements are added to the rear (enqueue) and removed from the front (dequeue) of the queue. |
||||
|
||||
Visit the following resources to learn more: |
||||
|
||||
- [@article@Java Queue](https://jenkov.com/tutorials/java-collections/queue.html) |
||||
|
@ -1 +1,8 @@ |
||||
# Record |
||||
# Record |
||||
|
||||
A record is a special type of class in Java that is designed to hold immutable data. It automatically generates methods like `equals()`, `hashCode()`, and `toString()` based on the components declared in its header, reducing boilerplate code. Records are useful for creating data transfer objects (DTOs) or simple data aggregates where the primary purpose is to store and access data. |
||||
|
||||
Visit the following resources to learn more: |
||||
|
||||
- [@article@Java Records](https://jenkov.com/tutorials/java/record.html) |
||||
- [@video@Java Records](https://www.youtube.com/watch?v=xs7DiEIHW0U) |
||||
|
@ -1 +1,7 @@ |
||||
# Regular Expressions |
||||
# Regular Expressions |
||||
|
||||
Regular expressions, often shortened to "regex," are sequences of characters that define a search pattern. These patterns are used to match character combinations in strings. They can be used to search, edit, or manipulate text and data. Regular expressions provide a powerful and flexible way to work with text-based data. |
||||
|
||||
Visit the following resources to learn more: |
||||
|
||||
- [@article@Java Regular Expressions Tutorial](https://jenkov.com/tutorials/java-regex/index.html) |
||||
|
@ -1 +1,8 @@ |
||||
# Set |
||||
# Set |
||||
|
||||
A Set is a data structure that stores a collection of unique elements. This means that no duplicate values are allowed within a Set. Sets provide efficient ways to check for membership (if an element exists in the set) and perform operations like union, intersection, and difference. |
||||
|
||||
Visit the following resources to learn more: |
||||
|
||||
- [@article@Java Set](https://jenkov.com/tutorials/java-collections/set.html) |
||||
- [@article@Java Set Interface and Implementation](https://www.digitalocean.com/community/tutorials/java-set) |
||||
|
@ -1 +1,8 @@ |
||||
# Stack |
||||
# Stack |
||||
|
||||
A stack is a fundamental data structure that follows the Last-In, First-Out (LIFO) principle. Imagine a stack of plates; you can only add or remove plates from the top. This means the last element added to the stack is the first one to be removed. Stacks are used to manage function calls, evaluate expressions, and implement undo/redo functionality. |
||||
|
||||
Visit the following resources to learn more: |
||||
|
||||
- [@article@Java Stack Tutorial](https://jenkov.com/tutorials/java-collections/stack.html) |
||||
- [@article@Guide to Java Stack](https://www.baeldung.com/java-stack) |
||||
|
@ -1 +1,9 @@ |
||||
# Static Keyword |
||||
# Static Keyword |
||||
|
||||
The `static` keyword in Java is used to create members (variables and methods) that belong to the class itself, rather than to any specific instance of the class. This means there's only one copy of a static variable shared by all objects of that class, and you can access static members directly using the class name without needing to create an object. Static methods can only access static variables and call other static methods. |
||||
|
||||
Visit the following resources to learn more: |
||||
|
||||
- [@article@Java Static Keyword Explained With Examples](https://www.freecodecamp.org/news/java-static-keyword-explained/) |
||||
- [@article@Static and Non-static Fields in Java](https://jenkov.com/tutorials/java/fields.html#static-and-non-static-fields) |
||||
- [@article@Guide to the Java 'static' Keyword](https://www.baeldung.com/java-static) |
||||
|
@ -1 +1,8 @@ |
||||
# Static vs Dynamic Binding |
||||
# Static vs Dynamic Binding |
||||
|
||||
Static binding, also known as early binding, happens at compile time. The compiler knows exactly which method will be called based on the type of the variable. Dynamic binding, or late binding, occurs at runtime. The specific method to be called is determined based on the actual object type, not the variable type, allowing for more flexibility and polymorphism. |
||||
|
||||
Visit the following resources to learn more: |
||||
|
||||
- [@article@Static and Dynamic Binding in Java](https://www.baeldung.com/java-static-dynamic-binding) |
||||
- [@article@Static and Dynamic Binding in Java with Examples](https://beginnersbook.com/2013/04/java-static-dynamic-binding/) |
||||
|
@ -1 +1,7 @@ |
||||
# Strings and Methods |
||||
# Strings and Methods |
||||
|
||||
Strings are sequences of characters, like words or sentences, used to represent text in programming. Methods are actions you can perform on these strings, such as finding their length, changing their case (uppercase or lowercase), or extracting parts of them. These methods allow you to manipulate and work with text data effectively. |
||||
|
||||
Visit the following resources to learn more: |
||||
|
||||
- [@article@Java Strings](https://jenkov.com/tutorials/java/strings.html) |
||||
|
@ -1 +1,8 @@ |
||||
# Type Casting |
||||
# Type Casting |
||||
|
||||
Type casting is the process of converting a variable from one data type to another. This is often necessary when you need to perform operations between variables of different types, or when you need to store a value of one type in a variable of another type. In Java, type casting can be either implicit (automatic) or explicit (requiring a cast operator). |
||||
|
||||
Visit the following resources to learn more: |
||||
|
||||
- [@article@Type Casting in Java: Everything You Need to Know](https://www.simplilearn.com/tutorials/java-tutorial/type-casting-in-java) |
||||
- [@article@Java Type Casting (With Examples)](https://www.programiz.com/java-programming/typecasting) |
||||
|
@ -1 +1,8 @@ |
||||
# Variables and Scopes |
||||
# Variables and Scopes |
||||
|
||||
Variables are like containers that hold data in a program. Each variable has a name, a type (like integer, text, or boolean), and a value. The scope of a variable determines where in your code you can access and use that variable. Understanding scope is crucial to avoid naming conflicts and ensure data is accessed correctly within different parts of your program. |
||||
|
||||
Visit the following resources to learn more: |
||||
|
||||
- [@article@Java Variables](https://jenkov.com/tutorials/java/variables.html) |
||||
- [@article@Java Variable Scope](https://www.baeldung.com/java-variable-scope) |
||||
|
@ -1 +1,9 @@ |
||||
# Virtual Threads |
||||
# Virtual Threads |
||||
|
||||
Virtual Threads are lightweight threads managed by the Java Virtual Machine (JVM). Unlike traditional operating system threads, which are relatively expensive to create and manage, virtual threads are designed to be extremely lightweight, allowing for the creation of millions of them. They are intended to improve the scalability and concurrency of Java applications by making it easier to write code that can handle a large number of concurrent operations without the overhead associated with traditional threads. |
||||
|
||||
Visit the following resources to learn more: |
||||
|
||||
- [@article@Java 21 Virtual Threads: Dude, Where's My Lock?](https://netflixtechblog.com/java-21-virtual-threads-dude-wheres-my-lock-3052540e231d) |
||||
- [@article@Virtual Thread vs Thread in Java](https://www.baeldung.com/java-virtual-thread-vs-thread) |
||||
- [@article@The Ultimate Guide to Java Virtual Threads](https://rockthejvm.com/articles/the-ultimate-guide-to-java-virtual-threads) |
||||
|
@ -1 +1,8 @@ |
||||
# volatile keyword |
||||
# Volatile Keyword |
||||
|
||||
The `volatile` keyword in Java is a modifier that can be applied to instance variables. It ensures that all threads see the most up-to-date value of a variable. Without `volatile`, each thread might cache its own copy of the variable, leading to inconsistencies when multiple threads access and modify it concurrently. Using `volatile` forces the thread to read the variable's value directly from main memory, and write changes directly back to main memory, bypassing the thread's local cache. |
||||
|
||||
Visit the following resources to learn more: |
||||
|
||||
- [@article@Java Volatile Keyword](https://jenkov.com/tutorials/java-concurrency/volatile.html) |
||||
- [@article@Guide to the Volatile Keyword in Java](https://www.baeldung.com/java-volatile) |
||||
|
Loading…
Reference in new issue