N-Queens with first queen placed

I have an assignment in Java- place n queens on n by n board so that none is attacking each other.
The position of the first queen is given. My issue is when I initialize the board (multidimensional array) the rows are skipped and the first queen placed is not being moved.
How do I place the first queen on selected position and backtrack so it will be moved?
It’s a homework so just part of my code:

    boolean nQueens (int board[][], int level, int N) {
    if (level == N) {
        return true;

    for (int j = 0; j < N; j++) {

        if (notSafe(j, level, board, N)) {

        board[j][level] = 1;

        if(nQueens(board, level+1, N)) {
            return true;

        board[j][level] = 0;

    return false;

Jax-WS with NTLM authentification

As I read Jax-ws can authenticate with NTLM, but I have a problem;
First of all I create MyAuthenticator java class as describe in java documentation(see:

when I try to connect with soapUI everything is Ok, see request header:

Request Headers Value
(Request-Line)  POST /Online/OnlineServices.asmx HTTP/1.1
Content-Type    text/xml;charset=UTF-8
SOAPAction  "http://CTL.COM/OnlineServices/AcquireTicket"
Connection  Keep-Alive
User-Agent  Apache-HttpClient/4.1.1 (java 1.5)
Accept-Encoding gzip, deflate
Content-Length  702 

when I try to connect with java, I got 500 Internal server error, see header:

Request Headers Value
(Request-Line)  POST /Online/OnlineServices.asmx HTTP/1.1
SOAPAction  "http://CTL.COM/OnlineServices/AcquireTicket"
Accept  text/xml, multipart/related, text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Content-Type    text/xml;charset="utf-8"
User-Agent  JAX-WS RI 2.1.4-b01-
Connection  keep-alive
Accept-Encoding gzip, deflate
Content-Length  443

this is my code :

        Authenticator.setDefault(new MyAuthenticator(domain + "\kuser","kpass"));
        OnlineServicesSoap onlineServicesSoap = new OnlineServices(url, qName).getOnlineServicesSoap();
        Map<String, List<String>> headers = new HashMap<String, List<String>>();
        headers.put("Content-Type", Collections.singletonList("text/xml;charset=UTF-8"));
        headers.put("Accept-Encoding", Collections.singletonList("gzip, deflate"));
        ((BindingProvider) onlineServicesSoap).getRequestContext().put(MessageContext.HTTP_REQUEST_HEADERS, headers);
        try {
            AcquireTicketResponse acquireTicketResponse = onlineServicesSoap.acquireTicket(acqTicket);
        } catch (RuntimeException ex) {
            System.out.println(ex.getMessage() + ex.getCause());

I searched a lot and found some posts suggesting to do NTLM authentication but I couldn’t to connect.. I don’t want to use axis implementation

Spring Boot: how to get localized messages from JSR 303 Bean Validation messages?

In my Spring Boot app, I have a regular MessageSource set up and it without any issues it resolves multi-lingual messages based on the HTTP Accept-Language header.

However, it does not work for any messages coming from Bean Validation annotations, those always come in English. It’s as if they never pick up the current Locale.

Here is my global exception handler:

public ResponseEntity<ErrorSummary> handleConstraintViolationException(ConstraintViolationException e) {

    Locale l = LocaleContextHolder.getLocale();

    Set<Error> errors = e.getConstraintViolations().stream()
            .map(v -> new Error(v.getMessage(), String.valueOf(v.getPropertyPath())))

    return new ResponseEntity<>(new ErrorSummary(errors), HttpStatus.BAD_REQUEST);

When I debug I can see my Locale variable is “fr” (French), but all the constraint validation messages are in English.

Android app dependencies ClassNotFoundException

I’m new in Android development. Not very new in ordinary EE Java and Gradle.

So I am trying to build a REST consumer app for Android. I have a (1) .jar file I will need (contains DTOs and api consumers). That (1) .jar has dependencies on other (2) jars from Nexus repo. These (2) do depend on other (3) jars (e.g. apache commons lang3, etc.) from maven repos.

The funny thing is that… The app compiles and install just fine. But on runtime it occasionaly tends to lose some classes from (1) (at least (1) — dunno about (2) and (3) yet).

I know SO does not like pics in questions, but in this case I believe pics = clarity.

See below. Same runtime, same jar. Except one of the classes is not loaded, and another one, sitting right next to it, is available.

Some classes are not seen by the classloader

And some are seen

Why is that so? What did I do wrong?

One more thing… If I attempt to instantiate one of the missing classes (there’s more than one) in main activity (inside onCreate()), sometimes that class appears in the classpath and creates an object just fine. But as ridiculous as it may sound some other class goes missing! It feels like Classloader has limited number of slots for classes it could possibly handle.

Error downloading a File using JSF and OMNIfaces

I have an entity like this

public class myFiles  implements Serializable{

    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int idmyFiles;

    private File myFile;

geters and setters...

I have an upload form that seems to work, when I upload a file I can see it in the postgtes table.

IN the form (I am using primefaces) I have this

          <p:fieldset id="myFiles" class="recuadro" legend = "Upload a fileos" >      

                                <p:fileUpload value="#{abmBean.fichero}" mode="simple"  />

                                <p:commandButton   id="btnSubir" ajax="false" process="@all" update="@all"  action="#{abmBean.uploadFile()}" value="Subir" />


This is the method that uploads the file

public void uploadFile()

            File destFile = new File("/tmp/"+fichero.getFileName());
            FileUtils.copyInputStreamToFile(fichero.getInputstream(), destFile);

    /* Then I just create a myFile object F and just F.setFile(destFile) */

It seems to work

To download the file I have this method

public downloadFile(int id)

/* the int id is the id of the myfile object F */

/* I retrieve from the database the F object and then this*/
    File fichero = new File("/tmp/"+F.getFile.getName());

                FileUtils.copyFile(F.getFile, fichero);

                Faces.sendFile(fichero, true);


This works just fine and I have the file back

But the problem is this, I realize that the file I uploaded was also copied to the /tomcat7/bin folder andif I remove the file from there then when I want to dowload it I get a fileNotFoundException.

All I need is to be able to provide the user the file from the database

I am using Tomcat7, Java 1.6 (yes pretty old) Primefaces 6, Postgresql 9.1 and JSF2 on a Debian

Java – && for two dimensional arrays

I’m trying to have an if statement that looks at characters in a 2D array and sees whether three of them are all the same character at the same time (in order to make a game of Tic Tac Toe, and ran into the same error :

bad operand types for binary operator '&&'
                if (TicTac[0][0] && TicTac[0][1] && TicTac[0][2] == 'x') {

Incidentally I was wondering how I can make it work.

Inconsistent byte array read when sent from PC to PC and from PC to Android

I have a Server application on my PC which reads a jpg file and sends it through a socket to the android device. The problem is that when android device receives a byte array, it can’t be converted to bitmap. I created a PC application to receive that same array and the data received is different than on the android even though I am using the same code to receive it.

Hence my assumption is that I somehow need to read it differently on android.

PC Java Server

        ServerSocket serverSocket = new ServerSocket(PORT);
        Socket clientSocket = serverSocket.accept();

        BufferedImage image = ImageIO.read(new File("D:\test1\test.jpg"));
        ByteArrayOutputStream byteArrayoutputStream = new ByteArrayOutputStream();
        ImageIO.write(image,  "jpg", byteArrayoutputStream);
        OutputStream outputStream = clientSocket.getOutputStream();

        byte[] size = ByteBuffer.allocate(4).putInt(byteArrayoutputStream.size()).array();


Android receiver

    DataInputStream inputStream = new 

    byte[] sizeAr = new byte[4];
    int size = ByteBuffer.wrap(sizeAr).asIntBuffer().get();

    byte[] imageAr = new byte[size];
    bMap = BitmapFactory.decodeByteArray(imageAr, 0, imageAr.length);//this returns null

Why the number of wifi connections: 0?

I want to show Wifi connection list with android studio. There are 2 connections on wifi settings of my phone but my application doesn’t see them.

Thanks in advance

When I open debug application i see this sentence:
Number Of Wifi connections : 0

So why It can’t see wifi connections?
I tried when wifi is enabled and when it’s disabled.


import java.util.List;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.widget.TextView;

public class MainActivity extends Activity {

private StringBuilder sb = new StringBuilder();
private TextView tv;
List<ScanResult> scanList;

protected void onCreate(Bundle savedInstanceState) {
    tv= (TextView)findViewById(R.id.txtWifiNetworks);

private void getWifiNetworksList(){
    IntentFilter filter = new IntentFilter();
    final WifiManager wifiManager =
    registerReceiver(new BroadcastReceiver(){

        @SuppressLint("UseValueOf") @Override
        public void onReceive(Context context, Intent intent) {
            sb = new StringBuilder();
            scanList = wifiManager.getScanResults();
            sb.append("n  Number Of Wifi connections :" + " " +scanList.size()+"nn");
            for(int i = 0; i < scanList.size(); i++){
                sb.append(new Integer(i+1).toString() + ". ");




<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"



Check if ActionPerform method occured but from another class

How to check from a class ModalDialog extends JDialog implements ActionListener if actionPerformed(ActionEvent e) method ocurred in another class (Connect extends JFrame implements ActionListener)? And one step further, how to check which of two buttons that I have in ModalDialog fired ActionPerformed method? (I know about event.getSource, but I need to check it from another class).

public ModalDialog()
    btn8 = new Button("human");
    btn8.setMaximumSize(new Dimension(60,40));

    btn9 = new Button("robot");
    btn9.setMaximumSize(new Dimension(60,40));
public void actionPerformed(ActionEvent e)

class Connect extends JFrame implements ActionListener 
public void actionPerformed(ActionEvent e) 
    ModalDialog md = new ModalDialog();
    if(md.ActionPerformed(e)....)...something like that...

Return string from boolean method

I have the following class diagram.

enter image description here

I need to output a toString that looks like ” James, Sid (1234): Director at £100000.0 (£29822.0 tax) and is eligible for bonus

However i cannot find a way to print out the part where it return whether an employee is eligible for bonus or not.

Any help is much appreciated!

Here is my attempt to create the class.

package org.com1027.formative.ye00036;

public class Employee {
    //Class Field(s)
    private int id = 0;
    private String forename = null;
    private String surname = null;
    private Salary salary = null;
    private CompanyPosition companyPosition = null;

    //Parameterised constructor using all fields, allowing creation of objects
    public Employee(int id, String forename, String surname, Salary salary, CompanyPosition companyPosition) {
        this.id = id;
        this.forename = forename;
        this.surname = surname;
        this.salary = salary;
        this.companyPosition = companyPosition;

    //Returns the employee's ID
    public int getId() {
        return id;
    //Returns the employee's Forename
    public String getForename() {
        return forename;
    //Returns the employee's Surname
    public String getSurname() {
        return surname;
    //Returns the employee's Salary
    public Salary getSalary() {
        return salary;
    //Returns the employee's Company Position
    public CompanyPosition getPositionName() {
        return companyPosition;
    //Checks if an employee is eligible for bonus
    public boolean eligibleForBonus(){
        if (salary.getSalary() >= 40000) 
            return true;
            return false;

    public String toString() {
        return getForename() + ", " + getSurname() + "(" + getId() +
                "): " + getPositionName() + "at " + salary.getSalary() + " (" + salary.calculateTax() + ") and is ";