How Do You Troubleshoot a Java Compilation Error “class fooBar is public, should be declared public class…”?

Problem scenario
You try to compile a java program, but you get this error:

hello.java:1: error: class HelloWorld is public, should be declared in a file named HelloWorld.java
public class HelloWorld {
^
1 error

What is wrong?

Solution
The .java file must have a name of “HelloWorld” like the public class in the error.

 » Read more..

How Do You Create a Puppet Manifest to Install Java?

Problem scenario
You have Puppet agent and Puppet Master set up and configured to work together. You are are running open source Puppet 5.x on Ubuntu servers in AWS. You want to install Java on the Puppet agent nodes. You tried to use the Java module.

On the Puppet Master server, you ran this: puppet module install puppetlabs-java –version 2.2.0

This is your site.pp file:

class { ‘java’ :
package =’java-1.8.0-openjdk-devel’,  » Read more..

How Do You Write a Java Program to Read in Letters and Numbers?

Problem scenario
You want to have a basic Java program that can read in letters and numbers. How do you write such a program?

Solution
1. Verify the “javac” command works. Run “man javac” to see the man page. If you do not get a man page, install the Java development tools. On a RedHat derivative, run this: sudo yum -y install java-devel

2.

 » Read more..

How Do You Install Java so You Can Compile Programs on a RHEL Server?

Problem scenario
You have installed Java. But you cannot use the javac command. You get errors like this: “-bash: javac: command not found”

How do you install Java so you can compile programs on a RedHat Linux server?

Solution
Run this command: sudo yum -y install java-devel

If you want to do this on a Debian or Ubuntu Linux server,

 » Read more..

How Do You Build a Java Program with Maven?

Problem scenario
You want to use Maven to build a Java program from source code. The code is in at least two different .java files. What do you do?

Solution
Prerequisites
This assumes that you have installed Maven. If you need assistance, see this posting.

Procedures
1.

 » Read more..

How Do You Troubleshoot “Error: Could Not Create the Java Virtual Machine”?

Problem scenario
You ran a Hadoop command but you receive this error:

Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

What do you do?

Solution
Run hadoop help. This error can happen when you have an incorrect flag.

 » Read more..

How Do You Install and Configure the rdf4j Server and Workbench GUI?

Problem scenario
You want to use the rdf4j (Resource Description Framework for Java). You want to install the rdf4j server and workbench. You are using Debian 9 Linux. What should you do?

Solution
Prerequisites
i. We recommend having a 30 GB of hard disk free.

ii. We recommend having 5.75 GB of RAM (it can be a combination of RAM and swap space).

 » Read more..

How Do You Find the Version of Java that is Installed on Your Windows Server?

Problem scenario
You want determine what version of Java is installed (if any). What do you do?

Solution
Open PowerShell and run this command:
(Get-WmiObject Win32_Product | Where {$_.Name -match “Java”}).Version

Alternative way without PowerShell:
1. Go to Control Panel -Uninstall a Program
2. See if Java is installed

 » Read more..

How Do You Troubleshoot the Java Program Message “java.sql.SQLException: No database selected”

Problem scenario
Your Java program returns this message: “java.sql.SQLException: No database selected”
What should you do?

Possible Solution #1
Your SQL statement was appropriate for a database but not for the circumstance of connecting to a SQL instance. Try show databases; instead of the SQL you were running.

Possible Solution #2
Did you connect to the SQL instance you thought you connected to?

 » Read more..

How Do You Run a Java Program to Run SQL Commands Against a MySQL Database?

Problem scenario
You have a MySQL database. Rather than use a SQL front-end application, you want to write a Java program that will run a SQL statement against the database. What should you do?

Solution

1. Install the Java compiler if it is not already installed. If you need assistance, see this posting.

2. Run this command:
curl -Lk https://www.javatpoint.com/src/jdbc/mysql-connector.jar /tmp/mysql-connector.jar

3.

 » Read more..