How Do You Troubleshoot the Java Compilation Problem “error expected … illegal start of type”?

Problem scenario
When trying to compile a Java program, you get this output:

ContInt.java:15: error: expected
System.out.println("test");
^
ContInt.java:15: error: illegal start of type
System.out.println("test");
^

What do you do?

Solution
Create a class for the System.out.println statement to be in.

Here is code that would cause the error:

import java.util.Scanner;

public class TicTacToe {

public static void main(String[] args) {
   System.out.println("Please enter text, then press enter: ");
   Scanner x = new Scanner(System.in);
   String var1 = x.next();
   System.out.println(var1);
   }

class board {
   System.out.println("test");
  }

}

Here is code that would not cause the error:

import java.util.Scanner;

public class TicTacToe {

public static void main(String[] args) {
   System.out.println("Please enter text, then press enter: ");
   Scanner x = new Scanner(System.in);
   String var1 = x.next();
   System.out.println(var1);
   }

class board {
   board() {
   System.out.println("test");
   }
  }

}

How Do You Use Amazon Simple Queue Service?

Problem scenario
You want to use Amazon SQS. How do you use this in AWS?

Solution

  1. Log into the AWS console.
  2. Go here: https://console.aws.amazon.com/sqs/
  3. Click "Get Started"
  4. Enter a queue name (e.g., contintqueue)
  5. Click "Quick-Create Queue"
  6. Click the radio button associated with the queue. Then click "Queue Actions" (the button near the top left).
  7. Click "Send a message"
  8. Enter some text and click "Send Message."
  9. Click "Close."
  10. Click "Queue Actions" again.
  11. Click "View/Delete Messages"
  12. Click "Start Polling for Messages"
  13. Click on the message you want to view.

How Do You Troubleshoot “error: no suitable method found for toString(String)”?

Problem scenario
You are trying to print out a multi-dimensional array in Java. When you try to compile your program, you get this:

error: no suitable method found for toString(String)
System.out.println(Arrays.toString(Arrays.toString(var1)));
^
method Arrays.toString(long[]) is not applicable
(argument mismatch; String cannot be converted to long[])

What should you do?

Solution
You need to pass a one-dimensional array to Arrays.toString in the System.out.println statement.

Are you using Arrays.toString in a nested way?

Assuming you have a two-dimensional array called "arr2d_var1", you may have tried this:

System.out.println(Arrays.toString(Arrays.toString(arr2d_var1)));

Instead of using Arrays.toString in a nested way, make sure you have a single-dimensional array as the argument for Arrays.toString. Here is a corrected example:

System.out.println(Arrays.toString(arr2d_var1[0]));

How Do You Install Apache Presto on Any Type of Linux?

Problem scenario
You want to install Apache Presto to try it out. How do you do this with a script that will work on Debian/Ubuntu, CentOS/RHEL/Fedora and/or SUSE?

Solution
Prerequisites
i. You have Python installed as "python" (not just python3). If you need assistance installing Python, see this posting. Verify that python --version works. You may need to use sudo ln -s $(which python) /bin/python

ii. You have Java installed. If you need assistance, see this posting.

Procedures
1. Use this script (e.g., like "sudo bash /tmp/presto.sh" and read the last few lines as they provide for manual steps done from different terminal windows):

version=0.240
#0.149 was a stable version
# The next version of this should be .343.  It doesn't have a launcher.py file.  It was seriously refactored. 
# Some lines will have to be commented out or deleted.  The future URLs will be like this:
# https://repo1.maven.org/maven2/io/prestosql/presto-server/343/presto-server-343.tar.gz
# https://repo1.maven.org/maven2/io/prestosql/presto-cli/343/presto-cli-343-executable.jar


echo "This assumes that Python and Java have already been installed"
echo "This script requires Python 3 unlike normal versions of Presto.  You could modify the script where it downloads the launcher.py file"
echo "That launcher.py file is the only thing that requires Python 3.  The installation media it uses would otherwise default to utilize Python 2"
echo "**************************************************************************************"
echo "This script needs access to the internet to download the installation media for Presto"
curl https://repo1.maven.org/maven2/com/facebook/presto/presto-server/$version/presto-server-$version.tar.gz > /tmp/presto-server-$version.tar.gz
cp /tmp/presto-server-$version.tar.gz /opt/
cd /opt/
sudo tar -xvf presto-server-$version.tar.gz
cd presto-server-$version
mkdir /data # With RHEL servers, this is unnecessary.
cd /data
mkdir presto
cd /opt/presto-server-$version
mkdir etc
echo "Getting special files from GitHub.  If the .config and .properties files have trailing spaces or spaces near = signs, there can be issues."
echo "That is why we get the special files known to work from GitHub"
curl https://raw.githubusercontent.com/ContinualIntegration/presto/master/config.properties > /tmp/config.properties
curl https://raw.githubusercontent.com/ContinualIntegration/presto/master/jvm.config > /tmp/jvm.config
curl https://raw.githubusercontent.com/ContinualIntegration/presto/master/log.properties > /tmp/log.properties
curl https://raw.githubusercontent.com/ContinualIntegration/presto/master/node.properties > /tmp/node.properties
curl https://raw.githubusercontent.com/ContinualIntegration/presto/master/launcher.py > /tmp/launcher.py

mv /tmp/config.properties /opt/presto-server-$version/etc/config.properties
mv /tmp/jvm.config /opt/presto-server-$version/etc/jvm.config
mv /tmp/log.properties /opt/presto-server-$version/etc/log.properties
mv /tmp/node.properties /opt/presto-server-$version/etc/node.properties
mv /tmp/launcher.py /opt/presto-server-$version/bin/launcher.py

curl https://repo1.maven.org/maven2/com/facebook/presto/presto-cli/$version/presto-cli-$version-executable.jar > /tmp/presto-cli-$version-executable.jar

cp /tmp/presto-cli-$version-executable.jar /bin/presto
chmod +x /bin/presto
chmod +x /opt/presto-server-$version/bin/launcher.py
echo "*************************************"
echo "The installation script has finished."
echo "*************************************"
echo "Run these five Linux commands and the last Presto SQL-like command:
cd /opt/presto-server-$version/bin
sudo ./launcher start
sudo ./launcher run -Djdk.attach.allowAttachSelf=true
cd /bin/
./presto --server localhost:8080 --catalog jmx --schema default
You should see the last line look like this:   com.facebook.presto.server.PrestoServer ======== SERVER STARTED ========
If the last line does not look like that, try to "./presto --server localhost:8080 --catalog jmx --schema default" command again.

After you have run those commands and are at the Presto CLI, run this command:
SELECT * FROM system.runtime.nodes;
"

2. Most likely you will need a second terminal to issue the final two Linux commands and the Presto SQL-like command as described at the bottom of the script above. Some error messages are ignorable, while sometimes you have to run the ./presto --server localhost:8080 --catalog jmx --schema default command twice.

FFR
This link may be of assistance to you for more installation media and peripherals:

How Do You Configure an External Monitor’s Placement with a Macbook Pro?

Problem scenario
You have a Mac laptop. You have connected a separate monitor. To get your mouse one the screen, you have to move the direction of the mouse in a different direction relative to the physical location of where you see this external monitor. You have to commit to memory where to move the mouse. You want the external monitor to be mouse-reachable in the direction that it is in front of you. How can you get the position to match?

Solution
Go to the Apple symbol in the upper-right hand corner. Go to System Preferences -> Displays. Click on "Gather Windows." Go to Arrangement. Click on the blue rectangles to identify which monitor is which. Move the rectangles in a way that reflects their physical location.

How Do You Create a Callable Function in Java outside of the “main” Section?

Problem scenario
You have a public static void main (String[] args) portion of your Java program. You want to have a subroutine such as a function outside of this section. How do you code this?

Solution
In Java methods are components of an object that perform an action on the object themselves. We therefore use the term "method" here and not "function". Here is an example of a method inside a class that runs from the public static void main(String[] args) section of code:

public class ContClass {
  static void contMethod() {
    System.out.println("I just got executed!");
  }

  public static void main(String[] args) {
    contMethod();
  }
}

Call the above file ContClass.java. Run these commands:

javac ContClass.java
java ContClass

How Do You Troubleshoot the Error “Could not find suitable distribution for Requirement.parse(‘botocore==2.0.0dev11’)”?

Problem scenario
You try to install the AWS CLI version 2.x

You run this command:

$ sudo python3 setup.py install

You get a message like this:

Processing dependencies for awscli==2.0.7
Searching for botocore==2.0.0dev11
Reading https://pypi.org/simple/botocore/
No local packages or working download links found for botocore==2.0.0dev11
error: Could not find suitable distribution for Requirement.parse('botocore==2.0.0dev11')

What should you do?

Possible solution (or workaround)
Abort. Try installing AWS CLI 1.x. You can use these directions as a guide.