/r/javahelp
General subreddit for helping with Java code.
General subreddit for helping with Java code.
Message the mods if you have suggestions.
Java Discord server (unofficial)
Learning Java
Please head over to /r/learnjava and read the sidebar there.
The best free Java tutorials are:
Use the MOOC as main course and Java for Complete Beginners as secondary resource.
Don't forget the Official Oracle Java Tutorials and the Official Java Documentation as they are extremely valuable resources.
Where should I download Java?
With the introduction of the new release cadence, many have asked where they should download Java, and if it is still free. To be clear, YES — Java is still free.
If you would like to download Java for free, you can get OpenJDK builds from the following vendors, among others:
Some vendors will be supporting releases for longer than six months. If you have any questions, please do not hesitate to ask them!
Posting rules
DO NOT DELETE your posts once they are solved!
No illegal/pirated content!
No "Do my homework" posts!
Describe the problem and what you want to achieve.
Do not ask for or reply with solutions or keys to solutions.
Use the search function.
No offers/requests to/for help via PM, Discord, Skype, etc.
Post titles must be descriptive.
No promises of rewards of any kind!
Don't be a Jerk!
No JavaScript, Android, Minecraft or Processing!
No links to your stackoverflow questions.
Format your code.
No screenshots of code!
No AI generated content!
/r/javahelp
I'd like to achieve the following: Parse a Strign that contains the day of the week in three letters to DayOfWeek. Example like this:
DayofWeek weekday = DayOfWeek.valueOf("Mon".toUpperCase());
Problem: I get the day of the week as "Mon", "Tue", "Wed", "Thur" or "Fri". And when I try parsing them with "valueOf" I get the followign error:
JAXBException
java.lang.IllegalArgumentException: No enum constant java.time.DayOfWeek.MON
My source, which feeds me this data, gives me "Mon", "Tue", etc as a String. And I cannot change it. I use JAXB unmarshalling.
And I need to transfer the this 3-letter String to DayofWeek
Hi, I am working with a forked Java (Clojure) application that I did not write myself. I am deploying my fork to Heroku. Inside the repository, there is a CUSTOM build script (in ./bin) called build.sh that checks if the Clojure command line tools are installed and then builds the .jar file. The script works locally with no problems. There is no Maven or Gradle used in this project. I successfully deployed the application to Heroku by building the .jar file locally using the script, and pushing that .jar file to Heroku. However, I would like to push my entire REPO to Heroku and have Heroku take care of building the .jar file and deploying it for me.
To do this, I need to (in this order):
I have not been successful with this. This is what I've tried:
release\
phase, so it runs as part of the build process before deploying.i dont know what to do next ,do projects learn more about something ,how i should develop myself.
Let's provide some context:
1- I have a local MSSQL server which goes by the name (local)/MSSQLLocalDB or the name of my device which is:"DESKTOP-T7CN5JN\\LOCALDB#6173A439" .
2-I am using a java project with maven to manage dependencies.
3-java jdk21
4-I have established a connection in IntelliJ with the database and it presented url3 in the provided snippet.
5-The database uses windows authentication
Problem: As shown in the following code snippet I tried 3 different connection Strings and all lead to runtime errors.
Goal: figure out what is the correct connection format to establish a connection and why none of these is working
I feel like I tried looking everywhere for a solution
String connectionUrl1 = "jdbc:sqlserver://localhost:1433;databaseName =laptop_registry;integratedSecurity = true;encrypt=false";
String connectionUrl2 = "jdbc:sqlserver://DESKTOP-T7CN5JN\\LOCALDB#6173A439;databaseName = laptop_registry;integratedSecurity=true;encrypt=false";
String connectionUrl3 = "jdbc:jtds:sqlserver://./laptop_registry";
line 15: try (Connection conn = DriverManager.getConnection(<connectionUrlGoesHere>)
){...}catch.....
URL1 results in the following error
com.microsoft.sqlserver.jdbc.SQLServerException: Cannot open database "laptop_registry" requested by the login. The login failed. ClientConnectionId:f933922b-5a12-44f0-b100-3a6390845190
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:270)
at com.microsoft.sqlserver.jdbc.TDSTokenHandler.onEOF(tdsparser.java:329)
at com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:137)
at com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:42)
at com.microsoft.sqlserver.jdbc.SQLServerConnection$1LogonProcessor.complete(SQLServerConnection.java:6577)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.sendLogon(SQLServerConnection.java:6889)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:5434)
at com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(SQLServerConnection.java:5366)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:7745)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:4391)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:3828)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:3385)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectInternal(SQLServerConnection.java:3194)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:1971)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1263)
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:683)
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:253)
at org.mainn.dbconnector.MSSQLDatabaseConnector.main(MSSQLDatabaseConnector.java:15)
URL2 results in the following
com.microsoft.sqlserver.jdbc.SQLServerException: The connection to the host DESKTOP-T7CN5JN, named instance localdb#6173a439 failed. Error: "java.net.SocketTimeoutException: Receive timed out". Verify the server and instance names and check that no firewall is blocking UDP traffic to port 1434. For SQL Server 2005 or later, verify that the SQL Server Browser Service is running on the host.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:242)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.getInstancePort(SQLServerConnection.java:7918)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.primaryPermissionCheck(SQLServerConnection.java:3680)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:3364)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectInternal(SQLServerConnection.java:3194)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:1971)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1263)
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:683)
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:253)
at org.mainn.dbconnector.MSSQLDatabaseConnector.main(MSSQLDatabaseConnector.java:15)
URL 3 results in the following error
java.sql.SQLException: No suitable driver found for jdbc:jtds:sqlserver://./laptop_registry
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:708)
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:253)
at org.mainn.dbconnector.MSSQLDatabaseConnector.main(MSSQLDatabaseConnector.java:15)
I fix this by renaming my image files from something like popcorn.png
to popcorn_image.png
, and that fixed the problem
Right now, I am following a yt tutorial on how to make a java rpg, and i'm on episode 13, right now im stuck on this error,
Exception in thread "main" java.lang.IllegalArgumentException: input == null!
at java.desktop/javax.imageio.ImageIO.read(ImageIO.java:1356)
at objects.OBJ_ARROW.<init>(OBJ_ARROW.java:18)
at main.UI.<init>(UI.java:30)
at main.GamePanel.<init>(GamePanel.java:45)
at main.Main.main(Main.java:24)
and this is my code:
package objects;
import java.io.IOException;
import javax.imageio.ImageIO;
import main.GamePanel;
public class OBJ_ARROW extends SuperObject {
GamePanel gp;
public OBJ_ARROW(GamePanel gp) {
this.gp = gp;
name = "Arrow";
try {
image = ImageIO.read(getClass().getResourceAsStream("/res/objects/arrow.png"));
uTool.scaleImage(image, gp.tileSize, gp.tileSize);
} catch(IOException e) {
e.printStackTrace();
}
collision = true;
}
}
UtilityTool.java:
package main;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
public class UtilityTool {
public BufferedImage scaleImage(BufferedImage original, int width, int height) {
BufferedImage scaledImage = new BufferedImage(width, height, original.getType());
Graphics2D g2 = scaledImage.createGraphics();
g2.drawImage(original, 0, 0, width, height, null);
g2.dispose();
return scaledImage;
}
}
i've searched online for answers, one of them is that you use an invalid link to the file, but it seems like I have the correct one. Does anyone know a fix to this?
Hi I am new to learning Java. I find it easy to write java code than other languages. What are some good resources to learn Java collections?
Hi, Im new to sprinboot. I searched about this online and did not get a satisfactionalry answer.
What is the industry "standard" method of making API calls to other backends from the Springboot backend? Are there any libs that are more in use than others? are there native ways? TIA!
Done with Java basics
Data Types
loops
Array, HashMaps
OOP
Exception Handling
File I/O
I have built a tictactoe, library management system, calculator, temperature converter, contact manager list.
Am I in a good place to dive into spring boot?
Please can you recommend more Java console application projects that I should build?
Please can you recommend resources for learning SpringBoot?
I am working on a hobby project of mine and I am scraping some websites however one of them uses JavaScript to load a lot of the page content so for example instead of a link being embedded in the href attribute of an "a" tag it's a "#" but when I click on the button element I am taken to another page
My question: now I want to obtain the actual link that is followed whenever the button is clicked on however when using Jsoup I can't simply do doc.selectFirst("a"). attr("href") since I get # so how can I get around this?
I am using eclipse and I'm thank I'm using j.D k twenty two The warning is "build path Specifies execution environment JavaSE look" I've heard. That it means my j d k is corrupted or something in it totally seems like it because some stuff isn't working like the set bounds But I want to make sure of it
A modern language needs a modern UI Toolkit.
Java uses JavaFX that is very powerful but JavaFX alone is not enough to create a real user interface for real apps.
JavaFX for example isn't able to interact with the OS APIs like the ones used to create a tray icon or to send an OS notification.
To do so, you need to use AWT but AWT is completely dead, it still uses 20+ years old APIs and most of its features are broken.
TrayIcons on Linux are completely broken due to the ancient APIs used by AWT,
same thing for the Windows notifications.
Is Java dead as a programming language for native apps?
What's your opinion on this?
https://bugs.java.com/bugdatabase/view_bug?bug_id=JDK-8341144
https://bugs.java.com/bugdatabase/view_bug?bug_id=JDK-8310352
https://bugs.java.com/bugdatabase/view_bug?bug_id=JDK-8323821
https://bugs.java.com/bugdatabase/view_bug?bug_id=JDK-8341173
https://bugs.java.com/bugdatabase/view_bug?bug_id=JDK-8323977
https://bugs.java.com/bugdatabase/view_bug?bug_id=JDK-8342009
I'm building a microservice app. Can somebody check it out and give me feedback? I want to know what else can implement, errors that I made, etc.
In the link I share the database structure and the documentation in YAML of each service:
The task is to fill an array with 10 entries and if the value of an entry already exists, then delete it. I'm failing when it comes to comparing in the array itself.
my first idea was: if array[i]==array[i-1]{
........;
}
but logically that doesn't work and apart from making a long if query that compares each position individually with the others, I haven't come up with anything.
Can you help me?
(it's an array, not an ArrayList, then I wouldn't have the problem XD)
im trying to add the Line and Ball at the same time but only one works at a time specificly witchever frame.add is last works
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.Graphics;
import javax.swing.Timer;
public class Ball {
public static void main(String[] args) {
JFrame frame = new JFrame("Ball Window");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
int CenterX = (int) (screenSize.getWidth()/2);
int CenterY = (int) (screenSize.getHeight()/2);
BallPanel bp = new BallPanel();
LinePanel lp = new LinePanel();
frame.add(bp);
frame.add(lp);
frame.setSize(400,400);
frame.setLocation(CenterX, CenterY);
frame.setVisible(true);
}
}
//Line
class LinePanel extends JPanel implements ActionListener{
public void paint(Graphics e){
e.drawLine(300, 0, 300, 400);
}
public void actionPerformed(ActionEvent e) {
repaint();
}
}
//Ball
class BallPanel extends JPanel implements ActionListener{
private int delay = 10;
protected Timer timer;
private int x = 0;
private int y = 0;
private int radius = 15;
private int dx = 2;
private int dy = 2;
public BallPanel()
{
timer = new Timer(delay, this);
timer.start();
}
public void actionPerformed(ActionEvent e) {
repaint();
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(Color.red);
if (x < radius)dx = Math.abs(dx);
if (x > getWidth() - radius)dx = -Math.abs(dx);
if (y < radius)dy = Math.abs(dy);
if (y > getHeight() - radius)dy = -Math.abs(dy);
x += dx;
y += dy;
g.fillOval(x - radius, y - radius, radius*2, radius*2);
}
}
File 1:
import java.util.Random;
public class School {
private Student[] students;
private Course[] courses;
private static int curStudents = 0;
private static int curCourses = 0;
public School(Student[] students, Course[] courses) {
this.students = students;
= courses;
}
// your code goes here
public void addStudent(Student s){
if (curStudents< students.length){
students[curStudents] = s;
curStudents++;
} else {
System.out.println("Student array is full.");
}
}
public Course getCourseByName(String name) {
for (Course c : courses) {
if (c != null && c.getCourseName().equals(name)) {
return c;
}
}
return null;
}
public void printStudentsAndGrades(Course c) {
if (c != null) {
int[] studentNums = c.getStudents();
for (int num : studentNums) {
Student student = findStudentByNumber(num);
if (student != null) {
System.out.println(student.toString());
}
}
}
}
public void addCourse(Course c) {
if (curCourses < courses.length) {
courses[curCourses] = c;
curCourses++;
} else {
System.out.println("Course array is full.");
}
}
private Student findStudentByNumber(int studentNumber) {
for (Student s : students) {
if (s != null && s.getStudentNumber() == studentNumber) {
return s;
}
}
return null;
}
private double calculateAverage(Course c) {
int[] studentNums = c.getStudents();
int totalGrade = 0;
int count = 0;
for (int num : studentNums) {
Student student = findStudentByNumber(num);
if (student != null) {
totalGrade += student.getGrade();
count++;
}
}
if (count == 0) {
return 0;
}
return (double) totalGrade / count;
}
public void printAverages() {
for (Course c : courses) {
if (c != null) {
double avg = calculateAverage(c);
System.out.println("Average for course " + c.getCourseName() + ": " + avg);
}
}
}
public static void main(String[] args) throws Exception {
String[] names = { "Bobby", "Sally", "Eve", "Abdul", "Luis", "Sadiq", "Diego", "Andrea", "Nikolai",
"Gabriela" };
int[] studentNums = new int[10];
Random rn = new Random();
School school = new School(new Student[10], new Course[2]);
for (int i = 0; i < 10; i++) {
int studentNum = rn.nextInt(100000);
Student s = new Student(names[i], studentNum, i * 10);
studentNums[i] = studentNum;
school.addStudent(s);
}
Course cst = new Course("CST8116", true, "Spring");
Course basket = new Course("Basket Weaving", false, "Fall");
cst.setStudents(studentNums);
basket.setStudents(studentNums);
school.addCourse(cst);
school.addCourse(basket);
school.printStudentsAndGrades(school.getCourseByName("CST8116"));
school.printStudentsAndGrades(school.getCourseByName("Basket Weaving"));
school.printAverages();
}
}
File 2 (separate different file)
public class Student {
private String name;
private int studentNumber;
private int grade;
public Student(String name, int studentNumber, int grade){
this.name=name;
this.studentNumber=studentNumber;
this.grade=grade;
}
public String getName(){
return name;
}
public int getStudentNumber(){
return studentNumber;
}
public int getGrade(){
return grade;
}
public String toString(){
return "Name: " + name + ", Student Number: " + studentNumber + ", Grade: " + grade;
}
}
I keep getting this error:
Student cannot be resolved to a type
I have checked everything there are no typos
The third file is reached easily
EDIT: Guys not sure how this works but the solution is:
I save the file as file1.Java instead of file1.java the capital J was causing the problem
Thanks for all the replies
I saw something like that in class but it wasn’t clicking
Total newbie here. I'm having two problems with jdk21 that, I think, are related. I'm working on openstreetmap spatial data through R and osmosis.
In R when I run a r5r command that uses java it says
Errore in .jcall("RJavaTools", "Z", "hasField", .jcast(x, "java/lang/Object"), :
java.lang.NullPointerException: Cannot invoke "Object.getClass()" because "<parameter1>" is null
Also when I try to use osmosis (that is based on java) through windows console it doesn't work at all. This is just an example:
C:\Users\pepit>osmosis --read-pbf "C:\\Users\\pepit\\Desktop\\Università\\R studio\\dati_raw\\osm_extract_full.pbf"
nov 06, 2024 3:11:20 PM org.openstreetmap.osmosis.core.Osmosis run
INFO: Osmosis Version 0.49.2
SLF4J(W): No SLF4J providers were found.
SLF4J(W): Defaulting to no-operation (NOP) logger implementation
SLF4J(W): See for further details.
nov 06, 2024 3:11:20 PM org.openstreetmap.osmosis.core.Osmosis run
INFO: Preparing pipeline.
nov 06, 2024 3:11:20 PM org.openstreetmap.osmosis.core.Osmosis main
SEVERE: Execution aborted.
org.openstreetmap.osmosis.core.OsmosisRuntimeException: The following named pipes () and 1 default pipes have not been terminated with appropriate output sinks.
at org.openstreetmap.osmosis.core.pipeline.common.Pipeline.connectTasks(Pipeline.java:96)
at org.openstreetmap.osmosis.core.pipeline.common.Pipeline.prepare(Pipeline.java:116)
at org.openstreetmap.osmosis.core.Osmosis.run(Osmosis.java:86)
at org.openstreetmap.osmosis.core.Osmosis.main(Osmosis.java:37)https://www.slf4j.org/codes.html#noProviders
I think my problem may be related to this https://stackoverflow.com/questions/73041409/cannot-invoke-object-getclass-because-object-is-null-java16
I really hope someone can help me solve this problem, I didn't manage to figure it out at all...
EDIT: this is the command I use on R. It computes travel times from origins to destinations through the network r5r_core (based on openstreetmap files)
travel_times_by_od_pair <- r5r::travel_time_matrix(
r5r_core = r5r_core,
origins = origins,
destinations = destinations[type == o_type, ],
mode = "WALK",
max_trip_duration = 30L
)
Best ai for java which gives accurate answers and the correct full code if a snippet is given
JavaFX: ScrollPane makes ListView not take 100% of BorderPane's space.
ListView without ScrollPane
// displayListView
ListView<String> displayListView = new ListView<>();
ObservableList<String> observableDisplayListView = FXCollections.observableArrayList();
displayListView.setItems(observableDisplayListView);
ScrollPane displayListViewScrollPane = new ScrollPane();
displayListViewScrollPane.setContent(displayListView);
ListView with ScrollPane
// displayListView
ListView<String> displayListView = new ListView<>();
ObservableList<String> observableDisplayListView = FXCollections.observableArrayList();
displayListView.setItems(observableDisplayListView);
So, I got an assignment that resolves around timetables. I have
Now, I know what XML and XSD are, but I'm not quite sure what to make of the XSD file in particular. The instruction is:
In the appendix you will find both the task and an XML file with the input data. The XSD schema is also attached, but does not necessarily have to be used.
My internet research has shown me that it's possible to validate an XML against a XSD to confirm whether it's valid. But is this the end of the oppertunities?
Could I somehow use the XSD as a template to extract the data (and if so, do you maybe have instructions on how?!?)
a) in a collection? E.g. map
b) as objects if I recreate the data model?
And yes, although he clarifies that XSD does not have to be used, I'm seizing the oppertunity to learn about it. So I'm handing this question over to the community What could I / should I use the XSD for?
Thank you in advance!!
I have problem in understanding one thing but before that i will paste here code:
Class Game:
package Config;
import KeyHandler.KeyHandler;
import javax.swing.*;
public class Okno extends JFrame {
KeyHandler keyHandler = new KeyHandler();
public Okno() {
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
Game gamepanel = new Game(this.keyHandler);
this.add(gamepanel);
this.addKeyListener(keyHandler);
this.setFocusable(true);
this.pack();
this.setVisible(true);
gamepanel.run();
}
public Okno(int width, int height) {
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
Game gamepanel = new Game(width, height, this.keyHandler);
this.add(gamepanel);
this.addKeyListener(keyHandler);
this.setFocusable(true);
this.pack();
this.setVisible(true);
gamepanel.run();
}
}
package Config;
import KeyHandler.KeyHandler;
import javax.swing.*;
public class Okno extends JFrame {
KeyHandler keyHandler = new KeyHandler();
public Okno() {
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
Game gamepanel = new Game(this.keyHandler);
this.add(gamepanel);
this.addKeyListener(keyHandler);
this.setFocusable(true);
this.pack();
this.setVisible(true);
gamepanel.run();
}
public Okno(int width, int height) {
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
Game gamepanel = new Game(width, height, this.keyHandler);
this.add(gamepanel);
this.addKeyListener(keyHandler);
this.setFocusable(true);
this.pack();
this.setVisible(true);
gamepanel.run();
}
}
package Config;
import Entities.Enemy;
import Entities.Entity;
import Entities.Player;
import KeyHandler.KeyHandler;
import javax.swing.*;
import java.awt.*;
public class Game extends JPanel {
int tileSize = 32;
public int width;
public double height; // Change height to double
KeyHandler kh;
Enemy wrog = new Enemy(100);
public Game(KeyHandler kh) {
width = 40;
height = 22.5; // Now this works
setBackground(Color.WHITE);
setPreferredSize(new Dimension(width * tileSize, (int) (height * tileSize))); // Cast to int here
this.kh = kh;
}
public Game(int width, int height, KeyHandler kh) {
this.width = width;
this.height = height;
setBackground(Color.WHITE);
setPreferredSize(new Dimension(width*tileSize, height*tileSize));
this.kh = kh;
}
public void run(){
initialization();
gameloop();
}
public void initialization(){
Player.getInstance().loseHealth(10);
wrog.loseHealth(15);
Player.getInstance().showHealth(); // Wywołanie metody showHealth dla gracza
wrog.showHealth(); // Wywołanie metody showHealth dla wroga
}
public void gameloop(){
while(true){
if(kh.upPressed == true){
System.out.println("do gory");
}
if(kh.downPressed == true){
System.out.println("do dolu");
}
if(kh.leftPressed == true){
System.out.println("w lewo");
}
if(kh.rightPressed == true){
System.out.println("w prawo");
}
System.out.println("");
}
}
public void paintComponent(Graphics g){
g.setColor(Color.BLACK);
g.fillRect(0, 0,32, 32);
}
}
My problem is that without the line "System.out.println("w prawo");" in method gameloop console doesnt print any logs even tho it should however if i dont delete this line it works fine and priints what it should. I can skip this step but i want to know why is this problem occuring. Also i know threads but i wanted to do this loop like in LWJGL without including thread
Hallo every one I have a question about the complexity of transforming java code from 8 version to 17 . What will be the impacts . Is there flagrant changes like code syntax or libraries import? Thanks and sorry for my poor English.
Is this still available in jdK twenty two I believe setbounds method Or setposition's method I am sorry if I break any of the rules.Sometimes I have poor understanding of what count as breaking something Like , for example , I can't tell if my game is too similar to a game and might be copyrighted
So saying that is this how you do either of these methods
Label_name.setBounds(x,y,width,hight) Lable_namr.setPostion(x,y)
Can anyone help me understand why my connection to the database in Netbeans keeps running infinitely?
I'm using netbeans 20 I believe everything is configured in jdk 21
here some images about the installation
https://imgur.com/a/KBxXmWm
Basically all examples skip or just assume that reader knows how to do it so please tell me what plugins, files, etc I need that I can just do mvn clean install on my features.xml and then those features should be available in karaf by using "feature:repo-add" and "feature:install"
More specificly what command do I have to run in command line and in what directory?
please read my previous post first.
previous post: https://www.reddit.com/r/javahelp/comments/1fjvk4y/application_goes_down_without_any_trace_java7/
App goes unresponsive one or two times a day and everything works normal once i restarted the tomcat server.
Last time i can't provide any info now i have taken a thread dump and by analyzing that i have found that all the thread are on waiting state to acquire connection. I have changed some of the configuration of c3p0 and the app ran 2 or 3 days without any problem after that it's start doing the same thing again.
I have upload the threaddump in fastthread you can check that here. https://fastthread.io/ft-thread-report.jsp?dumpId=1&ts=2024-11-05T20-59-40
I have checked the entire source code, all the connections that are created is properly closed. I have no idea why this happening.
I can provide thread dump if anybody what to take a look.
Please help me resolve this issue. Thanks.
Trying to find Java Runtime 11.0.0 for a game.
For example, I have an object "myCar" initialized using the "Outer" class. The "Outer" class contains a static inner class called "Inner" where some static attributes such as "brandName" are defined as static. Can i access those static attributes in the " Inner" class from the objects I create in the main function?
Code:
package staticinnerclass;
import java.lang.*;
class Outer{
//Some class attributes
int maxSpeed;
String color;
static int inProduction = 1;
public Outer(int maxSpeed, String color) {
this.maxSpeed = maxSpeed;
this.color = color;
}
public Outer() {
this(180, "White");
}
//static int length = 10;
//The static inner class defines a number of static attributes
//The static inner class defines metadata to describe a class
//All the static attributes give information about a class, not about objects!
static class Inner{
private static int width=100, length=50, rimSize = 16;
private static String projectName = "Car model 1";
private static String brandName = "Honda";
private static String destMarket = "Europe";
//NOTE! Attributes are public by default in a static class
static int armrestSize = 30;
//Define some static getter methods to print some class private attributes
static void displayBrandName() {
System.out.println(brandName);
}
static void displayMarketDetails() {
System.out.println("Proj. name: " + projectName + "\nDest. market: " + destMarket);
}
/*
* In this case some of the attributes are made private, so getters and setters
* are necessary.
* */
}
}
public class StaticInnerClass {
public static void main(String args[]) {
//A static class' methods can be called without creating an object of it
Outer.Inner.displayBrandName();
System.out.println(Outer.Inner.armrestSize);
Outer.Inner.displayMarketDetails();
Outer newCar = new Outer(200, "Blue");
System.out.println(newCar.armRestSize) //Is there some way to do it? ??
}
}
Sorry, I'm very new to programming and playing around with everything right now. I'm following my textbook and trying to do the exercises but all of them give me this error whenever I try to run it. I even tried to compile via the Command Prompt/Terminal, but it just won't create the class file. What's happening? The Test.java is in the correct folder. Thanks!
Why, as a variable of class A can also point to an object DescendantOfA extends A, are interfaces and classes not interchangeable? Why can it not hold an object implementing interface A? I could have an interface with default methods and a class with the exact same public methods.
The use case is a library where they replaced a public API from a class to an interface, keeping the same name (so they changed class A
to interface A
) and suddenly it was not compatible anymore.
In my stupid brain it is the same concept: some object on which I can access the public methods/fields described by A.