Ejemplos de Código Java para Tareas Comunes

Método para Invertir una Cadena en Java

Este método toma una cadena de texto y devuelve una nueva cadena con los caracteres en orden inverso.


public String invertirCadena(String s) {
    String resultado = "";
    if (s == null) {
        return null; // O manejar como se prefiera
    }
    for (int i = s.length() - 1; i >= 0; i--) {
        resultado = resultado + s.charAt(i);
    }
    return resultado;
}

Método para Invertir un Array en Java

Este método invierte los elementos de un array

Read More

Data Communication Concepts and Transmission Methods

Data Communication Fundamentals

Core Concepts in Data Communication

Data Communication: The process of communicating information in binary form between two or more points. It requires four basic elements:

  • Transmitter: A device that transmits data.
  • Message: The data to be transmitted.
  • Medium: The path data takes from source to destination.
  • Receiver: The device receiving the data.

Bit: The smallest unit of information and the base unit for communications.

Byte: The minimum continuous set of bits that enables

Read More

Networking Essentials: LAN, WAN, and Data Transmission

Networking Fundamentals

LAN vs. WAN

LAN (Local Area Network): Local networking, typically found in homes, businesses, or schools, and geographically limited. It is owned by an independent organization.

WAN (Wide Area Network): Covers a large geographical area and is typically used by service providers.

Network Infrastructure

Hardware: Routers, switches, NICs (Network Interface Cards)

Software: Network operating/management systems, operating systems, firewalls, network security applications

Services: T-

Read More

Java Concepts: Practice Questions and Examples

Java Concepts: Practice Questions

  • Primitive data type variables cannot be used to invoke methods.
  • Import statements are not needed if one class in a package uses another in the same package.
  • Classes declared as final cannot be subclassed.
  • Methods in an abstract class do not have to be abstract.
  • Static/private methods cannot be overridden.

Data Type Conversion

  • String to int: int result = Integer.parseInt(string);

Threads

Create and start a thread that checks if an integer is even (divisible by 2):

  • new Thread(
Read More

Pathfinding Algorithms: BFS, DFS, A*, and Uniform Cost

Breadth-First Search (BFS) and Depth-First Search (DFS)

from collections import deque
def bfs(maze, start, end):
  rows = len(maze)
  cols = len(maze[0])
  directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
  queue = deque([(start, [start])])
  visited = set()
  visited.add(start)
  node_visited = 0
  while queue:
    current, path = queue.popleft()
    node_visited += 1
    if current == end:
      return path, node_visited
    for r, c in directions:
      x = current[0] + r
      y = current[
Read More

C Language Stack Implementation and Applications

C Code: Checking Parentheses Correctness

#include <stdio.h>
#include <string.h>

#define N 20

typedef struct stack {
    int a[N];
    int top;
} stack;

void push(stack *s, int x) {
    s->top++;
    s->a[s->top] = x;
}

int pop(stack *s) {
    int x;
    x = s->a[s->top];
    s->top--;
    return x;
}

int isOpenBracket(int x) {
    if (x == '{' || x == '[' || x == '(') {
        return 1;
    } else {
        return 0;
    }
}

int isCloseBracket(int x) {
    if 
Read More