What is the difference between "Components" and "AWT Components" in java graphical interfaces?

I am creating a java application to take the color of a pixel from the screen, and in eclipse windows builder these two elements appear to me and I don't know what is the difference between them.

Could someone explain what the difference is?

I am interested in putting a list item inside a Choice Any suggestion?

This is the application that I am creating:

Application that can take the color code of a pixel on the screen

In eclipse they appear to me like this:

enter the image description here

Java – How to make a minimum and maximum ceiling on a random number?

You can do something like this:

public class Sorteio {
    private static final Random RND = new Random();

    public static int sortear(int min, int max) {
        return RND.nextInt(max - min + 1) + min;
    }

    public static int() sortearSete() {
        return new int() {
            sortear(0, 9),
            sortear(10, 18),
            sortear(19, 26),
            sortear(27, 33),
            sortear(34, 39),
            sortear(40, 44),
            sortear(45, 48)
        };
    }
}

The method sortear(int, int) gives you two numbers within a range. For example, sortear(20, 30) give any number from 20 to 30, including 20 itself and 30 itself. And then the method sortearSete() gives you these 7 numbers. It is important that you adjust the number ranges within this method to the ranges you want.

I placed the following tracks: a track containing 10 numbers from 0 to 9; a strip containing 9 numbers from 10 to 18; a strip containing 8 numbers from 19 to 26; a strip containing 7 numbers from 27 to 33; a strip containing 6 numbers from 34 to 39; a strip containing 5 numbers from 40 to 44 and a strip containing 4 numbers from 45 to 48.

java: efficient way to find the best result of A mod M in a range of numbers

I am writing a code that takes two numbers N and M and finds the best result of A mod M for all numbers of A in the range 1,2,3, …, N-1, N.

1 ≤ N, M ≤ 10 ^ 9

My code is:

public static void main(String() args) throws IOException {
    long n=readLong(), m=readLong(), a=Integer.MIN_VALUE;
    for(int i=1; i<=n; i++){
        a=Math.max(i%m, a);
    }
    System.out.println(a);
}

My code works for small ranges as in the following test case:

Entry`

10 5

Departure

4

However, it is not yet efficient enough (TLE). Is there a way to make going through all the numbers faster?

filter – JAVA Filter by date within a JAVA List

I am trying to filter by a date that comes from this object, but it is only bringing the first in the list, it is not checking the list to validate the value, can anyone give a light?

if (dueDate! = null) {
invoicesDTO = declarationsListResponse.getStatementsListResult (). getStatements (). getStatementDetails ()
.stream ()
.filter (sd -> sd.getDueDate (). equalsIgnoreCase (Constants.DATETIME_YYYY_MM_DD.format (dueDate)))
.map ((StatementDetails StatementDetails) -> {
InvoiceDTO invoiceDTO = new InvoiceDTO ();
invoiceDTO.setMaskedPan (maskedPan);
invoiceDTO.setMinDueAmount (StatementDetails.getMinDueAmount ());
invoiceDTO.setClosingBalance (StatementDetails.getClosingBalance ());
invoiceDTO.setDueDate (StatementDetails.getDueDate ());
invoiceDTO.setOverdueAmount (StatementDetails.getOverdueAmount ());
DTO return invoice;
}). collect (Collectors.toList ());
return of DTO invoices;

java – android studio firebase error read data

@Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        final Post post = mPosts.get(position);

            holder.username.setText(this.username);

            if(imgURL.equals("default"))
                holder.img_perfil.setImageResource(R.drawable.ic_person_red);
            else
                Glide.with(mContext).load(imgURL).into(holder.img_perfil);


            holder.mensaje.setText(post.getMessage());


            if(post.getEstado_animo().equals("Normal"))
                holder.animo.setImageResource(R.drawable.ic_cara_normal);
            else if(post.getEstado_animo().equals("Triste"))
                holder.animo.setImageResource(R.drawable.ic_cara_triste);
            else if(post.getEstado_animo().equals("Feliz"))
                holder.animo.setImageResource(R.drawable.ic_cara_feliz);

    }

That Post list comes from this method

private void leerPost(){
        mPosts = new ArrayList<>();

        reference = FirebaseDatabase.getInstance().getReference("Posts");
        reference.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                mPosts.clear();

                for (DataSnapshot snapshot : dataSnapshot.getChildren()){
                    Post post = snapshot.getValue(Post.class);


                            mPosts.add(post);


                    DatabaseReference reference2 = FirebaseDatabase.getInstance().getReference("Users").child(post.getSender());
                    reference2.addValueEventListener(new ValueEventListener() {
                        @Override
                        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                            User user = dataSnapshot.getValue(User.class);

                            postAdapter = new PostAdapter(getContext(), mPosts, user.getUsername(), user.getImageURL());
                            recyclerView.setAdapter(postAdapter);
                        }

                        @Override
                        public void onCancelled(@NonNull DatabaseError databaseError) {

                        }
                    });


                }

            }

            @Override
            public void onCancelled(@NonNull DatabaseError databaseError) {

            }
        });



    }

What I have is in a FireBase database a "Post" reference where there are "sender" values ​​"Message" "Encourage" each user created can create a post and what I want is to be able to collect all those posts and display their message etc. but it generates this annoying error that I don't know how to fix, create the PostAdapter to be able to create the RecyclerView inside a Fragment. I appreciate your help.

Here is the error "PID: 18504 java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals (java.lang.Object)' on a null object reference"

Minecraft Java and Bedrock Windows 10 servers 35% discount for 6 months

Minecraftserver.net
Looking for a solid hosting company that doesn't resell OVH or others? Look no further, all of our hardware is company owned, we operate our own IP addresses and have been around since 2010 hosting Minecraft, so we know one or two things about hosting.
We have a promotion of 25% discount for the use of life "WHT25" This promotion works for the lifetime of the server if you upgrade / level down you still get 25% discount!
We accept PayPal and credit card payments through Stripe.

Use "STAYINNPLAY" for a 35% discount in the first 6 months!

You can see all our Minecraft hosting server plans on our website.
You want Minecraft 1.15.2 or Bedrock servers for Windows10 Switch, Xbox, iPhone, etc. we have it just let us know and we can connect it so you can start getting honey and playing with the bees!

Our servers are located in 6 global locations: Los Angeles, Seattle, Dallas, New York, Chicago and the Netherlands (EU). We have players from all over the world (Australia, Norway, UK, USA, Thailand, etc.) who have said that the performance is excellent and without delay. If you want to test it, we have our test servers below:

Minecraft test servers
ny.minecraftserver.net New York, NY Location
nl.minecraftserver.net Amsterdam, NL Location
ch.minecraftserver.net Chicago, IL Location

la.minecraftserver.net Los Angeles, CA Location
wa.minecraftserver.net Seattle, WA Location
tx.minecraftserver.net Dallas, TX Location

All hardware is company owned, we also have our own network!

Order your own Minecraft server from the original today minecraft hosting server company!
If you want more control over your server and SSH access, we provide Premium VPS hosting at our New York location on Intel E3-1231v3 with SSD raided from just $ 8 / GB
PureVoltage also provides New York laying, dedicated servers, VPS hosting, IP Transit and much more.

java – How to change color of action bar in android studio

I am a student and developer developer and I have a project that I have to do which basically consists of changing the color of the action bar by selecting one of the 3 radio buttons where the colors red, green and blue are and when the user presses the button selection changes color and return to a screen with Hello World, the code is as follows:

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });

    Intent intent = getIntent();

    if(intent != null){
        String cor = intent.getStringExtra("cor");
        if(cor == null) { //não há cor passada no intent

            ;

            cor = "azul";
        }
        else{

        }

        if(cor.equalsIgnoreCase("verde"))
            toolbar.setBackgroundColor(Color.GREEN);
        else if(cor.equalsIgnoreCase("vermelho"))
            toolbar.setBackgroundColor(Color.RED);
        else
            toolbar.setBackgroundColor(Color.BLUE);


    }

}

private void ShareMessage(String msg){
    Intent shareMsgIntent = new Intent();

    shareMsgIntent.setAction(Intent.ACTION_SEND);
    shareMsgIntent.putExtra(Intent.EXTRA_TEXT, msg);
    shareMsgIntent.setType("text/plain");

    if  (shareMsgIntent.resolveActivity(getPackageManager()) != null) {
        startActivity(shareMsgIntent);
    }
}

private void ShowColorPreference(){
    Intent colorPreferenceIntent = new Intent(this, Main2Activity.class);
    colorPreferenceIntent.putExtra("cor", "verde");
    startActivity(colorPreferenceIntent);
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

public void onShareClick(View view) {
    ShareMessage("Olá mundo!");
    ShowColorPreference();
}

}


public class Main2Activity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main2);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });


    Intent intent = getIntent();
    String cor = intent.getStringExtra("cor");

    RadioButton rdbVerde = (RadioButton)findViewById(R.id.radioVerde);
    RadioButton rdbAzul = (RadioButton)findViewById(R.id.radioAzul);
    RadioButton rdbVermelho = (RadioButton)findViewById(R.id.radioVermelho);

    if(cor.equalsIgnoreCase("verde"))
        rdbVerde.setChecked(true);
    else if(cor.equalsIgnoreCase("vermelho"))
        rdbVermelho.setChecked(true);
    else
        rdbAzul.setChecked(true);

}

public void onSelecionarClick(View view) {
    String cor = "";

    RadioButton rdbVerde = (RadioButton)findViewById(R.id.radioVerde);
    RadioButton rdbAzul = (RadioButton)findViewById(R.id.radioAzul);
    RadioButton rdbVermelho = (RadioButton)findViewById(R.id.radioVermelho);

    if(rdbVerde.isChecked())
        cor = "verde";
    else if(rdbAzul.isChecked())
        cor = "azul";
    else if (rdbVermelho.isChecked())
        cor = "vermelho";


}

}

Overview of Java server security issues

My goal is to understand what security issues will arise when I use older versions of Java 8 in my server applications. There are many Java security issues, but most are only relevant to client applications.

This vulnerability does not apply to Java implementations, generally on servers …

There is a similar question. But:

  • The question is outdated
  • Of course, you should patch all the software for maximum security. But in practice, updating the software is sometimes associated with high costs. Therefore, you should explain to your administration why there is a security problem and what impacts arise.

So my questions:

  • Are there any lists with Java security issues that are only relevant to server applications?
  • Is there any guide on this topic?

Java: how to fix coverage error for insecure deserilization when calling idle endpoint?

JsonNode response = restTemplate.getForObject(url, JsonNode.class);

Giving error like –
tainted_source: org.springframework.web.client.RestTemplate.getForObject (java.lang.String, java.lang.Class, java.lang.Object ()) returns data from an HTTP request.

the response is deserialized as shown below and gives the following error:

CollectionType collectionType = TypeFactory.defaultInstance().constructCollectionType(List.class,
        Object.class);

Insecure deserialization (UNSAFE_DESERIALIZATION)
3. sink: a response of contaminated value is deserialized. This can allow an attacker to bypass security checks or execute arbitrary code.
(If possible, use pure data formats like JSON or XML to serialize and deserialize untrusted data. Otherwise, if you must use native serialization methods, check the integrity of the data (eg with HMAC) before deserializing it ).

How can we serialize insecure data or how can we make it secure.

java – help needed with address book

I am a new person in the Java world. I started my Java adventure a month ago. I am trying to create my own address book where I can add, edit, search and delete contacts. At this point I was detained because I did not know how to create methods to edit and delete contacts.

Contact class

    import java.util.concurrent.atomic.AtomicInteger;

public class Contact {
    private static AtomicInteger nextID = new AtomicInteger(1);
    private int Id;
    private String FirstName;
    private String Surname;
    private String phoneNumber;
    private String email;
    private String address;

    Contact(int Id, String FirstName, String Surname, String phoneNumber, String email, String address) {
        this.Id = Id;
        this.FirstName = FirstName;
        this.Surname = Surname;
        this.phoneNumber = phoneNumber;
        this.email = email;
        this.address = address;
    }

    Contact(String FirstName, String Surname, String phoneNumber, String email, String address) {
        this(nextID.getAndIncrement(), FirstName, Surname, phoneNumber, email, address);
    }

    int getId() {
        return Id;
    }

    String getFirstName() {
        return FirstName;
    }

    String getSurname() {
        return Surname;
    }

    String
    getPhoneNumber() {
        return phoneNumber;
    }
    String getEmail(){
        return email;
    }
    String getAddress(){
        return address;
    }

    @Override
    public String toString() {
        return"nnId: " + getId() + "nName: " + getFirstName() + "nSurname: " + getSurname() + "nPhone number: "
                + getPhoneNumber() + "nEmail: "  +getEmail() + "nAddress: " + getAddress();
    }

    public static void setNextID(AtomicInteger nextID) {
        Contact.nextID = nextID;
    }

    public void setId(int id) {
        Id = id;
    }

    public void setFirstName(String firstName) {
        FirstName = firstName;
    }

    public void setSurname(String surname) {
        Surname = surname;
    }

    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public void setAddress(String address) {
        this.address = address;
    }
}

And my
Control panel class

private enum Options {
    First_Name,
    Surname,
}

private Data data;
private Scanner sc;
private List contacts;

public AddressBookControlPanel(Data data) {
    sc = new Scanner(System.in);
    this.data = data;
    try {
        contacts = data.loadAllContacts();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

public AddressBookControlPanel(String MyContacts) {
    this(new Data(MyContacts));
}

public AddressBookControlPanel(File file) {
    this(new Data(file));
}

private List searchContact(String searchString, Options options) {
    switch (options) {
        case First_Name:
            return contacts.stream().filter(person ->
                    person.getSurname().equals(searchString)).collect(Collectors.toList());
        case Surname:
            return contacts.stream().filter(person ->
                    person.getFirstName().equals(searchString)).collect(Collectors.toList());
        default:
            System.out.println("Invalid filter option");
            return new ArrayList<>();
    }
}

public void start() {
    while (true) {
        Action option = showMenuAndChoose();
        switch (option) {
            case ADD_CONTACT:
                Contact contact = getContactInformation();
                data.saveContactToFile(contact);
                contacts.add(contact);
                break;

            case EDIT_CONTACT:
                System.out.println("Put the name of contact which you want edit ");
                int index = sc.nextInt() - 1;
                sc.nextLine();
                fillContactInformation(contacts.get(index));
                System.out.println("Contact's list are updated.");
                break;
            case SEARCH_CONTACT:
                Options selectedFilter = showFindPersonFilterOptionsAndGetSelection();
                System.out.print("Enter name: ");
                String searchString = sc.nextLine();
                List filteredContacts = searchContact(searchString, selectedFilter);
                if (filteredContacts.size() == 0) {
                    System.out.println("No matches");
                } else {
                    for (Contact c : filteredContacts)
                        System.out.println(c);
                    break;
                }
            case DISPLAY_ALL_CONTACTS:
                System.out.println(this.contacts);
                System.out.println();
                break;
            case DELETE_CONTACT: // coming soon
                break;
            case EXIT:
                System.out.println(" Program is closed. ");
                System.exit(0);
                break;
        }

    }

}

private Action showMenuAndChoose() {
    System.out.println(" 1. Add new contact ");
    System.out.println(" 2. Edit exisisted contact");
    System.out.println(" 3. Search contact ");
    System.out.println(" 4. Show all contacts ");
    System.out.println(" 5. Delete contact ");
    System.out.println(" 6. Close program ");

    String option;
    option = sc.nextLine();
    switch (option) {
        case "1":
            return Action.ADD_CONTACT;

        case "2":
            return Action.EDIT_CONTACT;

        case "3":
            return Action.SEARCH_CONTACT;

        case "4":
            return Action.DISPLAY_ALL_CONTACTS;

        case "5":
            return Action.DELETE_CONTACT;

        case "6":
            return Action.EXIT;
        default:
            System.out.println(" Choose number from 1 to 6 ");
    }
    while (!option.equals("6")) ;
    return null;
}

private Contact getContactInformation() {
    System.out.println(" Put name ");
    String firstName = sc.nextLine();
    System.out.println(" Put surname ");
    String surname = sc.nextLine();
    System.out.println(" Put phone number ");
    String phoneNumber = sc.nextLine();
    System.out.println(" Put e-mail address ");
    String email = sc.nextLine();
    System.out.println(" Put address ");
    String address = sc.nextLine();
    return new Contact(firstName, surname, phoneNumber, email, address);
}

private Options showFindPersonFilterOptionsAndGetSelection() {
    System.out.println(" 1. Search by name ");
    System.out.println(" 2. Search by surname ");
    System.out.println();
    String option;
    do {
        option = sc.nextLine();
        switch (option) {
            case "1":
                return Options.First_Name;
            case "2":
                return Options.Surname;
            default:
                System.out.println(" Choose number 1 or 2 ");
        }
    } while (option.equals("1") && option.equals("2"));
    return null;
}

private List editContact() {
    List contacts = editContact();
    System.out.println(" Pick person to edit ");
    int index = sc.nextInt() - 1;
    sc.nextLine();
    fillContactInformation(contacts.get(index));
    System.out.println("Contact's list are updated.");


    return contacts;
}

private  Contact fillContactInformation(Contact contacts) {
    System.out.println("Put first name:");
    String name = sc.nextLine();

    System.out.println("Put surname:");
    String surname = sc.nextLine();

    System.out.println("Put phone number:");
    String mobileNumber = sc.nextLine();

    System.out.println("Put email address:");
    String email = sc.nextLine();

    System.out.println("Put address:");
    String city = sc.nextLine();
    contacts.setFirstName(name);
    contacts.setSurname(surname);
    //contacts.setAddress(address);
    //contacts.setId(new Contact.mobileNumber,email));

    return contacts;
} }

Can you help me finish this program? I will be grateful for any help.