Java import does not work. Folder not recognized

I am working on an Android project in which the Java code is stored in the src folder. The main code is saved in this folder. In the same folder there is another folder with the Beetbox class. This class must be imported in the main class. The beet box is located in the path under / ofai / music. Please help me fix this.

Import at.ofai.music.beetroot;

java – Is the size of the string pool affected by setting the maximum heap size?

I have a Java application with strange memory usage. I have found that memory usage is significantly higher than the maximum heap size (Xmx is 800mUse is 1.4g).

One of the most recent changes before that was a sharp increase in the number of unique strings used. So I thought that the many strings that I used a lot of memory outside of the heap for are possible. Is this possible?

I am using Java 11.

Java – how to draw an arch of a panel?

I am creating a Java program in which I can give the user the arc length depending on the radius and the angle he gives me. Then I want to graph the bow that is displayed in my control panel. This is my ActionListener for the "Calculate" button. How do I call there to graph the sheet?

ActionListener enter = (ActionEvent ae) ->{
        String opciones = (String) modalidad.getSelectedItem();

        double ang = Float.parseFloat(angulo.getText());
        double rad = Float.parseFloat(radio.getText());
        double longitud;

        if (opciones.equals("Grados")) {
            ang = ang * 2 * mate.pi / 360;

        }

        longitud = ang*rad;
        resultado.setText(String.valueOf(longitud));
        ang=ang*360/2*mate.pi;


    };

How do I remove an element from an array and loop through it to avoid spaces? (Java)

My question is how do I remove an element from an array and then loop through it to avoid spaces. I created my code, but if you delete a number, for example, it will reappear. Can you tell me what's wrong with my code? Another thing that I also noticed is that when I enter a repeated number, I cannot enter another number again. It's like this 5 duplicated itself 🙁


Exercise suggested by my teacher

Create a system that asks for the length of the array. This array contains whole cigars.

The following menu is available:

1.- Alta de un numero

The index of the next empty position is an attribute in the class in which the array is located.

The array has no repeated numbers. If the number is already in the array, the user is informed that it already exists and that of another number.

2.- Cambio de numero

The number is asked to search for it. If it is found, the new number is requested. If the number is already included in the agreement, the user is informed that it already exists and that of another number.

3.- Eliminar un numero

The number is asked if it is found. If you are sure you want to log out. If the answer is positive, the other numbers are included in the arrangement so as not to leave any empty space.

4.- Imprimir los numeros
5.- Salir

Note: The system has two classes, one of which is the main class and the other is the integer array.


Main class

import java.util.Scanner;

public class TestNumber {

public static void main(String() args) {
    Scanner leer = new Scanner(System.in);
    Numero_Dos numP;
    int opc1, n, j=0, k = 0, numero = 0, dato = 0;
    System.out.println("¿Cuantos numeros tendra el programa?");
    n = leer.nextInt();
    numP = new Numero_Dos(n);
    do {
        System.out.println("1.- Alta de numero");
        System.out.println("2.- Cambio de numero");
        System.out.println("3.- Eliminar un numero");
        System.out.println("4.- Imprimir numeros");
        System.out.println("5.- Salir");
        opc1 = leer.nextInt();
        switch (opc1) {
            case 1:
                if (j

}}

Class of the number

public class Number_Two {

private int arrayN();

Numero_Dos(int numero) {
    arrayN = new int(numero);
}

public void setNumero(int i, int numero) {
    arrayN(i) = numero;
}

public boolean numeroRepetido(int numero) {
    for (int i = 0; i < arrayN.length; i++) {
        if (arrayN(i) == numero) {
            return true;
        }
    }
    return false;
}

public int buscarNum(int dato) {
    for (int i = 0; i < arrayN.length; i++) {
        if (dato == arrayN(i)) {
            return i;
        }
    }
    return -1;
}

public void borrarNumero(int posicion) {
    for (int i = posicion - 1; i < arrayN.length - 1; i++) {
        arrayN(i) = arrayN(i + 1);
    }
}

public int getNumero(int i) {
    return arrayN(i);
}

}}


Departure

run:
¿Cuantos numeros tendra el programa?
2
1.- Alta de numero
2.- Cambio de numero
3.- Eliminar un numero
4.- Imprimir numeros
5.- Salir
1
Ingrese el numero por favor
5
1.- Alta de numero
2.- Cambio de numero
3.- Eliminar un numero
4.- Imprimir numeros
5.- Salir
1
Ingrese el numero por favor
5
Este numero ya esta repetido, ingresa otro
1.- Alta de numero
2.- Cambio de numero
3.- Eliminar un numero
4.- Imprimir numeros
5.- Salir
1
No puedes agregar mas numeros
1.- Alta de numero
2.- Cambio de numero
3.- Eliminar un numero
4.- Imprimir numeros
5.- Salir
3
Ingrese que numero desea eliminar
5
1.- Alta de numero
2.- Cambio de numero
3.- Eliminar un numero
4.- Imprimir numeros
5.- Salir
4
Los numeros son: 5
Los numeros son: 0
1.- Alta de numero
2.- Cambio de numero
3.- Eliminar un numero
4.- Imprimir numeros
5.- Salir
3
Ingrese que numero desea eliminar
5
1.- Alta de numero
2.- Cambio de numero
3.- Eliminar un numero
4.- Imprimir numeros
5.- Salir
4
Los numeros son: 5
Los numeros son: 0
1.- Alta de numero
2.- Cambio de numero
3.- Eliminar un numero
4.- Imprimir numeros
5.- Salir
1
No puedes agregar mas numeros
1.- Alta de numero
2.- Cambio de numero
3.- Eliminar un numero
4.- Imprimir numeros
5.- Salir

Java – Does my code comply with good clean code conventions?

Here is a class I implemented to sort parameter rows in the form of an array of strings.

public class ParameterLinesSorter : IParameterLinesSorter
{
    private int identiferIndex;
    private IEnumerable parameterLines;

    public IEnumerable> Sort(IEnumerable parameterLines, int identiferIndex)
    {
        this.identiferIndex = identiferIndex;
        this.parameterLines = parameterLines;

        return IsNotNullAndNotEmpty() ? FilterAndSort() : new List>();
    }

    private bool IsNotNullAndNotEmpty()
    {
        return parameterLines != null && parameterLines.Any();
    }

    private IEnumerable> FilterAndSort()
    {
        return parameterLines
            .Where(parameterLine => parameterLine.Any())
            .GroupBy(parameterLine => parameterLine.ElementAt(identiferIndex));
    }
}

Here is an example of using a simple test:

    (Test)
    public void ShouldReturnListWithTwoGroupsOfOneElement()
    {
        IEnumerable parameterLines = new List() {
            new string(){ "C", "3", "3" },
            new string(){ "M", "3", "5" }
        };


        IEnumerable> expectedGroups = new List>() {
            new List(){ new string(){ "C", "3", "3" }},
            new List(){ new string(){ "M", "3", "5" }}
        };

        Assert.AreEqual(expectedGroups, sorter.Sort(parameterLines, 0));
    }

Note that this class and sorting method are used only once in the entire system.

Shortly before, the IsNotNullAndNotEmpty and FilterAndSort methods had arguments, but I've read that the best thing for a method was to have no arguments. So I preferred to pass identifierIndex and parameterLines as instance variables. Is it really good practice?

I listen to every other recommendation.

Thank you in advance.

How do I find a number in an array? (Java)

Again it's me (sorry if I ask too much, I'm new to this area) 🙂

The problem is that I cannot find the numbers I have entered and cannot print all the numbers in the menu. If you could help me it would be a big help 🙁


This is the exercise suggested by my teacher: c

Create a system that asks for the length of the array. This array contains whole cigars.
The following menu is available:

1.- Alta de un numero

The index of the next empty position is an attribute in the class in which the array is located.

2.- Busqueda de numero

The number is asked to search for it. If it is found, the positions where this number is located are displayed.

3.- Imprimir los numeros
4.- Salir

Note: The system has two classes, one of which is the main class and the other is the integer array.


This is my code:

1.- main class

import java.util.Scanner;

public class TestNumber {

public static void main(String() args) {
    Scanner leer = new Scanner(System.in);
    int opc, n, j = 0, l = 0, numeros = 0, dato;
    Numero num1;
    System.out.println("Ingrese el numero de arreglos, por favor: ");
    n = leer.nextInt();
    num1 = new Numero(n);
    do {
        System.out.println("1.- Alta de numero");
        System.out.println("2.- Busqueda de numero");
        System.out.println("3.- Imprimir numeros");
        System.out.println("4.- salir");
        opc = leer.nextInt();
        switch (opc) {
            case 1:
                if (j < n) {
                    j += 1;
                    System.out.println("Ingrese los numeros:");
                    numeros = leer.nextInt();
                    num1.setNumero(l, numeros);
                    System.out.println("Ingresando numeros.......");
                } else {
                    System.out.println("No puedes registrar más numeros");
                }
                break;
            case 2:
                System.out.println("Ingrese el numero que sea buscar");
                dato = leer.nextInt();
                    if (!num1.buscarNum(dato)) {
                    num1.buscarNum(dato);
                        System.out.println("El numero " + dato + " esta en la ubicación " + l);
                    } else {
                        System.out.println("No existe un numero en la ubicacion " + l);
                    }
                break;
            case 3:
                for (int i = 0; i < n; i++) {
                    System.out.println("Los numeros son: " + num1.getNum(i));
                }
                break;
        }
    } while (opc < 4);
}

}}

2.- number class

public class number {

private int numero();


Numero(int i) {
    numero = new int(i);
}

void setNumero(int i, int numeros) {
    numero(i) = numeros;
}

public boolean buscarNum(int dato) {
    for (int i = 0; i < numero.length; i++) {
        if (dato == numero(i)) {
            i = numero.length;
        }
        return true;
    }
    return false;
}

public int getNum(int i) {
    return numero(i);
}

}}

reactjs – react native does not identify a Java JDK

I am currently working on a native app. But when I try to start the npx application, I give an error.
JAVA_HOME is set to an invalid directory: / usr / lib / jvm / java-8-openjdk-amd64

info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 960 file(s) to forward-jetify. Using 4 workers...
info Starting JS server...
warn Failed to automatically start the packager server. Please run "react-native start" manually. Error details: EACCES: permission denied, open '/home/noobmaster/Desktop/mkFirstReactNativeAndroidAPP/AwesomeProject/node_modules/react-native/scripts/.packager.env'
/bin/sh: 1: adb: not found
info Launching emulator...
error Failed to launch emulator. Reason: No emulators found as an output of `emulator -list-avds`.
warn Please launch an emulator manually or connect a device. Otherwise app may fail to launch.
info Installing the app...

ERROR: JAVA_HOME is set to an invalid directory:  /usr/lib/jvm/java-8-openjdk-amd64

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.


error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/getting-started.html#android-development-environment. Run CLI with --verbose flag for more details.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081

    at makeError (/home/noobmaster/Desktop/mkFirstReactNativeAndroidAPP/AwesomeProject/node_modules/execa/index.js:174:9)
    at Promise.all.then.arr (/home/noobmaster/Desktop/mkFirstReactNativeAndroidAPP/AwesomeProject/node_modules/execa/index.js:278:16)
    at 
    at process._tickCallback (internal/process/next_tick.js:188:7)


This is only the case with React-Native. other IDEs like ecpilse, netbeans, android studio have no problem finding jdk.

my JAVA_HOME is
/ usr / lib / jvm / java-8-openjdk-amd64

Java validation framework and immutability

I designed simple objects Validation framework in Java as part of a code refactoring.

The framework has one ValidationRule Interface with a method Errors validate(MyObject myObject, Context ctx).
There are a number of classes (validators) that implement different validation rules, each validation checking a different part of the object properties and subordinate collections.

The rules are looped and validation errors are accumulated and returned to the user.

The code that I redesign often changes the object to be validated in the "middle" of a validation logic:

if (myObject.getName() == null) {
    myObject.setName(DEFAULT_NAME);
}

Certain rules are based on the assumption that the object has changed (for example, they expect the name to always be non-null).

From a design perspective, I would like to keep the validation framework "read-only". This makes the rules easy to understand and justify, but I need to be able to mutate the properties of certain objects from one rule to the next.

What would be a good pattern to get such a result?

1) Validation rules do not mutate the object to be validated (this can be enforced by passing one ImmutableMyObject to the validation interface)

2) Each rule should be able to mutate the objects to be validated so that the next rules work

Ideas welcome!

java – How can I view the items in a list?

I consume a soap service and in its response object it has the following structure:

public class ResponseServicio{
  protected String codigo;
  protected Encuesta encuesta;

}

public class Encuesta{
  protected List preguntas;


}

public class Preguntas{

   protected String idPregunta;
   protected String pregunta;
   protected String respuesta;
}

What I need is to answer all questions in the service with their ID and their answer in a string type field. I have the following, and even now, if it only shows me 1 question because I am showing the first item, but how can I show you all the questions that may go with your ID and your answer?
should i use one for or something?

ResponseServicio respuesta = new ResponseServicio();
RespuestaSoap port = servicio.getEncuesta();
respuesta = port.consultaEncuesta();

resultado.put("Campo1", respuesta.getEncuesta().getPreguntas().get(0));

Java – Does walking through a large record on a map affect performance with every click?

I need to get values ​​from a map by adapter position that I get from a RecyclerView.

As you can see, every time I click on an album cover, I create a new array of album objects.

final Album() albums = new Album(albumMap.size());
      for (Map.Entry e : albumMap.entrySet()){
      albums(i++) = e.getValue();
 }

Then I get the album like this: String selectedAlbum = albums(position).getAlbum();

But what if someone has more than 10,000 albums on their device and every time an album is clicked, a new array of album objects is created and i iterate just to get the album name.

Would this affect performance if there were many albums?

TL; DR Is this code bad?

Complete code

@Override
    public void onClickAlbum(int position, Map albumMap) {
        if (getActivity() != null) {
            int i = 0;
            final Album() albums = new Album(albumMap.size());
            for (Map.Entry e : albumMap.entrySet()){
                albums(i++) = e.getValue();
            }
            String selectedAlbum = albums(position).getAlbum();
            Main.getInstance().setSongsFilteredBy(SongsLibrary.getInstance().getSongsByAlbum(selectedAlbum));
            Intent intent = new Intent(getActivity(), ListSongsActivity.class);
            intent.putExtra("title", selectedAlbum);
            startActivity(intent);
            Toast.makeText(getActivity(), "test: " + selectedAlbum, Toast.LENGTH_SHORT).show();
        }
}