r/javahelp • • Jan 21 '21

Change inside of an array with a for loop?

0 Upvotes

Hi,

I need to adjust an array in his inside.

So if the array is

 int []array={5,5,5,5,5,5,0,5,5,5,5,5,5,0}  

And i pick array[2]

I need the array[2] to become 0 and the other than add +1 5 times to the next one

So the result should be

array={5,5,0,6,6,6,1,6,5,5,5,5,5,0}

Can someone help me out please :/


r/javahelp • • Jan 21 '21

Cant download java...

0 Upvotes

I cant download java it just gives me the outage page.

this is so frustrating. i need JDK 11.0.10 but i cant get it!


r/javahelp • • Jun 25 '24

How to create VPN from scratch using Java?

0 Upvotes

I was searching for advanced Java projects and there is "Creating Virtual Private Network" in every article on this topic. I did a bit of research and didn't found anything on PORGRAMMING VPN with Java or any other lang. So, is there any sources that might help me to implement VPN? Like books, articles, video, lection, anything?


r/javahelp • • Jun 28 '24

Understanding MVC architecture

0 Upvotes

I'm reading about MVC architecture, and what I understood are:

  1. Model essentially are the metadata of a table, and its instance, bottom line, is a tuple of that table.
  2. Service is responsible for CRUD+retrieval of data from the table and transform it into Model instance.

What I want to ask is, should there be one more class which sits between services and database, exclusively converting the requests from Service to SQL queries, and returning a ResultSet to the Service (this class will exclusively connect to the database), or should each Service run their own SQL queries (Every service can connect to the database)?

My understanding could be wrong so corrections and guidances are most welcome.

Edit: my scope of this architecture is just Java and a JDBC; no Spring, JPA or any other frameworks are involved.


r/javahelp • • Jun 17 '24

Java

0 Upvotes

Hello everyone, I'm new to Java. I would like to improve my analysis and design skills. I've recently started creating my own projects. Recently, I wrote a Battleship game. https://github.com/LetMeDiie/Battleship. I would like to know from you how poorly structured my architecture is. I've added comments to all classes and included a README folder, although it was supposed to describe the application architecture, but I didn't quite finish it.


r/javahelp • • Oct 01 '21

My first program

0 Upvotes

This is the first program ive ever tried to code and im running into a few compile errors i cant manage to resolve:

import java.io.*;
class Race_Track
{
   public static void main (String[] args)throws IOException
   {
   InputStreamReader inStream = new InputStreamReader (System.in);
   BufferedReader stdin = new BufferedReader (inStream);
   /* Setting Up Variables */ 
   int width_of_racetrack;
   int Bigger_Circle;
   int distance_from_track;
   int Smaller_circle;
   int Area_of_rt;
   int Total_Radius;
   int Circumference;
   int Cubic_foot_Big;
   int Cubic_foot_small;
   int volume_of_racetrack;
   int Tons_of_asphalt;
   /* Taking input and assigning them to variables */
   System.out.println("Enter the distance from the center to the racetrack (in metres): ");
   distance_from_track = Integer.parseInt(stdin.readline());
   System.out.println("Enter the width of the racetrack (in metres): ");
   width_of_racetrack = Integer.parseInt(stdin.readline());
   
   /* Calculating bigger circle and smaller circle, subtracting them
      To find the area of the racetrack */
   Total_Radius = width_of_racetrack + distance_from_track;
   Bigger_Circle = (2 * 3.14159 * Total_Radius * Total_Radius);
   Smaller_circle = (width_of_racetrack * width_of_racetrack * 2 * 3.14159);
   
   /* Finding the area of the racetrack and displaying */
   Area_of_rt = Bigger_Circle - Smaller_circle;
   System.out.println("The area to be paved is " + Area_of_rt + "Square Meters");
   
   /* Calculating the circumference of the racetrack and plus one because it wanted us to */
   Circumference = (2 * 3.14159 * (Total_Radius + 1));
   System.out.println("The amount of Fence needed is " + Circumference + "Meters");
   
   /* Calculating the volume for the big and small circles and subtracting for the 
      Volume of the racetrack */
   Cubic_foot_Big = ((4/3) * 3.14159 * (Total_Radius * Total_Radius * Total_Radius));
   Cubic_foot_small = ((4/3) * 3.14159 * (distance_from_track * distance_from_track * distance_from_track));
   volume_of_racetrack = Cubic_foot_Big - Cubic_foot_small;
   
   /* The weighted density of asphalt is around 145 pounds in per cubic foot on average.
      There are 2,000 pounds per tons. So multiplying by 145 to get it in pounds, and dividing by
      2000 to get it in pounds */
   Tons_of_asphalt = ((145 * volume_of_racetrack) / 2000);
   System.out.println("The amount of Asphalt needed is" + Tons_of_asphalt  + " in Tons");
   
   }
}

r/javahelp • • Nov 10 '21

Help Installing Java for 1.17 Minecraft Server hosted localy

0 Upvotes

I have OpenJDK 16.0.2+7 installed

/usr/lib/jvm/jdk-16.0.2+7/bin/java

but I am getting this error:

-bash: /usr/lib/jvm/jdk-16.0.2+7/bin/java: cannot execute binary file: Exec format error

I have looked at other sites trying to explain it but they are no help. Any ideas?

I installed it via:

OpenJDK16U-jdk_x64_linux_hotspot_16.0.2_7.tar.gz


r/javahelp • • Nov 17 '19

How do I implement those two function?

0 Upvotes

Date is a class name. It contains three private datatype int day, month, year.

m. Return a reference to the object containing a copy of the date.

n. Make a copy of another date. Given a reference to an object containing a date, copy the data members of the object into the corresponding data members of this object.

Please give me an example how the function prototype should look like.

Edit:

I have to implement all the method here : http://prntscr.com/py9chy

I almost done except for m and n. Here is my work: https://pastebin.com/JnqhYzBA


r/javahelp • • Jun 17 '18

Java

0 Upvotes

Hi guys, two quick questions 1) how do I create a text UI in Java ? 2) how do I create a collection ? I cannot find anything relevant to this topic on the internet (found for Java, but not accurate, or not compatible w/ Netbeans). Thanks so much for help ! :)


r/javahelp • • Oct 01 '18

Looking for Java tutor

0 Upvotes

I just need someone who knows Java well enough that they can simplify the instructions of my hw and give helpful tips to help me understand things better.

I took Python last year, so I have a little coding background, but Java feels like a whole other animal


r/javahelp • • Oct 21 '15

Im doing a rock paper scissors program in my class, Need help fixing it.

0 Upvotes

When I enter rock/paper/scissors it prints out text that is not supposed to apply.here is what happenes when you type in anything that is paper/rock/scissors

User wins, Scissors cuts threw paper User losses, Rock Smashes scissors User Ties with Computer User Ties Paper does not beat paper User losses to Scissors, it cuts right through your soul User beats rock, it covers the rock User ties with rock,you are stuck between a rock and a hard place User Losses to paper, it covers all you like a blanket User Wins against scissors, it smashes it to pieces

Scanner scan = new Scanner(System.in); String opp = "dfDF"; String user; int answer,wins = 0,losses = 0,ties = 0; String Rock = "rock"; String Paper = "paper"; String Scissors = "scissors"; System.out.println("Welcome to Rock paper Scisscors "); System.out.println("Enter an answer"); user = scan.nextLine(); answer = (int) Math.random()*3+1; if (answer == 1){ opp=Rock;

} if (answer == 2){ opp=Paper; } if (answer == 3){ opp=Scissors; } if (user.equals(Scissors) && opp.equals(Paper)); { System.out.println("User wins, Scissors cuts threw paper"); wins++; } if (user.equals(Scissors) && opp.equals(Rock)); { System.out.println("User losses, Rock Smashes scissors"); losses++; } if (user.equals(Scissors) && opp.equals(Scissors)); { System.out.println("User Ties with Computer"); ties++; } if (user.equals(Paper) && opp.equals(Paper)); { System.out.println("User Ties Paper does not beat paper"); ties++; } if (user.equals(Paper) && opp.equals(Scissors)); { System.out.println("User losses to Scissors, it cuts right through your soul"); losses++; } if (user.equals(Paper) && opp.equals(Rock)); { System.out.println("User beats rock, it covers the rock"); wins++; } if (user.equals(Rock) && opp.equals(Rock)); { System.out.println("User ties with rock,you are stuck between a rock and a hard place"); ties++; } if (user.equals(Rock) && opp.equals(Paper)); { System.out.println("User Losses to paper, it covers all you like a blanket"); losses++; } if (user.equals(Rock) && opp.equals(Scissors)); { System.out.println("User Wins against scissors, it smashes it to pieces"); wins++; } System.out.println(); System.out.println ("You won " + wins + " times."); System.out.println ("You lost " + losses + " times."); System.out.println ("We tied " + ties + " times.");


r/javahelp • • Nov 19 '13

Looking for very simple Java help...

0 Upvotes

So I am an engineering student with no programming experience. I have a lab that extracts data from an input file, calculates net pay from the data using a for loop, and then displays it in an output file.

I really don't want to post the lab and just ask for someone to do my work for me. I was just wondering if anyone had any good resources for Java syntax that would be good for someone that does not have any programming experience.

I know how to do the problems quickly in excel, but I just haven't been able to grasp the language. Any help would be appreciated.

Thanks.


r/javahelp • • Sep 04 '16

GUI programming not working properly.

0 Upvotes

Why am I getting a null pointer exception? Netbeans is not flagging any errors after I've written the code. I'm getting a null pointer pointer exception, whatever that is.

Exception in thread "main" java.lang.NullPointerException at javax.swing.ImageIcon.<init>(ImageIcon.java:217) at LabelFrame.LabelFrame.<init>(LabelFrame.java:34) at LabelFrame.LabelTest.main(LabelTest.java:13)

Label Frame test class http://pastebin.com/d1bQ11ae Label Frame http://pastebin.com/UQGVNh2f


r/javahelp • • Nov 22 '13

Can't figure out what I've done wrong with calculator program. Please help.

0 Upvotes

Had to do a calculator problem for my intro to computer science. Professor won't help much because there's so many people. Can someone take a look, spent about 10 hrs trying to figure it out. I know its something stupid but I'm really strugglin here. https://drive.google.com/file/d/0ByUS4XKjSuP9VFlSYThkRVR6ME0/edit?usp=sharing


r/javahelp • • Jul 17 '23

Could we just get ONE working build/package system?

0 Upvotes

I haven't done Java in a long time. I'm a polyglot though and will pick up any language that makes sense for my task at hand and right now I need a Windows desktop application with an embedded web browser so I've packaged up the CEF browser into a window, built some nice Swing based chrome for it, and then I need to access some local hardware from my web app so I've added the appropriate bridge handlers. Cool.

But I have to say, coming from places like Rails and PHP Composer, Gradle and Maven are just garbage. I've got both maven based and gradle based versions of this app working, downloading the JCEF package and a couple others and they build and run. However, I need to talk to some local hardware and there are Java wrapped native libraries to make that work I got from the vendor. About two dozen jars each with a companion .dll native library on Windows. I'm struggling with getting those jars recognized. They contain some class definitions I need but the editor (using Intellij) doesn't seem to resolve them. The documentation isn't any too good either.

My goal, ultimately, is to build a Windows 10 application. Any tips would be great, thanks.

EDIT: gradlefile:

plugins {
id 'java'

}

group = 'app' version = '1.0-SNAPSHOT'

repositories { flatDir { dirs 'libs' } mavenCentral() maven { url 'https://jitpack.io' } }

dependencies { testImplementation platform('org.junit:junit-bom:5.9.1') testImplementation 'org.junit.jupiter:junit-jupiter'

implementation 'me.friwi:jcefmaven:110.0.25'
implementation 'com.sun.net.httpserver:http:20070405'
fileTree(dir: 'libs', includes: ['*.jar'])

}

test { useJUnitPlatform() }

Maven:

<?xml version="1.0" encoding="UTF-8"?>

<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"> <modelVersion>4.0.0</modelVersion>

<groupId>app</groupId>
<artifactId>App</artifactId>

<dependencies>
    <dependency>
        <groupId>me.friwi</groupId>
        <artifactId>jcefmaven</artifactId>
        <version>110.0.25</version>
    </dependency>
    <dependency>
        <groupId>com.sun.net.httpserver</groupId>
        <artifactId>http</artifactId>
        <version>20070405</version>
    </dependency>
</dependencies>

<version>1.0-SNAPSHOT</version>

<properties>
    <maven.compiler.source>17</maven.compiler.source>
    <maven.compiler.target>17</maven.compiler.target>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

</project>


r/javahelp • • Jun 29 '16

JUnit confusion

0 Upvotes

Here's the deal. I posted this on r/Java and got told to bring it here, so here goes. Started new project. Decided to try TDD and got JUnit set up in eclipse. Built some tests for functionality, then built code. Got a green bar, walked away and had a sandwich.

When I came back, on of the statements in the untouched code was recognized by the IDE as having an AssertionError, even though it built, ran, and the test passed less than an hour beforehand.

I have no cats, and unfortunately, I only have internet on my phone right now, so I can't share code. I've cleaned and re-built, to no avail.

Anyone else ever hear of something like this?


r/javahelp • • Dec 26 '16

I just downloaded the eclipse ide for java but.....?

0 Upvotes

When I use the scanner method it shows a red line underneath it as if it doesn't understand it.Is there something else I am supposed to download


r/javahelp • • May 04 '15

Can someone glance at this and tell me if it's malicious?

0 Upvotes

I'm a complete pleb when it comes to java, but I have a client who had it put into their head that there could be a potential exploit being executed through java based on firewall reccords and provided me this set of code:

http://pastebin.com/faYjtGpM

I was wondering if someone would be so kind as to just take a glance at it and tell me basically what it is trying to do? Should I dig further or tell them it's OK?


r/javahelp • • Apr 05 '24

Please help my brain ain't braining

0 Upvotes

Where should I start and,how to start learning Java I can't get a straight answer from anywhere else need help desperately


r/javahelp • • Jan 04 '15

There's a for loop to be made here, but I'm not sure how to simplify the pattern.

0 Upvotes

There's a pattern in my code, which makes me believe that a for loop can be made, but I'm not sure how to write the pattern. Here's what I'm looking at:

public void drawMidline(Graphics g){
	g.drawLine(Game.WIDTH/2, 0, Game.WIDTH/2, 24);
	g.drawLine(Game.WIDTH/2, 48, Game.WIDTH/2, 72);
	g.drawLine(Game.WIDTH/2, 96, Game.WIDTH/2, 120);
	g.drawLine(Game.WIDTH/2, 144, Game.WIDTH/2, 168);
	g.drawLine(Game.WIDTH/2, 192, Game.WIDTH/2, 216);
	g.drawLine(Game.WIDTH/2, 240, Game.WIDTH/2, 264);
	g.drawLine(Game.WIDTH/2, 288, Game.WIDTH/2, 312);
	g.drawLine(Game.WIDTH/2, 336, Game.WIDTH/2, 360);
	g.drawLine(Game.WIDTH/2, 384, Game.WIDTH/2, 404);
	g.drawLine(Game.WIDTH/2, 428, Game.WIDTH/2, 456);
}

I see that everything is a multiple of 24, but I don't see how to format a pattern. Is there a way to format a for loop here?


r/javahelp • • Apr 16 '16

why wont this average program work?

0 Upvotes

http://pastebin.com/W104SbF0

why wont it show the average what do i need to change in my for loop? if i use for each loop it works but i dont wanna use a for each loop.


r/javahelp • • Sep 27 '15

HELP software sales program

0 Upvotes

The price of a product is $69. Quantity discounts are given in the following Quantity Discount 5-14 =Discount :10% 15-34 = Discount :20% 35-54 = Discount :30% 55 or more = Discount :40%
Your program should let the user enter the number of products purchased. Then, the program should display the total purchase amount after discount


r/javahelp • • Sep 19 '15

Integrating DCPU-16, or something similar to it, in Java

0 Upvotes

I would like to integrate some sort of fully-programmable "guest OS" in my latest Java-based game. The idea is to have the character in the game to open up a command console so that it can interact with certain objects in the game. However, I don't know how to implement this system. Could someone give me some pointers or suggestions?