Why am I able to call on String class methods with a String literal?

First of all, I am using the Drjava interactions pane to test all the codes that I am posting here(I do not have access to any other IDE in my current situation).
I have noticed that I am able to call methods that belong to the String class with string literals as well as string objects. That is,

String s1 = "a";  

s1 has access to all String methods such as getBytes(), length(), charAt(), etc.

While in the case of integers, an int variable doesn’t have access to the methods that are within the Integer class.

Why is this the case?

On a side note:

When I try to compare two string literals with the same value, as in

String s1 = "a";
String s2 = "b";

s1 == s2;

The boolean I get is false, which is not supposed to be the case according to the numerous post/articles I have read on string literals vs string objects.

Does this have something to do with how the Drjava functions specifically? Is that a part of why I am able to call on String methods with string literals?

Image on JButton

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Image;
import javax.imageio.ImageIO;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;

public class Test extends JPanel {

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {

    private static void constructGUI() {
        JFrame frame = new JFrame("Testy");

        JPanel centerPanel = new JPanel();
        centerPanel.setPreferredSize(new Dimension(100, 400));
        frame.add(centerPanel, BorderLayout.CENTER);

        Test eastPanel = new Test();
        frame.add(eastPanel, BorderLayout.EAST);


    public Test() {

        setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
        Dimension d = new Dimension(50, 50);

        JButton button1 = new JButton("");

        button1.setIcon(new ImageIcon(this.getClass().getResource("/Pictures/ellipse.png")));

        button1.setMaximumSize(new Dimension(Integer.MAX_VALUE, button1.getMinimumSize().height));

        JButton button2 = new JButton("");

        button2.setIcon(new ImageIcon(this.getClass().getResource("/Pictures/ellipse.png")));

        button2.setMaximumSize(new Dimension(Integer.MAX_VALUE, button2.getMinimumSize().height));

        JButton button3 = new JButton("");

        button3.setIcon(new ImageIcon(this.getClass().getResource("/Pictures/ellipse.png")));

        button3.setMaximumSize(new Dimension(Integer.MAX_VALUE, button3.getMinimumSize().height));




enter image description here

In my program I am trying to put the ellipse picture on top of all my buttons. As you can see in the image I posted, the ellipse.png is in the “Pictures” source folder.

However, the image does not appear on the JButtons for some reason.

I have read many posts but I can’t see a way to solve my problem.

Also, here is a link to the actual ellipse picture:


Apache FOP 2.2 Include Fonts using Relative Path

I’m setting up a fop.xconf and configuring which fonts are available to Apache FOP and would like to use a relative path rather than an absolute path:

<fop version="1.0">

    <default-page-settings height="11in" width="8.26in"/>

    <hyphenation-pattern lang="en" country="ZA">en_ZA</hyphenation-pattern>

        <renderer mime="application/pdf">
            <directory recursive="true">/Users/me/Code/company/project/src/main/resources/templates/fonts</directory>
                    <from font-family="Helvetica" />
                    <to font-family="OpenSans" />

Is it possible to set that fonts directory inside renderers to use a relative path?

Or is possible to set it programmatically in which case I could make use of


to get the full path?

2017-10-24 05:24:48,591 WARN  org.apache.fop.apps.FOUserAgent - The font directory ./fonts could not be found.
2017-10-24 05:24:48,591 WARN  org.apache.fop.apps.FOUserAgent - The font directory ./templates/fonts could not be found.
2017-10-24 05:24:48,591 WARN  org.apache.fop.apps.FOUserAgent - The font directory ./resources/templates/fonts could not be found.

nested for loop even number print out

hello I am writing a code that will print even integers after the 10th number it will start on a new line so it will be 10 numbers per column and 10 rows. my code is printing all number but i want it to only print even numbers i tried to use an if statement but it does not seem to work please help. below is my code.

public static void mjj() {
    int s = 1;
    for (int i = 1; i <=10;i++) {
        for (int j = 1; j <=10;j++) {
            if (s % 2 == 0)
                System.out.print(s++ + " ");


1 2 3 4 5 6 7 8 9 10 
11 12 13 14 15 16 17 18 19 20 
21 22 23 24 25 26 27 28 29 30 
31 32 33 34 35 36 37 38 39 40 
41 42 43 44 45 46 47 48 49 50 
51 52 53 54 55 56 57 58 59 60 
61 62 63 64 65 66 67 68 69 70 
71 72 73 74 75 76 77 78 79 80 
81 82 83 84 85 86 87 88 89 90 
91 92 93 94 95 96 97 98 99 100 

i want it to print this

2 4 6 8 10 12 14 16 18 20 
22 24 26 28 30 32 34 36 38 40

and so on until the 10th row

How to indicate the position in a Java class within an if statement?

I would like some advice, I want to evaluate my position within a java class and from that run some code using an if statement.

This is part of my code in Android Studio


    public void onBindViewHolder(PictureViewHolder holder, final int position) {
        PictureListPizza pictureListPizza = pictureListPizzas.get(position);

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                if (PizzaActivity.class != null){
                    if(position == 0){
                        Intent intent = new Intent(activity, Pizza1Activity.class);
                    if(position == 1){
                        Intent intent = new Intent(activity, Pizza2Activity.class);
                    if(position == 2){
                        Intent intent = new Intent(activity, Pizza3Activity.class);



As you can see I am placing if (PizzaActivity. class! = null){} but I know it is wrong.

It’s for an android project.

I hope you can help me, thank you in advance.


How to create an ArrayList from a dialog box in JavaFX?

Hello having trouble creating an array from a dialog box. I am able to type in the dialog and print out index [0] of ArrayList list. But when I press Ok it restarts and replaces index [0] instead of adding to the array list. How do I get the application to keep running instead of restarting?

Original Assignment: Going back to the GUI assignment. You can modify this to use JavaFX if you want to.
Create an application that has a button that has “Enter your info.” When clicked it will present a JDialog that has labels and text boxes that allow the user to enter their name, email, and phone number. The JDialog will have buttons OK and Cancel.
When the user clicks Cancel, the dialog will go away without doing anything else.
When the user clicks OK, the user’s information will be extracted from the dialog, and dumped out on the console.
Notice that you only are listening for Click events.
We will add to that spec.
Define a class to hold the info for a single person. Declare an ArrayList of this type. When the user clicks OK, extract the info from the dialog. This time, pass the info to the constructor method of your class that will hold the info. Add this newly created object to your array list.
Using an enhanced for loop, dump the ArrayList onto the console.
Add several user info’s to the ArrayList, each time, dumping the entire list to the console.
Sort the ArrayList. Dump the ArrayList onto the console.

public class UsefulGUI extends Application {

    public void start(Stage primaryStage) {
        Button button = new Button();
        button.setText("Enter your info");
        button.setOnAction(new EventHandler<ActionEvent>() {
            public void handle(ActionEvent event) {

        StackPane pane = new StackPane();

        Scene scene = new Scene(pane, 500, 300);

        primaryStage.setTitle("Useful GUI");
    public class User {
        private String name;
        private String email;
        private String phone;

        public User(String n, String e, String p) {
            this.name = n;
            this.email = e;
            this.phone = p;
        public String toString() {
            return "Name: " + name + " Email: " + email + " Phone: " + phone;
    public void dialogBox() {
        Dialog<User> dialog = new Dialog<>();
        ArrayList<User>list = new ArrayList<User>();

        dialog.setTitle("User info");

        Label name = new Label("Name: ");
        Label email = new Label("Email: ");
        Label phone = new Label("Phone: ");
        TextField textName = new TextField();
        TextField textEmail = new TextField();
        TextField textPhone = new TextField();

        GridPane grid = new GridPane();
        grid.add(name, 1, 1);
        grid.add(textName, 2, 1);
        grid.add(email, 1, 2);
        grid.add(textEmail, 2, 2);
        grid.add(phone, 1, 3);
        grid.add(textPhone, 2, 3);

        ButtonType buttonType = new ButtonType("Ok", ButtonData.OK_DONE);
        dialog.getDialogPane().getButtonTypes().addAll(buttonType, ButtonType.CANCEL);

        dialog.setResultConverter(new Callback<ButtonType, User>() {
            public User call(ButtonType b) {
                if (b == buttonType) {
                    return new User(textName.getText(), textEmail.getText(), textPhone.getText());
                return null;
        Optional<User>info = dialog.showAndWait();

        // Adds user to list
        list.add(new User(textName.getText(), textEmail.getText(), textPhone.getText()));
        System.out.print("Info Added.n NEWUSER ");
        System.out.println(new User(textName.getText(), textEmail.getText(), textPhone.getText()));

        for (int i = 0; i < list.size(); i++) {
            System.out.println(i + ". " + list.get(i));

        //if (info.isPresent()) {
        //  System.out.println(info.get());
    public void quitApplication() {
    public static void main(String[] args) {

How to package a swt-javafx application in maven

My maven is like the following, while I can’t build a runnable jar by “mvn clean install”. The error throw when I run the jar is that I cannot find the classes in jfxswt.jar or jfxrt.jar. It seems that the lib of javafx is still can’t find in runtime.
Do someome have
same issue before?

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">


Write method countVowels to take a string and return the amount of vowels

 public static void main(String[] args)
        Scanner in = new Scanner(System.in);
        System.out.print("Input the string: ");
        String str = in.nextLine(); 

        System.out.print("Number of  Vowels in the string: " + countVowels(str)+"n");

   public String countVowels(String count) {


sorry but im very new to java and coding and trying to find a way to create a vowel counter but I seem to struggle with creating one ive tried looking up many answers but cant find one.

TwinPrimes on JAVA

Twin primes are a pair of prime numbers that differ by 2. For example, 3 and 5 are twin primes, 5 and
7 are twin primes, and 11 and 13 are twin primes. Write a Java program TwinPrimes.java that prompts
the user to input the search range of twin primes, display all the twin primes (2 pairs per line) within
the range, and print the number of twin primes found. The search range is assumed to be positive and
your program should repeatedly perform the same task until a sentinel value of -1 is entered.

The expected output of your program should be as follows:

Round 1:
Enter the search range: 100

(3,5) (5,7)

(11,13) (17,19)

(29,31) (41,43)

(59,61) (71,73)

Number of twin primes less than or equal to 100 is 8

Round 2:
Enter the search range: 150

(3,5) (5,7)

(11,13) (17,19)

(29,31) (41,43)

(59,61) (71,73)


Number of twin primes less than or equal to 200 is 15

Round 4:

Enter the search range: -1


I know that I am not complected the code, but I am struggling on how to print the Prime numbers in ( , ) ( , )way and how to calculate the number of twin primes show it at the end.

The below coding is what I had to do:

import java.util.Scanner;

import java.util.Random;

public class TwinPrimes {

    public static void main(String[] args) {

        int i = 0;

        int A, B = 0, D = 0;

        int num = 0;

        System.out.println("Round" + " " + ++i + ":");
        Scanner scn = new Scanner(System.in);
        System.out.print("Enter the search range:");
        A = scn.nextInt();
            if (A < 0)

        for (i = 3; i <= A; i++) {

            int counter = 0;
            for (num = B; num >= 1; num--) {

                    if (B % num == 0) {
                        counter = counter + 1;
                if (counter == 2) {

            System.out.println("(" + i + "," + i + ")" + " " + "(" + i + "," + i + ")");

            // sum Number of twin primes to
            System.out.println("Number of twin primes less than or equal to " + A + " " + "is" + " ");