# java.lang

***

**1. Creating and Initializing Objects:**

```java
// Creating an instance of the String class
String myString = new String("Hello World!");
```

**2. Accessing Object Properties:**

```java
// Getting the length of the string
int length = myString.length();
```

**3. Performing String Operations:**

```java
// Concatenating two strings
String newString = "Hello" + " " + "World!";
```

**4. Comparing Objects:**

```java
// Comparing two strings for equality
boolean isEqual = myString.equals("Hello World!");
```

**5. Converting Objects to Strings:**

```java
// Converting an integer to a string
String numberString = Integer.toString(123);
```

**6. Parsing Strings to Objects:**

```java
// Parsing a string to an integer
int number = Integer.parseInt("123");
```

**7. Formatting Strings:**

```java
// Formatting a string with placeholders
String formattedString = String.format("Name: %s, Age: %d", "John", 25);
```

**8. Regular Expressions:**

```java
// Matching a pattern in a string
Pattern pattern = Pattern.compile("[a-zA-Z]+");
Matcher matcher = pattern.matcher("This is a test string");

// Checking if the pattern matches any part of the string
boolean matches = matcher.find();
```

**9. Threading:**

```java
// Creating a thread
Thread thread = new Thread(() -> System.out.println("Hello from a thread!"));

// Starting the thread
thread.start();
```

**10. Synchronization:**

```java
// Synchronizing a block of code to prevent race conditions
synchronized (myObject) {
    // Code that should be executed in a thread-safe manner
}
```

**11. Exception Handling:**

```java
try {
    // Code that may throw an exception
} catch (Exception e) {
    // Code to handle the exception
}
```

**12. Collections: ArrayList:**

```java
// Creating an ArrayList
ArrayList<String> names = new ArrayList<>();

// Adding elements to the list
names.add("John");
names.add("Mary");

// Getting an element from the list
String name = names.get(0);
```

**13. Collections: HashSet:**

```java
// Creating a HashSet
Set<Integer> numbers = new HashSet<>();

// Adding elements to the set
numbers.add(1);
numbers.add(2);
numbers.add(3);

// Checking if the set contains a certain element
boolean contains = numbers.contains(2);
```

**14. Collections: HashMap:**

```java
// Creating a HashMap
Map<String, Integer> ages = new HashMap<>();

// Putting a key-value pair into the map
ages.put("John", 25);

// Getting the value associated with a key
int age = ages.get("John");
```

**15. Collections: Stream:**

```java
// Creating a stream
Stream<Integer> numbersStream = Stream.of(1, 2, 3, 4, 5);

// Performing operations on the stream
int sum = numbersStream.reduce(0, Integer::sum);
```

**16. Lambda Expressions:**

```java
// Creating a lambda expression
Runnable task = () -> System.out.println("Hello from a lambda!");

// Running the lambda
new Thread(task).start();
```

**17. Generics:**

```java
// Creating a generic class
class MyContainer<T> {
    private T value;

    public T getValue() {
        return value;
    }

    public void setValue(T value) {
        this.value = value;
    }
}

// Creating an instance of the generic class
MyContainer<String> container = new MyContainer<>();
```

**18. Inheritance:**

```java
// Creating a superclass
class Animal {
    public void eat() {
        System.out.println("Animal is eating...");
    }
}

// Creating a subclass
class Dog extends Animal {
    @Override
    public void eat() {
        System.out.println("Dog is eating...");
    }
}

// Creating an instance of the subclass
Dog dog = new Dog();
dog.eat();
```

**19. Polymorphism:**

```java
// Creating a superclass
class Shape {
    public void draw() {
        System.out.println("Shape is being drawn...");
    }
}

// Creating a subclass
class Circle extends Shape {
    @Override
    public void draw() {
        System.out.println("Circle is being drawn...");
    }
}

// Using the superclass reference to call the overridden method
Shape shape = new Circle();
shape.draw();
```

**20. Interfaces:**

```java
// Creating an interface
interface Flyable {
    void fly();
}

// Creating a class that implements the interface
class Bird implements Flyable {
    @Override
    public void fly() {
        System.out.println("Bird is flying...");
    }
}

// Creating an instance of the class that implements the interface
Bird bird = new Bird();
bird.fly();
```

**21. Reflection:**

```java
// Creating an instance of the Class class
Class<?> clazz = Class.forName("java.lang.String");

// Getting information about the class
String name = clazz.getName();
Method[] methods = clazz.getMethods();
```

**22. Annotations:**

```java
// Creating an annotation
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Loggable {
}

// Annotating a method
@Loggable
public void myMethod() {
    // Implementation goes here
}
```

**23. JAR Files:**

```java
// Creating a JAR file
JarFile jarFile = new JarFile("my-app.jar");
```

**24. Class Loading:**

```java
// Creating a custom class loader
class MyClassLoader extends ClassLoader {
    @Override
    protected Class<?> findClass(String name) throws ClassNotFoundException {
        // Implementation goes here
    }
}

// Loading a class using the custom class loader
Class<?> clazz = new MyClassLoader().loadClass("MyClass");
```

**25. Serialization:**

```java
// Creating an object to be serialized
Person person = new Person("John", 25);

// Serializing the object
FileOutputStream fileOutputStream = new FileOutputStream("person.ser");
ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);
objectOutputStream.writeObject(person);

// Deserializing the object
FileInputStream fileInputStream = new FileInputStream("person.ser");
ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
Person deserializedPerson = (Person) objectInputStream.readObject();
```

**26. Networking: Socket:**

```java
// Creating a socket
Socket socket = new Socket("localhost", 8080);
```

**27. Networking: ServerSocket:**

```java
// Creating a server socket
ServerSocket serverSocket = new ServerSocket(8080);
```

**28. Networking: DataInputStream and DataOutputStream:**

```java
// Sending data to a socket
DataOutputStream dataOutputStream = new DataOutputStream(socket.getOutputStream());
dataOutputStream.writeUTF("Hello from client!");

// Receiving data from a socket
DataInputStream dataInputStream = new DataInputStream(socket.getInputStream());
String message = dataInputStream.readUTF();
```

**29. Networking: URL:**

```java
// Creating a URL object
URL url = new URL("https://example.com");
```

**30. Networking: HttpClient:**

```java
// Creating an HTTP client
HttpClient httpClient = new HttpClient();

// Sending an HTTP request
HttpMethod method = new GetMethod("https://example.com");
HttpResponse response = httpClient.executeMethod(method);
```

**31. Date and Time:**

```java
// Getting the current date and time
LocalDateTime now = LocalDateTime.now();
```

**32. Formatting Date and Time:**

```java
// Formatting the date and time
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String formattedDateTime = now.format(formatter);
```

**33. Parsing Date and Time:**

```java
```
