user interface – How to freely drag and drop elements on IntelliJ IDEA GUI designer for Java?

user interface – How to freely drag and drop elements on IntelliJ IDEA GUI designer for Java?

I Think this still applies
IntelliJ: How to use No Layout or Absolute Layout like Eclipse?

Layout managers in swing has some sort of boundaries that they work with. As far as i have read in the docs the GUI-builder aims to mimic their behaviours (havent used it myself). Its better to learn how they work instead to position your components properly.

user interface – How to freely drag and drop elements on IntelliJ IDEA GUI designer for Java?

Read up on the managers and their behaviour here:
http://docs.oracle.com/javase/tutorial/uiswing/layout/layoutlist.html

user interface – How to freely drag and drop elements on IntelliJ IDEA GUI designer for Java?

object – How to create a custom Iterator in Java?

object – How to create a custom Iterator in Java?

A minimal example would be to return an empty iterator, whose hasNext() always returns false and next() will throw NoSuchElementException.

public Iterator<Foo> iterator() {
    return new Iterator<Foo>() {
        public boolean hasNext() { 
            return false;
        }
        public Foo next() {
            throw new NoSuchElementException();
        }
    };
}

Of course most iterators have states. For example you can iterate from 0 to the integer value the Foo instance holds.

import java.util.Iterator;
import java.util.NoSuchElementException;

public class Foo implements Iterable<Foo> {
    private final int value;

    public Foo(final int value) {
        this.value = value;
    }


    @Override
    public Iterator<Foo> iterator() {
        return new Iterator<Foo>() {
            private Foo foo = new Foo(0);

            @Override
            public boolean hasNext() {
                return foo.value < Foo.this.value;
            }

            @Override
            public Foo next() {
                if (!hasNext()) throw new NoSuchElementException();

                Foo cur = foo;
                foo = new Foo(cur.value+1);
                return cur;
            }
        };
    }

    public static void main(String[] args) {
        Foo foo = new Foo(10);
        for (Foo f: foo) {
            System.out.println(f.value);
        }
    }
}

object – How to create a custom Iterator in Java?

Also Read: object – How to create a custom Iterator in Java?

spring – Exception in Rest Template : Exception in thread main java.lang.NoClassDefFoundError: org/springframework/core/log/LogDelegateFactory

spring – Exception in Rest Template : Exception in thread main java.lang.NoClassDefFoundError: org/springframework/core/log/LogDelegateFactory

You need to have spring core on your classpath.

Try adding

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
    <version>5.2.8.RELEASE</version>
</dependency>

spring – Exception in Rest Template : Exception in thread main java.lang.NoClassDefFoundError: org/springframework/core/log/LogDelegateFactory

spring – Exception in Rest Template : Exception in thread main java.lang.NoClassDefFoundError: org/springframework/core/log/LogDelegateFactory

java Array maxSpan

java Array maxSpan

https://github.com/mirandaio/codingbat/blob/master/java/array-3/maxSpan.java

If you refer to the code hosted on GitHub at the link above.
As you can read in the documentation, the maxSpan function returns the (max) numbers of elements between two occurrences of a number.
For example:
maxSpan([1, 2, 1, 1, 3]) → 4
the first 1 and the last 1 elements in the array generate the maxSpan value of 4.

 public int maxSpan(int[] arr) {

        int n = arr.length;

        if(n == 0)
            return 0;
        if(n == 1)
            return 1;

        int loIdx = 0;
        int hiIdx = 0;

        for (int i = 0, j=n-1; i < n && j>=0; i++, j--) {
            if(arr[0]== arr[i])
                loIdx = i;
            if(arr[n-1] == arr[j])
                hiIdx = j;
        }
        return Math.max(loIdx+1, n-hiIdx);
}

java Array maxSpan

java Array maxSpan

multithreading – The difference between BLOCKED and TIMED_WAITING on java

multithreading – The difference between BLOCKED and TIMED_WAITING on java

You’re right, the thread state for a Thread inside the method Thread.sleep should be TIMED_WAITING.

multithreading – The difference between BLOCKED and TIMED_WAITING on java

To cite the authoritative source:

public static final Thread.State TIMED_WAITING

Thread state for a waiting thread with a specified waiting time. A thread is in the timed waiting state due to calling one of the following methods with a specified positive waiting time:

  • Thread.sleep
  • Object.wait with timeout
  • Thread.join with timeout
  • LockSupport.parkNanos
  • LockSupport.parkUntil

I tested several Java versions (Oracle’s implementation) in the range 1.6 to 1.8, inclusive, and all show the correct behavior of reporting threads inside Thread.sleep with the state TIMED_WAITING.

It’s also important to consider the following statement about Thread.sleep():

… The thread does not lose ownership of any monitors.

So, since the thread does not lose ownership of monitors, it won’t reacquire monitors. So it shouldn’t be in Thread.State.BLOCKED.

So either you are using a different JVM/JRE implementation or a modified Thread class, maybe it has been modified via Instrumentation at runtime. In either case, the information you have given in your question are not enough to narrow your problem further.

It would be useful as well to know which version of jstack you have used as the output has a different format than I got. Maybe it’s the tool which prints the state wrong…

multithreading – The difference between BLOCKED and TIMED_WAITING on java

multithreading – The difference between BLOCKED and TIMED_WAITING on java

java – Getting warning SLF4J :Class path contains multiple SLF4J bindings

java – Getting warning SLF4J :Class path contains multiple SLF4J bindings

You have to use the information SLF4J provide you and back trace the dependency using dependency:tree and its includes option.

This message:

SLF4J: Found binding in [jar:file:/Users/macuser/.m2/repository/ch/qos/logback/logback-classic/1.2.10/logback-classic-1.2.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/macuser/.m2/repository/org/apache/logging/log4j/log4j-slf4j-impl/2.17.1/log4j-slf4j-impl-2.17.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]

Means that the following dependencies are being imported:

  • ch.qos.logback:logback-classic:1.2.10:jar
  • org.apache.logging.log4j:log4j-slf4j-impl:2.17.1:jar

Then you can filter your dependency tree using -Dincludes=

mvn dependency:tree -Dincludes=ch.qos.logback:logback-classic,org.apache.logging.log4j:log4j-slf4j-impl

You may omit the version and type here because thats not really important.

This will give you the exact dependencies you will have to exclude.

And from the dependencies you reference, I think your problem lies in the use of Log4J2 with a SLF4J bindings whereas spring boot use SLF4J with Logback as default implementation.

You can read this to use log4j2 with Spring boot: https://www.callicoder.com/spring-boot-log4j-2-example/

java – Getting warning SLF4J :Class path contains multiple SLF4J bindings

Related posts

Unable to import gpdraw in Java

Unable to import gpdraw in Java

The problem is that gpdraw is not included in Java per default. As MadProgrammer pointed out, you have to include the library in your compile/runtime classpath.

  • BlueJ:

    The first way is via the Preferences dialog. Open the Preferences dialogue and select the Libraries tab. Then add the location where your classes are as a library path. Restart BlueJ – done. The selected libraries will now be available in all projects that you open.
    (http://www.bluej.org/faq.html)

  • Command:
    javac -sourcepath src -classpath path/to/gpdraw.jar
    

    (http://ubuntuforums.org/showthread.php?t=637270)

Unable to import gpdraw in Java

Unable to import gpdraw in Java

node.js – MongoDB error as setup Wizard ended prematurely, while installing it on windows 10

node.js – MongoDB error as setup Wizard ended prematurely, while installing it on windows 10

For me unchecking Install Compass helped …

I disabled installing the router (mongos) and bundeled software client (MongoDB Compass) and installer ran fine after that. Hope this helps.

node.js – MongoDB error as setup Wizard ended prematurely, while installing it on windows 10

node.js – MongoDB error as setup Wizard ended prematurely, while installing it on windows 10

I had this problem too and solve it in this way:

  • Remove the older version of MongoDB if you have installed it before.
  • Disable your antivirus if you have any of them
  • Go to C:>users>UserName>AppData>Local>Temp
  • Right Click on Temp and go to Properties
  • Select Security Tab
  • Select the User and check the permission and controll give the user full control by Checking Full Control on permission
  • Go Ahead and Install MongoDB.

Note that if you want to install MongoDB compass too, you should have internet connection.

I hope this will work for you.

javascript – Simple MongoDB query find item age > 10 learnyoumongo find function

javascript – Simple MongoDB query find item age > 10 learnyoumongo find function

The problem was two pronged – The main issue was I was expecting to be able to run the query with node test.js, and see the results from the parrots collection. But learnyoumongo has atomic tests, meaning they clear the database entirely before and after, so the only way to test was learnyoumongo test.js, and I kept getting an empty result set running the node command.

The other issue was with db.close(), you cant just call db.open and then db.close, because open is async and it would close right after opening, hence the sockets closed error. So you put db.close in the toArray function, or in any other callback of db.open.

Also Read: javascript – Simple MongoDB query find item age > 10 learnyoumongo find function

javascript – Simple MongoDB query find item age > 10 learnyoumongo find function

asp.net ajax – Javascript Sys.Application.add_init

asp.net ajax – Javascript Sys.Application.add_init

Based on your description, seems like the user is clicking the button before the full initialization happens. So I would guess whats happening is that either they are really moving through the application fast, or their computers could be slower (meaning slower rendering time) and they may have a slower internet connection, thus causing the page to run slower and these weird errors happen to occur. Ive experienced this one (both computer slowness and network slowness) as being the cause of these kinds of issues.

Or there was some random error in the framework that caused the page to break, and the user didnt notice it.

asp.net ajax – Javascript Sys.Application.add_init

asp.net ajax – Javascript Sys.Application.add_init