Java

1376 readers
26 users here now

For discussing Java, the JVM, languages that run on the JVM, and other related technologies.

founded 1 year ago
MODERATORS
1
2
3
 
 

cross-posted from: https://lemmy.ml/post/22574276

If there was one reason I liked coding in Java, it'd be AssertJ and its brilliant extensibility.

The image is an example of it from bjForth

The ability to create custom assertions makes the test code concise and read naturally.

4
 
 

Even though I don't use Azure, I found this quite interesting.

5
 
 

Not a lot of information out there about running Java on k8s

I have also been looking into benchmarks between HTTP servers.

There is this but its just "Hello world"

6
7
 
 

So I am working on a homework project for my network architure class were I have to devlop an FTP program using UDP (not TCP). I was able to get my GET and PUT functions to send a 21byte test file and it worked. However when I tried to do a 1MB file the program hanged and did not send all of the data. I need to be able to send files of 1MB, 25MB, 50MB, and 100MB. Here is my code.

GET (Client Side)

 private static void getFile(String serverFilePath, String clientFilePath) throws IOException 
	{
        clientFilePath = clientFilePath.replaceAll("^\"|\"$", ""); //Strip quotes if any.
		if(!clientFilePath.startsWith("/"))
			clientFilePath = currentDir + "/" + clientFilePath;
		
		sendMessage("GET " + serverFilePath);
		
		//Write file to client
        try (FileOutputStream fos = new FileOutputStream(clientFilePath)) 
		{
            while (true) 
			{
                byte[] buffer = new byte[BUFFER_SIZE];
                DatagramPacket packet = new DatagramPacket(buffer, buffer.length);
                socket.receive(packet);

                String data = new String(packet.getData(), 0, packet.getLength());
                if (data.equals("DONE")) break;

                fos.write(packet.getData(), 0, packet.getLength());
            }
        }
        System.out.println("[Client] File downloaded successfully.");
    }

PUT (Client Side)

private static void putFile(String clientFilePath, String serverFilePath) throws IOException 
	{
        clientFilePath = clientFilePath.replaceAll("^\"|\"$", ""); //Strip quotes if any.
		if(!clientFilePath.startsWith("/"))
			clientFilePath = currentDir + "/" + clientFilePath;
			
		sendMessage("PUT " + serverFilePath);
		
		//Upload file to server
        try (FileInputStream fis = new FileInputStream(clientFilePath)) 
		{
            byte[] buffer = new byte[BUFFER_SIZE];
            int bytesRead;
            while ((bytesRead = fis.read(buffer)) != -1) 
			{
                DatagramPacket packet = new DatagramPacket(buffer, bytesRead, serverAddress, SERVER_PORT);
                socket.send(packet);
            }
            sendMessage("DONE");
        }
        System.out.println("[Client] File uploaded successfully.");
    }

GET (Server Side)

 private static void handleGet(String filePath, InetAddress clientAddress, int clientPort) throws IOException 
	{
        filePath = filePath.replaceAll("^\"|\"$", ""); //Strip quotes if any.
		if(!filePath.startsWith("/"))
			filePath = currentDir + "/" + filePath;
		
		//Check is file exists
		File file = new File(filePath);
        if (!file.exists()) 
		{
            sendMessage("[Server] Error File not found", clientAddress, clientPort);
            return;
        }
		
		//Write file to server
        try (FileInputStream fis = new FileInputStream(file)) 
		{
            byte[] buffer = new byte[BUFFER_SIZE];
            int bytesRead;
            while ((bytesRead = fis.read(buffer)) != -1) 
			{
                DatagramPacket packet = new DatagramPacket(buffer, bytesRead, clientAddress, clientPort);
                socket.send(packet);
            }
            sendMessage("DONE", clientAddress, clientPort);
        }
    }

PUT (Server Side)

private static void handlePut(String filePath, InetAddress clientAddress, int clientPort) throws IOException 
	{
        filePath = filePath.replaceAll("^\"|\"$", ""); //Strip quotes if any.
		if(!filePath.startsWith("/"))
			filePath = currentDir + "/" + filePath;
		
		File file = new File(filePath);
        try (FileOutputStream fos = new FileOutputStream(file)) 
		{
            while (true) 
			{
                byte[] buffer = new byte[BUFFER_SIZE];
                DatagramPacket packet = new DatagramPacket(buffer, buffer.length);
                socket.receive(packet);

                String data = new String(packet.getData(), 0, packet.getLength());
                if (data.equals("DONE")) break;

                fos.write(packet.getData(), 0, packet.getLength());
            }
        }
        sendMessage("DONE", clientAddress, clientPort);
    }
8
9
10
11
12
 
 

Hey Guys,

For my current spring boot project I have been using a @Scheduled annotation and using cron syntax for running jobs, but now I don't want to schedule jobs on holiday (based on US calendar).

So is there any approach to skip the schedule on holiday.

Thanks for your help in advanced.

13
14
 
 

cross-posted from: https://programming.dev/post/19544005

When managing a database, speed and efficiency are crucial. As applications handle more data and become more complex, the performance of database queries plays a big role in keeping everything running smoothly. One of the best ways to make queries faster is by using indexes. Similar to a book’s index that helps you quickly find a topic, database indexes allow you to find specific data without searching through the entire database. This article explains the basics of indexing, how it improves query performance, and some simple tips for using indexes effectively. Whether your database is small or large, understanding how to use indexes can help keep your application fast and responsive.

15
16
17
18
 
 

Hey guys, I'm pretty new to coding and I recently learnt java and now I have to learn spring boot but there are a lot of sources when searched and it's getting quite complicated.

So is there any documentation which can help me learn spring boot.

Also thank you for all the help.

19
 
 

Like you can see in the linked youtube video (forward to 7:14), he is using an older version of Launch4j and using "Only use private JDK runtimes" in the JRE tab to make sure the .exe file uses the JRE we bundled along with other necessary files. But the latest version I am using (3.5.0) does not have that option.

What is the alternative option for the newer versions of Launch4j?

20
21
 
 

cross-posted from: https://programming.dev/post/17309619

In this article, we will explore the key differences between Ktor and Spring Boot for Kotlin developers based on the experience of various developers.

22
23
24
25
view more: next ›