🎉 Java Learning Series: Day 13! 🎉
Hello, Java learners! Today, we're diving into the heart of Java: **Object-Oriented Programming (OOP)**! 🚀 Get ready to understand the magic behind `Classes` and `Objects`.
Think of a `Class` as a blueprint or a template for creating something. It defines what attributes (data) and behaviors (methods) that "thing" will have. An `Object`, on the other hand, is a real-world instance of that class. You can create many objects from a single blueprint, each with its unique state but sharing the same defined behaviors. This concept brings structure, reusability, and modularity to your code! 🏗️💡
Let's see an example with a `Dog` class and its objects! 🐕🦺
```java
// Define a Class: Dog
class Dog {
// Attributes (properties) of a Dog
String name;
String breed;
// Constructor: A special method to create Dog objects
public Dog(String name, String breed) {
this.name = name;
this.breed = breed;
}
// Methods (behaviors) of a Dog
public void bark() {
System.out.println(name + " says Woof! Woof!");
}
public void displayInfo() {
System.out.println("Name: " + name + ", Breed: " + breed);
}
}
public class Day13_OOP {
public static void main(String[] args) {
// Create Objects (instances) of the Dog class
Dog myDog = new Dog("Buddy", "Golden Retriever"); // myDog is an object
Dog neighborDog = new Dog("Max", "German Shepherd"); // neighborDog is another object
// Access attributes and call methods on these objects
System.out.println("--- My Dog ---");
myDog.displayInfo();
myDog.bark();
System.out.println("n--- Neighbor's Dog ---");
neighborDog.displayInfo();
neighborDog.bark();
// Each object has its own unique data
// System.out.println(myDog.name); // Buddy
// System.out.println(neighborDog.name); // Max
}
}
```
Output example:
```
--- My Dog ---
Name: Buddy, Breed: Golden Retriever
Buddy says Woof! Woof!
--- Neighbor's Dog ---
Name: Max, Breed: German Shepherd
Max says Woof! Woof!
```
---
### Small Challenge:
Can you modify the `Dog` class to include an additional attribute like `age` (an `int`) and a new method called `play()` that prints "[Dog's Name] is playing fetch!"? Don't forget to update the constructor and create a new dog object with an age! 🐾🧠
Happy coding, and see you tomorrow! 👋
---
Hello, Java learners! Today, we're diving into the heart of Java: **Object-Oriented Programming (OOP)**! 🚀 Get ready to understand the magic behind `Classes` and `Objects`.
Think of a `Class` as a blueprint or a template for creating something. It defines what attributes (data) and behaviors (methods) that "thing" will have. An `Object`, on the other hand, is a real-world instance of that class. You can create many objects from a single blueprint, each with its unique state but sharing the same defined behaviors. This concept brings structure, reusability, and modularity to your code! 🏗️💡
Let's see an example with a `Dog` class and its objects! 🐕🦺
```java
// Define a Class: Dog
class Dog {
// Attributes (properties) of a Dog
String name;
String breed;
// Constructor: A special method to create Dog objects
public Dog(String name, String breed) {
this.name = name;
this.breed = breed;
}
// Methods (behaviors) of a Dog
public void bark() {
System.out.println(name + " says Woof! Woof!");
}
public void displayInfo() {
System.out.println("Name: " + name + ", Breed: " + breed);
}
}
public class Day13_OOP {
public static void main(String[] args) {
// Create Objects (instances) of the Dog class
Dog myDog = new Dog("Buddy", "Golden Retriever"); // myDog is an object
Dog neighborDog = new Dog("Max", "German Shepherd"); // neighborDog is another object
// Access attributes and call methods on these objects
System.out.println("--- My Dog ---");
myDog.displayInfo();
myDog.bark();
System.out.println("n--- Neighbor's Dog ---");
neighborDog.displayInfo();
neighborDog.bark();
// Each object has its own unique data
// System.out.println(myDog.name); // Buddy
// System.out.println(neighborDog.name); // Max
}
}
```
Output example:
```
--- My Dog ---
Name: Buddy, Breed: Golden Retriever
Buddy says Woof! Woof!
--- Neighbor's Dog ---
Name: Max, Breed: German Shepherd
Max says Woof! Woof!
```
---
### Small Challenge:
Can you modify the `Dog` class to include an additional attribute like `age` (an `int`) and a new method called `play()` that prints "[Dog's Name] is playing fetch!"? Don't forget to update the constructor and create a new dog object with an age! 🐾🧠
Happy coding, and see you tomorrow! 👋
---
Which of the following best describes an 'object' in Java?
Anonymous Quiz
9%
A blueprint or template for creating data structures.
82%
An instance of a class, representing a real-world entity with its own state and behaviors.
9%
A method that defines a specific action or task within a program.
0%
A special type of variable used to store multiple values of the same type.
Here's your Telegram post for Day 14! 🚀
---
Hey Java learners! 👋 It's Day 14, and we're diving deep into two of the most fundamental concepts in Object-Oriented Programming (OOP): **Inheritance** and **Polymorphism**! 🧬
These powerful principles are key to writing reusable, flexible, and scalable code. Inheritance allows classes to inherit properties and methods from other classes, saving you from writing redundant code. Polymorphism, on the other hand, lets objects take on many forms, enabling you to treat objects of different classes in a unified way. 🏗️
Let's see them in action with an example using shapes! 👇
```java
// Parent class representing a generic shape
class Shape {
public double calculateArea() {
System.out.println("Calculating area for a generic shape.");
return 0; // Default implementation
}
}
// Child class: Circle inherits from Shape
class Circle extends Shape {
private double radius;
public Circle(double radius) {
this.radius = radius;
}
// Method overriding: providing a specific implementation for Circle
@Override
public double calculateArea() {
return Math.PI * radius * radius;
}
}
// Child class: Rectangle inherits from Shape
class Rectangle extends Shape {
private double length;
private double width;
public Rectangle(double length, double width) {
this.length = length;
this.width = width;
}
// Method overriding: providing a specific implementation for Rectangle
@Override
public double calculateArea() {
return length * width;
}
}
public class Day14Demo {
public static void main(String[] args) {
// Polymorphism in action:
// A Shape reference can point to a Circle or Rectangle object
Shape circle = new Circle(5.0);
Shape rectangle = new Rectangle(4.0, 6.0);
Shape genericShape = new Shape(); // Can also instantiate the parent
System.out.println("Area of Circle: " + circle.calculateArea());
System.out.println("Area of Rectangle: " + rectangle.calculateArea());
System.out.print("Generic Shape action: ");
System.out.println("Area of Generic Shape: " + genericShape.calculateArea());
}
}
```
Output example:
```
Area of Circle: 78.53981633974483
Area of Rectangle: 24.0
Generic Shape action: Calculating area for a generic shape.
Area of Generic Shape: 0.0
```
**Small challenge for you!** 🤔
Can you add another shape, like a `Triangle`? 🔺 Make it inherit from `Shape` and override the `calculateArea()` method to return its specific area. Then, add an instance of your `Triangle` to the `main` method and calculate its area! Show off your inheritance and polymorphism skills! 💪
---
---
Hey Java learners! 👋 It's Day 14, and we're diving deep into two of the most fundamental concepts in Object-Oriented Programming (OOP): **Inheritance** and **Polymorphism**! 🧬
These powerful principles are key to writing reusable, flexible, and scalable code. Inheritance allows classes to inherit properties and methods from other classes, saving you from writing redundant code. Polymorphism, on the other hand, lets objects take on many forms, enabling you to treat objects of different classes in a unified way. 🏗️
Let's see them in action with an example using shapes! 👇
```java
// Parent class representing a generic shape
class Shape {
public double calculateArea() {
System.out.println("Calculating area for a generic shape.");
return 0; // Default implementation
}
}
// Child class: Circle inherits from Shape
class Circle extends Shape {
private double radius;
public Circle(double radius) {
this.radius = radius;
}
// Method overriding: providing a specific implementation for Circle
@Override
public double calculateArea() {
return Math.PI * radius * radius;
}
}
// Child class: Rectangle inherits from Shape
class Rectangle extends Shape {
private double length;
private double width;
public Rectangle(double length, double width) {
this.length = length;
this.width = width;
}
// Method overriding: providing a specific implementation for Rectangle
@Override
public double calculateArea() {
return length * width;
}
}
public class Day14Demo {
public static void main(String[] args) {
// Polymorphism in action:
// A Shape reference can point to a Circle or Rectangle object
Shape circle = new Circle(5.0);
Shape rectangle = new Rectangle(4.0, 6.0);
Shape genericShape = new Shape(); // Can also instantiate the parent
System.out.println("Area of Circle: " + circle.calculateArea());
System.out.println("Area of Rectangle: " + rectangle.calculateArea());
System.out.print("Generic Shape action: ");
System.out.println("Area of Generic Shape: " + genericShape.calculateArea());
}
}
```
Output example:
```
Area of Circle: 78.53981633974483
Area of Rectangle: 24.0
Generic Shape action: Calculating area for a generic shape.
Area of Generic Shape: 0.0
```
**Small challenge for you!** 🤔
Can you add another shape, like a `Triangle`? 🔺 Make it inherit from `Shape` and override the `calculateArea()` method to return its specific area. Then, add an instance of your `Triangle` to the `main` method and calculate its area! Show off your inheritance and polymorphism skills! 💪
---
🚀 Day 15: Dive into Java Libraries! 📚 Today, we unlock the power of `java.util` and `java.io`! These essential packages provide a vast collection of utility classes and robust tools for handling input/output operations. From data structures like `ArrayList` and `HashMap` in `java.util` to file manipulation with `FileReader` and `FileWriter` in `java.io`, you'll see how these libraries simplify complex tasks. Get ready to supercharge your Java applications! 💡📁
```java
import java.util.Scanner; // Part of java.util for input
import java.io.FileWriter; // Part of java.io for writing files
import java.io.FileReader; // Part of java.io for reading files
import java.io.BufferedReader; // Part of java.io for efficient reading
import java.io.IOException; // For handling I/O exceptions
public class LibraryDemo {
public static void main(String[] args) {
String fileName = "greeting.txt";
// --- Demonstrating java.util.Scanner for console input ---
System.out.print("Enter a greeting message: ");
try (Scanner scanner = new Scanner(System.in)) {
String message = scanner.nextLine();
// --- Demonstrating java.io.FileWriter for writing to a file ---
try (FileWriter writer = new FileWriter(fileName)) { // try-with-resources ensures writer is closed
writer.write(message);
System.out.println("✅ Message successfully written to " + fileName);
} catch (IOException e) {
System.err.println("❌ Error writing to file: " + e.getMessage());
}
// --- Demonstrating java.io.FileReader and BufferedReader for reading from a file ---
try (FileReader fileReader = new FileReader(fileName);
BufferedReader bufferedReader = new BufferedReader(fileReader)) {
String line = bufferedReader.readLine();
System.out.println("📖 Content read from " + fileName + ": " + line);
} catch (IOException e) {
System.err.println("❌ Error reading from file: " + e.getMessage());
}
}
}
}
```
Output example:
```
Enter a greeting message: Hello from Day 15!
✅ Message successfully written to greeting.txt
📖 Content read from greeting.txt: Hello from Day 15!
```
✨ **Your Challenge:** Modify the `FileWriter` part of the code to append a *second* line of text (e.g., "Keep learning Java!") to `greeting.txt` *without* overwriting the first line. (Hint: Look for overloaded `FileWriter` constructors that accept a boolean argument for appending!) 📝
---
```java
import java.util.Scanner; // Part of java.util for input
import java.io.FileWriter; // Part of java.io for writing files
import java.io.FileReader; // Part of java.io for reading files
import java.io.BufferedReader; // Part of java.io for efficient reading
import java.io.IOException; // For handling I/O exceptions
public class LibraryDemo {
public static void main(String[] args) {
String fileName = "greeting.txt";
// --- Demonstrating java.util.Scanner for console input ---
System.out.print("Enter a greeting message: ");
try (Scanner scanner = new Scanner(System.in)) {
String message = scanner.nextLine();
// --- Demonstrating java.io.FileWriter for writing to a file ---
try (FileWriter writer = new FileWriter(fileName)) { // try-with-resources ensures writer is closed
writer.write(message);
System.out.println("✅ Message successfully written to " + fileName);
} catch (IOException e) {
System.err.println("❌ Error writing to file: " + e.getMessage());
}
// --- Demonstrating java.io.FileReader and BufferedReader for reading from a file ---
try (FileReader fileReader = new FileReader(fileName);
BufferedReader bufferedReader = new BufferedReader(fileReader)) {
String line = bufferedReader.readLine();
System.out.println("📖 Content read from " + fileName + ": " + line);
} catch (IOException e) {
System.err.println("❌ Error reading from file: " + e.getMessage());
}
}
}
}
```
Output example:
```
Enter a greeting message: Hello from Day 15!
✅ Message successfully written to greeting.txt
📖 Content read from greeting.txt: Hello from Day 15!
```
✨ **Your Challenge:** Modify the `FileWriter` part of the code to append a *second* line of text (e.g., "Keep learning Java!") to `greeting.txt` *without* overwriting the first line. (Hint: Look for overloaded `FileWriter` constructors that accept a boolean argument for appending!) 📝
---
Which of the following classes is part of the `java.util` package and commonly used for parsing primitive types and strings from user input or other sources?
Anonymous Quiz
25%
java.io.BufferedReader
0%
java.util.Random
75%
java.util.Scanner
0%
java.io.PrintWriter
Here's your Telegram post for Day 16 of the Java learning series! 🚀
---
Hey Java learners! 👋 Ready to connect your applications to the vast world of external services?
On **Day 16**, we're diving into the exciting realm of **Working with APIs**! 🌐 Learn how your Java programs can talk to web services using `HttpClient` (the modern API since Java 11) or `HttpURLConnection` (the traditional way). We'll make a simple GET request to fetch data, opening up endless possibilities for integrating with third-party services, pulling dynamic content, and much more! Let's make our apps truly connected. 💻
```java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.io.IOException;
public class ApiClientExample {
public static void main(String[] args) {
HttpClient client = HttpClient.newHttpClient(); // Create an HttpClient instance
// Build an HttpRequest for a GET request
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://jsonplaceholder.typicode.com/posts/1")) // Target API endpoint
.GET() // Specify GET method
.build();
try {
// Send the request and get the response
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
// Print the status code and response body
System.out.println("Status Code: " + response.statusCode());
System.out.println("Response Body:n" + response.body());
} catch (IOException | InterruptedException e) {
System.err.println("Error making API request: " + e.getMessage());
e.printStackTrace();
}
}
}
```
Output example:
```
Status Code: 200
Response Body:
{
"userId": 1,
"id": 1,
"title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
"body": "quia et suscipitnsuscipit recusandae consequuntur expedita et cumnreprehenderit molestiae ut ut quas totamnnostrum rerum est autem sunt rem eveniet architecto"
}
```
**Small challenge:**
Can you modify the code to fetch data for a different post (e.g., post ID 5) or try fetching a user's data from `https://jsonplaceholder.typicode.com/users/1`? Share your code snippets in the comments! 👇
---
---
Hey Java learners! 👋 Ready to connect your applications to the vast world of external services?
On **Day 16**, we're diving into the exciting realm of **Working with APIs**! 🌐 Learn how your Java programs can talk to web services using `HttpClient` (the modern API since Java 11) or `HttpURLConnection` (the traditional way). We'll make a simple GET request to fetch data, opening up endless possibilities for integrating with third-party services, pulling dynamic content, and much more! Let's make our apps truly connected. 💻
```java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.io.IOException;
public class ApiClientExample {
public static void main(String[] args) {
HttpClient client = HttpClient.newHttpClient(); // Create an HttpClient instance
// Build an HttpRequest for a GET request
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://jsonplaceholder.typicode.com/posts/1")) // Target API endpoint
.GET() // Specify GET method
.build();
try {
// Send the request and get the response
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
// Print the status code and response body
System.out.println("Status Code: " + response.statusCode());
System.out.println("Response Body:n" + response.body());
} catch (IOException | InterruptedException e) {
System.err.println("Error making API request: " + e.getMessage());
e.printStackTrace();
}
}
}
```
Output example:
```
Status Code: 200
Response Body:
{
"userId": 1,
"id": 1,
"title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
"body": "quia et suscipitnsuscipit recusandae consequuntur expedita et cumnreprehenderit molestiae ut ut quas totamnnostrum rerum est autem sunt rem eveniet architecto"
}
```
**Small challenge:**
Can you modify the code to fetch data for a different post (e.g., post ID 5) or try fetching a user's data from `https://jsonplaceholder.typicode.com/users/1`? Share your code snippets in the comments! 👇
---
Which Java API is generally considered the modern and preferred way to make HTTP requests since Java 11?
Anonymous Quiz
29%
A. java.net.HttpURLConnection
14%
B. org.apache.http.client.HttpClient (an external library)
29%
C. java.net.http.HttpClient
29%
D. javax.net.ssl.HttpsURLConnection
Which of the following terms refers to the process of converting a Java object into a JSON string?
Anonymous Quiz
33%
Serialization
0%
Deserialization
33%
Parsing
33%
Encoding
🌟 Java Learning Series - Day 18 🌟
Hello, Java learners! 👋 Today, we're diving into the powerful world of **Regular Expressions** (Regex)! 🚀 Regular expressions are sequence of characters that define a search pattern. They are incredibly useful for searching, manipulating, and validating strings. Think of them as super-charged pattern matchers for text data! In Java, we use the `java.util.regex` package, featuring the `Pattern` and `Matcher` classes, to harness this power. Let's explore how to find and replace text using regex! ✨
```java
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegexBasics {
public static void main(String[] args) {
String text = "Java is a powerful language. Version 1.8 is widely used, but Java 21 is out!";
// 1. Finding all occurrences of "Java" (case-insensitive)
Pattern javaPattern = Pattern.compile("java", Pattern.CASE_INSENSITIVE);
Matcher javaMatcher = javaPattern.matcher(text);
System.out.println("🔍 Finding all 'Java' occurrences:");
while (javaMatcher.find()) {
System.out.println("Found: '" + javaMatcher.group() + "' at index " + javaMatcher.start());
}
// 2. Replacing all digits with a hash '#'
// "\d" is the regex for any digit (0-9)
String textWithNumbers = "My project ID is P123 and my build number is 4567.";
String replacedText = textWithNumbers.replaceAll("\d+", "#"); // \d+ matches one or more digits
System.out.println("n✏️ Text after replacing digits: " + replacedText);
// 3. Checking if the entire string matches a pattern (e.g., starts with a letter and ends with a number)
Pattern specificPattern = Pattern.compile("^[A-Za-z].*\d$"); // Starts with letter, ends with digit
String validString = "HelloWorld1";
String invalidString = "1HelloWorld";
System.out.println("n✅ Does '" + validString + "' match: " + specificPattern.matcher(validString).matches());
System.out.println("❌ Does '" + invalidString + "' match: " + specificPattern.matcher(invalidString).matches());
}
}
```
Output example:
```
🔍 Finding all 'Java' occurrences:
Found: 'Java' at index 0
Found: 'Java' at index 48
✏️ Text after replacing digits: My project ID is P# and my build number is #.
✅ Does 'HelloWorld1' match: true
❌ Does '1HelloWorld' match: false
```
### Small Challenge:
Can you modify the code to find and print all words that contain at least one digit in the original `text` variable? (Hint: Use `\b` for word boundaries and `\w*\d\w*` for words with digits). Good luck! 🧠💡
---
Hello, Java learners! 👋 Today, we're diving into the powerful world of **Regular Expressions** (Regex)! 🚀 Regular expressions are sequence of characters that define a search pattern. They are incredibly useful for searching, manipulating, and validating strings. Think of them as super-charged pattern matchers for text data! In Java, we use the `java.util.regex` package, featuring the `Pattern` and `Matcher` classes, to harness this power. Let's explore how to find and replace text using regex! ✨
```java
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegexBasics {
public static void main(String[] args) {
String text = "Java is a powerful language. Version 1.8 is widely used, but Java 21 is out!";
// 1. Finding all occurrences of "Java" (case-insensitive)
Pattern javaPattern = Pattern.compile("java", Pattern.CASE_INSENSITIVE);
Matcher javaMatcher = javaPattern.matcher(text);
System.out.println("🔍 Finding all 'Java' occurrences:");
while (javaMatcher.find()) {
System.out.println("Found: '" + javaMatcher.group() + "' at index " + javaMatcher.start());
}
// 2. Replacing all digits with a hash '#'
// "\d" is the regex for any digit (0-9)
String textWithNumbers = "My project ID is P123 and my build number is 4567.";
String replacedText = textWithNumbers.replaceAll("\d+", "#"); // \d+ matches one or more digits
System.out.println("n✏️ Text after replacing digits: " + replacedText);
// 3. Checking if the entire string matches a pattern (e.g., starts with a letter and ends with a number)
Pattern specificPattern = Pattern.compile("^[A-Za-z].*\d$"); // Starts with letter, ends with digit
String validString = "HelloWorld1";
String invalidString = "1HelloWorld";
System.out.println("n✅ Does '" + validString + "' match: " + specificPattern.matcher(validString).matches());
System.out.println("❌ Does '" + invalidString + "' match: " + specificPattern.matcher(invalidString).matches());
}
}
```
Output example:
```
🔍 Finding all 'Java' occurrences:
Found: 'Java' at index 0
Found: 'Java' at index 48
✏️ Text after replacing digits: My project ID is P# and my build number is #.
✅ Does 'HelloWorld1' match: true
❌ Does '1HelloWorld' match: false
```
### Small Challenge:
Can you modify the code to find and print all words that contain at least one digit in the original `text` variable? (Hint: Use `\b` for word boundaries and `\w*\d\w*` for words with digits). Good luck! 🧠💡
---
Which of the following regex metacharacters represents 'any single digit'?
Anonymous Quiz
11%
\s
11%
\w
44%
\d
33%
.
✨ **Day 19: Mastering Java Build Tools & Dependency Management!** ✨
Hey Java learners! 👋 Today we dive into the backbone of professional Java development: **Build Tools** like Maven and Gradle. 🛠️ These tools are indispensable for automating tasks like compiling code, running tests, packaging applications, and most importantly, managing project dependencies. Say goodbye to manual JAR hell! 📦 They ensure your project builds consistently and efficiently, making collaboration a breeze.
Let's look at a simple Java application that leverages an external library – something build tools handle seamlessly!
```java
package com.example;
import org.apache.commons.lang3.StringUtils; // An external dependency!
public class App {
public static void main(String[] args) {
String originalMessage = "hello java world";
// StringUtils comes from Apache Commons Lang3, managed by Maven/Gradle!
String capitalizedMessage = StringUtils.capitalize(originalMessage);
System.out.println("Original String: " + originalMessage);
System.out.println("Capitalized String: " + capitalizedMessage);
System.out.println("nThis app uses an external library. Build tools like Maven or Gradle make integrating 'StringUtils' effortless by simply declaring it as a dependency!");
}
}
```
Output example:
```
Original String: hello java world
Capitalized String: Hello java world
This app uses an external library. Build tools like Maven or Gradle make integrating 'StringUtils' effortless by simply declaring it as a dependency!
```
**Small Challenge:** 💡
When you use Maven or Gradle, you don't manually download `.jar` files for libraries. What is the name of the central configuration file in a Maven project where you would declare `org.apache.commons:commons-lang3:3.12.0` as a dependency? (Hint: It's the Project Object Model!)
Happy coding! 🚀📚
Hey Java learners! 👋 Today we dive into the backbone of professional Java development: **Build Tools** like Maven and Gradle. 🛠️ These tools are indispensable for automating tasks like compiling code, running tests, packaging applications, and most importantly, managing project dependencies. Say goodbye to manual JAR hell! 📦 They ensure your project builds consistently and efficiently, making collaboration a breeze.
Let's look at a simple Java application that leverages an external library – something build tools handle seamlessly!
```java
package com.example;
import org.apache.commons.lang3.StringUtils; // An external dependency!
public class App {
public static void main(String[] args) {
String originalMessage = "hello java world";
// StringUtils comes from Apache Commons Lang3, managed by Maven/Gradle!
String capitalizedMessage = StringUtils.capitalize(originalMessage);
System.out.println("Original String: " + originalMessage);
System.out.println("Capitalized String: " + capitalizedMessage);
System.out.println("nThis app uses an external library. Build tools like Maven or Gradle make integrating 'StringUtils' effortless by simply declaring it as a dependency!");
}
}
```
Output example:
```
Original String: hello java world
Capitalized String: Hello java world
This app uses an external library. Build tools like Maven or Gradle make integrating 'StringUtils' effortless by simply declaring it as a dependency!
```
**Small Challenge:** 💡
When you use Maven or Gradle, you don't manually download `.jar` files for libraries. What is the name of the central configuration file in a Maven project where you would declare `org.apache.commons:commons-lang3:3.12.0` as a dependency? (Hint: It's the Project Object Model!)
Happy coding! 🚀📚
Which file is primarily used by Maven to define project dependencies, plugins, and the build lifecycle?
Anonymous Quiz
0%
build.gradle
100%
pom.xml
0%
settings.xml
Which `java.time` class is used to represent a date without a time or a time-zone, like '2023-10-27'?
Anonymous Quiz
33%
LocalDateTime
0%
LocalTime
50%
LocalDate
17%
Instant
Which of the following statements about Java interfaces is TRUE?
Anonymous Quiz
38%
An interface can have instance fields (non-static, non-final variables).
50%
A class can implement multiple interfaces.
0%
An interface can have a constructor.
13%
All methods in an interface must be abstract and public.