Swapping elements in an array Java

I am working on a classes challenge in school. We have to great a Boat class and Harbor class. I have gotten every test to work except the final test of where boats are parked in the Harbor. The …

Print user inputs from 2D array using another class in Java?

I am trying to print user inputs in another class in Java. I have made a chessboard which asks the user to input strings on the board, and then, when these strings are printed on screen, I would like …

Casting an Object into a Class of type T

Let’s say I have an empty class called ClsA(), and a subclass of it called ClsB() like so: public static class ClsA {} public static class ClsB extends ClsA {} Supposing that we now have an …

Object array with variable from another class

Worksheet Question: The question said to declare an array of 5 objects of the class Node in the main Class – I managed to this as shown below But then the question continues populate the array by …

Variable value not being passed into another class

I’m trying to let the user to choose which option is in their menu, and setting the variables based on the option that the customer choose, but when I go to another class and retrieve it, there is no …

How to create a new object of Public Class

I am a newbie in Java, although I have knowledge of Object Oriented Programming from Python but I’m currently having problem understanding this example on creating public class either combining the …

What is the purpose of a static method in interface from Java 8?

Why are static methods supported from Java 8? What is the difference between the two lines in main method in below code? package sample; public class A { public static void doSomething() { …

Java ClassLoader: load same class twice

I have a ClassLoader which loads a class compiled by JavaCompiler from a source file. But when I change the source file, save it and recompile it, the ClassLoader still loads the first version of the …

What is this: [Ljava.lang.Object;?

I get this when I call toString on an object I received from a function call. I know the type of the object is encoded in this string, but I don’t know how to read it. What is this type of encoding …

Problem with Inner Class. Illegal Start of Expression error

I am practicing using inner classes but am having difficulty with a homework question: It is as follows: Create a Swing component class BetterButtons that extends JPanel and has three Jbutton …