diff --git a/tutorials/learn-html.org/en/CSS Variables.md b/tutorials/learn-html.org/en/CSS Variables.md index a332cc34d..7a3f13bf4 100644 --- a/tutorials/learn-html.org/en/CSS Variables.md +++ b/tutorials/learn-html.org/en/CSS Variables.md @@ -1,51 +1,63 @@ -Tutorial --------- - -This page is empty. You are welcome to contribute the content by sending me a pull request: - -[[https://github.com/ronreiter/interactive-tutorials]] - -Exercise --------- - -This page does not have an exercise yet. You are welcome to contribute one by sending me a pull request: - -[[https://github.com/ronreiter/interactive-tutorials]] - - -Tutorial Code -------------- - - - - - - - - - -Expected Output ---------------- - - - - - Hello, World! - - -

Hello, World!

- - - -Solution --------- - - - - - Hello, World! - - -

Hello, World!

- - +# CSS Variables: Enhancing Styling Flexibility + +Cascading Style Sheets (CSS) have come a long way in providing developers with powerful tools to style web pages. One of the most significant additions to CSS in recent years is the introduction of CSS variables, also known as custom properties. CSS variables allow developers to define reusable values that can be used throughout their stylesheets, providing greater flexibility and maintainability in styling web applications. + +## What are CSS Variables? + +CSS variables are named values that can be reused throughout a CSS stylesheet. They are defined using the `--` prefix followed by a name and assigned a value. For example: + +```css +:root { + --primary-color: #007bff; + --secondary-color: #6c757d; +} +``` + +In this example, we define two CSS variables, `--primary-color` and `--secondary-color`, with corresponding color values. The `:root` pseudo-class is used to define variables at the root level of the document, making them available globally within the stylesheet. + +## Using CSS Variables + +Once defined, CSS variables can be used anywhere in your stylesheet by referencing their names. For example: + +```css +body { + background-color: var(--primary-color); + color: var(--secondary-color); +} +``` + +In this example, we use the `var()` function to reference the `--primary-color` and `--secondary-color` variables, setting the background color of the `body` element to the primary color and the text color to the secondary color. + +CSS variables can also be scoped to specific elements or selectors, allowing for more granular control over styling. For example: + +```css +.card { + --card-background: #f8f9fa; + background-color: var(--card-background); +} +``` + +In this example, we define a CSS variable `--card-background` within the `.card` selector, which sets the background color for all elements with the `.card` class. + +## Benefits of CSS Variables + +CSS variables offer several advantages over traditional CSS styling methods: + +1. **Reusable Values:** CSS variables allow developers to define values once and reuse them throughout their stylesheets, reducing repetition and improving maintainability. + +2. **Dynamic Styling:** CSS variables can be updated dynamically using JavaScript, allowing developers to create dynamic and interactive user interfaces without modifying the underlying CSS. + +3. **Scoped Styling:** CSS variables can be scoped to specific elements or selectors, providing greater control over styling and reducing the risk of unintended side effects. + +4. **Consistent Design Systems:** CSS variables enable the creation of consistent design systems by centralizing style definitions and promoting reuse across multiple components and layouts. + +## Browser Support + +CSS variables are supported in all modern web browsers, including Chrome, Firefox, Safari, Edge, and Opera. However, support for older versions of Internet Explorer (IE) is limited or nonexistent. To ensure compatibility with older browsers, developers can use CSS preprocessors like Sass or Less, which offer similar functionality and compile down to standard CSS. + +--- +**References:** + +- [MDN Web Docs: CSS Variables](https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties) + +--- diff --git a/tutorials/learn-html.org/en/Grid Layout.md b/tutorials/learn-html.org/en/Grid Layout.md index 55f267d55..c24c23624 100644 --- a/tutorials/learn-html.org/en/Grid Layout.md +++ b/tutorials/learn-html.org/en/Grid Layout.md @@ -3,51 +3,87 @@ Tutorial The "Grid Layout" is a concept used for designing websites using HTML and CSS. The basic concept of a grid allows us to build an HTML page by using rows as the basic blocks, and each row can be divided into up to 12 columns. - -This tutorial is incomplete. You are welcome to contribute one by sending me a pull request: + +You are welcome to contribute one by sending me a pull request: [[https://github.com/ronreiter/interactive-tutorials]] Exercise -------- -This page does not have an exercise yet. You are welcome to contribute one by sending me a pull request: - -[[https://github.com/ronreiter/interactive-tutorials]] - +You can practice exercises here. [[https://github.com/yusuf7861?tab=repositories]] Tutorial Code ------------- +```bash + + + + + + + + Grid Layout tutorial + + + + +
+
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Iste, pariatur quis cum unde porro sequi, odit itaque officia
+
Item2
+
Item3
+
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Omnis voluptatibus dolore qui natus nam voluptates, harum hic ipsa laudantium suscipit et itaque corrupti perferendis quaerat possimus, labore maxime odit ipsum!
+
Item5
+
Item6
+
Item7
+
Item8
+
Item9
+
+ + +``` + Expected Output --------------- - - - - Hello, World! - - -

Hello, World!

- - - -Solution --------- +![Grid Layout](https://i.postimg.cc/3RY1KmdH/Grid.jpg) - - - - Hello, World! - - -

Hello, World!

- - diff --git a/tutorials/learnjavaonline.org/en/JavaDoc.md b/tutorials/learnjavaonline.org/en/JavaDoc.md new file mode 100644 index 000000000..69d4a82e8 --- /dev/null +++ b/tutorials/learnjavaonline.org/en/JavaDoc.md @@ -0,0 +1,149 @@ + +# What is Javadoc? +Javadoc is a tool which comes with JDK and it is used for generating Java code documentation in HTML format from Java source code, which requires documentation in a predefined format. + +Following is a simple example where the lines inside /*….*/ are Java multi-line comments. Similarly, the line which preceeds // is Java single-line comment. +```java +/** +* The HelloWorld program implements an application that +* simply displays "Hello World!" to the standard output. +* +* @author Zara Ali +* @version 1.0 +* @since 2014-03-31 +*/ +public class HelloWorld { + public static void main(String[] args) { + // Prints Hello, World! on standard output. + System.out.println("Hello World!"); + } +} +``` +## Output: +```sh +Hello World! +``` + +# The javadoc Tags: +The javadoc tool recognizes the following tags: +| Tag | Description | Syntax | +| ---- | ------- | -------- | +| @author | Adds the author of a class. | @author name-text | +| {@code} | Display text in code font without interpreting the text as HTML markup or nested javadoc tags. | {@code text} | +| {@docRoot} | Represents the relative path to the generated document's root directory from any generated page. | {@docRoot} | +| @deprected | Adds a comment indicating that this API should no longer be used. | @deprecated deprecatedtext | +| @exception | Adds a Throws subheading to the generated documentation, with the classname and description text. | @exception class-name description | +| {@inheritDoc} | Inherits a comment from the nearest inheritable class or implementable interface. | Inherits a comment from the immediate surperclass. | +| {@link} | Inserts an in-line link with the visible text label that points to the documentation for the specified package, class, or member name of a referenced class. | {@link package.class#member label} | +| {@linkplain} | Identical to {@link}, except the link's label is displayed in plain text than code font. | {@linkplain package.class#member label} | +| @param | Adds a parameter with the specified parameter-name followed by the specified description to the "Parameters" section. | @param parameter-name description | +| @return | Adds a "Returns" section with the description text. | @return description | +| @see | Adds a "See Also" heading with a link or text entry that points to reference.| @see reference | +| @serial | Used in the doc comment for a default serializable field. | @serial field-description include exclude | +| @serialData | Documents the data written by the writeObject( ) or writeExternal( ) methods. | @serialData data-description | +| @serialField | Documents an ObjectStreamField component. | @serialField field-name field-type field-description | +|@since|Adds a "Since" heading with the specified since-text to the generated documentation.| @since release | +|@throws| The @throws and @exception tags are synonyms.| @throws class-name description| +|{@value} | When {@value} is used in the doc comment of a static field, it displays the value of that constant. | {@value package.class#field} | +| @version | Adds a "Version" subheading with the specified version-text to the generated docs when the -version option is used. | @version version-text | + +If you are using JDK 1.7 then javadoc does not generate a great stylesheet.css, so we suggest to download and use standard stylesheet from https://docs.oracle.com + +```java +/** + * @version 21.0 + * since 2024 + * @author yjama + */ +package JavaDoc; + +/** + * + * @author yjama + * + * Class for Library Book + */ +public class Book { + /** + * @value 10 default value + */ + static int val = 10; + + /** + * Parametrized Constructor + * @param s Book Name + */ + public Book(String s) { + } + + /** + * Issue a Book to a student + * @param roll roll number of a student + * @throws Exception if book is not available, throws Exception + */ + + public void issue(int roll) throws Exception { + } + /** + * check if book is available or not + * @param str Book name + * @return if book is available returns true else false + */ + public boolean available(String str){ + return true; + } + + /** + * Get Book name + * @param id book id + * @return returns book name + */ + public String getName(int id){ + return ""; + } + + /** + * Main Method starts here + * @param args + */ + public static void main(String[] args) { + + } +} +``` + + + +## Output: +[https://ibb.co/NsZ2xmB] +[https://ibb.co/d7wZMJc] +[https://ibb.co/PmWjZVg] + +## Generating Javadoc for a Java File + +Follow these steps to generate Javadoc for your Java file: + +1. **Open Terminal or Command Prompt:** + Open a terminal (on macOS or Linux) or Command Prompt (on Windows) on your computer. + +2. **Navigate to the Directory Containing Your Java File:** + Use the `cd` command to navigate to the directory that contains your Java file. Replace `path/to/your/directory` with the actual path. For example: + ```bash + cd path/to/your/directory + ``` + +3. **Generate javadoc:** + Run the javadoc command followed by the name of your Java file or package. For example: + ```bash + javadoc YourClaas.java + ``` + If your Java file is part of a package, specify the package name instead of the file name: + ```bash + javadoc your/package/name + ``` + +4. **View the generated javadoc:** + Once the Javadoc generation process is complete, you'll see a new directory named `docs` in your current directory. Open the `index.html` file located inside the docs directory in a web browser to view the generated Javadoc. + + That's it! You've successfully generated Javadoc for your Java file. + diff --git a/tutorials/learnjavaonline.org/en/LambdaExpression.md b/tutorials/learnjavaonline.org/en/LambdaExpression.md new file mode 100644 index 000000000..def0b900a --- /dev/null +++ b/tutorials/learnjavaonline.org/en/LambdaExpression.md @@ -0,0 +1,117 @@ +# Lambda Expression in Java +In Java, a lambda expression is a concise way to represent an anonymous function—a method without a name. It provides a way to pass functionality as an argument to other methods or to create simple implementations of functional interfaces. + +Lambda expressions are particularly useful when working with functional interfaces, which have only one abstract method. They allow you to write shorter and more readable code by reducing boilerplate code, especially when dealing with simple operations or callbacks. + +[![Lambda Expression](https://i.ibb.co/S0fxQ7h/lambda-expression.jpg)](https://ibb.co/bLb3HRS) + +## Lambda Expression Syntax: +```bash +lambda operator -> body +``` + +## Example of Lambda Expression +```bash +package LambdaExpression; +/** + * This program demonstrates the usage of lambda expressions in Java. + */ + +@FunctionalInterface +interface MyLambda1 { + // Method to add two numbers + public int add(int x, int y); // Lambda expressions can take multiple parameters +} + +public class LambdaExample { + public static void main(String[] args) { + // Lambda expression to add two numbers + MyLambda1 m1 = (a, b) -> a + b; // Lambda expressions do not require 'return' keyword and type of the variable + + // Display the result of adding two numbers + System.out.println(m1.add(10, 10)); + } +} +``` + + +## Lambda Expression Parameters +There are three Lambda Expression Parameters are mentioned below: +- 1. Zero Parameter +- 2. Single Parameter +- 3. Multiple Parameters + +## 1. Lambda Expression with Zero parameter +```bash +() -> System.out.println("Zero parameter lambda"); +``` +### Example +```bash +// Functional interface with zero parameters +interface ZeroParamLambda { + void display(); +} + +public class ZeroParamLambdaExample { + public static void main(String[] args) { + // Lambda expression with zero parameters + ZeroParamLambda zeroParamLambda = () -> { + System.out.println("Lambda expression with zero parameters executed"); + }; + zeroParamLambda.display(); + } +} +``` + +## 2. Lambda Expression with Single parameter +```bash +(p) -> System.out.println("One parameter: " + p); +``` +> Note: It is not mandatory to use parentheses if the type of that variable can be inferred from the context. +### Example: +```bash +// Functional interface with single parameter +interface SingleParamLambda { + int square(int x); +} + +public class SingleParamLambdaExample { + public static void main(String[] args) { + // Lambda expression with single parameter + SingleParamLambda singleParamLambda = (int x) -> { + return x * x; + }; + int result = singleParamLambda.square(5); + System.out.println("Square of 5 is: " + result); + } +} +``` + +## 3. Lambda Expression with Multiple parameters +```bash +(p1, p2) -> System.out.println("Multiple parameters: " + p1 + ", " + p2); +``` +### Example: +```bash +// Functional interface with multiple parameters +interface MultiParamLambda { + int add(int a, int b); +} + +public class MultiParamLambdaExample { + public static void main(String[] args) { + // Lambda expression with multiple parameters + MultiParamLambda multiParamLambda = (int a, int b) -> { + return a + b; + }; + int sum = multiParamLambda.add(10, 20); + System.out.println("Sum of 10 and 20 is: " + sum); + } +} + +``` + +## Rules for the body of a lambda expression +- The body of the lambda expression can be either a single expression or more statements. +- If we are using a single expression as the body of a lambda expression, then no need to enclose the body with curly braces ({}). +- If we are using one or more statements as the body of a lambda expression, then enclosing them within curly braces({}) can be mandatory. \ No newline at end of file