r/javahelp • • May 23 '22

Micronaut returns the empty body

0 Upvotes

Hi,

In my "Hello World" application Micronaut returns the empty body instead of serializing a map as JSON. Here is the code

@Controller
public class BookController {

    private static final DynamoDbClient ddb = DynamoDbClient.builder()
            .httpClient(UrlConnectionHttpClient.builder().build()).build();

    @Get("/{id}")
    public Map<String, AttributeValue> getById(@PathVariable String id) {
        GetItemResponse result = ddb.getItem(GetItemRequest.builder()
                .tableName("DemoTable")
                .key(Map.of(
                        "id", AttributeValue.builder().s(id).build()))
                .build());
        
        System.out.println(result.item());

        return result.item();
    }

}

The line System.out.println(result.item()) prints all data but http response does not contain that.

{
  "statusCode": 200,
  "multiValueHeaders": {
    "Content-Type": [
      "application/json"
    ],
    "Date": [
      "Mon, 23 May 2022 20:26:13 GMT"
    ]
  },
  "body": "{}",
  "isBase64Encoded": false
}

In all examples that I have seen beans use annotation @ Introspected for proper JSON serialization but Map definitely does not have it.

Is there any other way to serialize the map?


r/javahelp • • May 03 '22

Why does eclipse say my scanner and print writer are never closed when I closed both of them?

0 Upvotes

I don’t understand why they eclipse says they haven’t been closed


r/javahelp • • May 06 '22

Requirement in take-home assignment to consider Java Collections memory usage

0 Upvotes

Hello. I have received Java take-home assignment and it states that: "Service should not use any databases (in-memory nor any persistent ones), only Java collections." and also "Think about memory usage and performance when choosing collections".

Now I am completely new to Java and was wondering what are these considerations when it comes to Collection memory usage? Maybe someone can tell.


r/javahelp • • Jan 16 '20

Homework Learning Java

0 Upvotes

Hello everyone, need help on what it is asking and what I should do. Thanks for helping everyone on Reddit! Is it asking what the statement trying to prove?

Refer to the below code snippet and explain the control statement:

for(y = 50, y > -50, y -= 5) System.out.println(y);


r/javahelp • • Jul 03 '19

Solved Why is my If, else if statement skipping the if part?

0 Upvotes

I have an if, else if statement written in my code

If(exam.getGrade()>70) { System.out.println('P'); } else if(exam.getGrade()<70) { System.out.println('F'); }

I tried changing the code around. The numbers. Nothing worked. I can't figure out why it prints out 'F' when in the full code, the exam score is 90


r/javahelp • • Aug 22 '21

Video automation with selenium

0 Upvotes

Hello to all ,

Are in the web guides whom can teach me how to do automation with selenium .

Thanks,


r/javahelp • • Sep 18 '21

Unsolved Java installer not openning

0 Upvotes

So me and her are tring to play some minecraft together, But she didnt has a java, so i decided to help her out. So I have donwloaded java installer from official Javawebsite. We have tried to use online and offline installer and both didnt work. Just after running the installer just wont open, and nothing is happening. Please I really need help her.


r/javahelp • • Dec 24 '22

How do we automate a java application?

0 Upvotes

How can we get the DOM structure of a java application and automate it? Can we use JAAPI ?


r/javahelp • • Feb 02 '23

Solved Does entering/existing try-catch blocks slow down execution?

0 Upvotes

Is there much overhead in having a bunch of try-catch clauses vs having one large block? (I'm still on Java 8 if that matter, probably won't be updating those systems any time soon.)

Something like this:

some code;
some code;
some code;
try{
    some code that might raise an exception;
}catch(SomeException e) {throw new SomeOtherException(e.getMessage);}
some code;
some code;
try{
    some code that might raise an exception;
}catch(SomeException e) {throw new SomeOtherException(e.getMessage);}
some code;
some code;
try{
    some code that might raise an exception;
}catch(SomeException e) {throw new SomeOtherException(e.getMessage);}
some code;
some code;
some code;

vs something like this:

try{
    some code;
    some code;
    some code;
    some code that might raise an exception;    
    some code;
    some code;
    some code that might raise an exception;
    some code;
    some code;
    some code that might raise an exception;
    some code;
    some code;
    some code;
}catch(SomeException e) {throw new SomeOtherException(e.getMessage);}

r/javahelp • • May 21 '21

Someone please tell me what this means

0 Upvotes

var fid = “[email protected]” ;


r/javahelp • • May 12 '21

Theoretical password cracking.

0 Upvotes

Okay, so no I'm not trying to hack into someone's account or anything like that. Originally this idea came up when I had a password protected ZIP file I forgot the password to. From what i understand, passwords are usually hashed. Then when i would enter a password, whatever i enter would then be hashed using the same algo, and compared to whatever the actual password is.

To check if passwords match, I'm assuming they would be iterated over, then if one of the hashed values are not correct, it would return from the function with an error.

Would it be possible, to calculate the time it takes to iterate over a single character. (the time you click submit compared to the time of the error message) Then use that time, to figure out the exact character that was wrong, change it and try again repeatedly until you have the correct one?

Im genuinely curious as to if something like this would work. In my head it seems relatively simple which is why i know it most likely wouldn't work, but would love to hear why it wouldn't. Thank you!


r/javahelp • • Jun 02 '21

Codeless What is Future class in java?

0 Upvotes

I saw this class being used in a project recently, which was handling a parallel processing request. Please explain to me in layman terms what is the purpose of this class?


r/javahelp • • Sep 09 '20

(Help, with Java exercise) Return the square root of a number Then convert this number to an int, rounding to the closest int value.

0 Upvotes

My Code

// Java code below
class SquareRootCalculator {
public int getRoundedSquarRoot(int number) {

float a= Math.sqrt(number);
int b= Math.round(a);
return a;      

    }
}

Test Code

int result = calculator.getRoundedSquarRoot(33);
System.out.println(result);

Console output

error: incompatible types: possible lossy conversion from double to float float a= Math.sqrt(number); ^


r/javahelp • • Sep 10 '20

The program im using says this has an illegal static declaration, how do i fix this? It seems alright to me

0 Upvotes

public class Helloworld {

public static void (String[] args) {

System.out.println("Hello, world");

}

}


r/javahelp • • Aug 24 '20

Can somebody explain to me a final method?

0 Upvotes

Was messing around in an IDE and tried to declare a method as final and for some reason it worked, so I'd like someone to explain to me what it is please!


r/javahelp • • Sep 05 '20

Need Help with Popping Blocks Program

0 Upvotes

public class Challenge {

public static char\[\] finalResult(char\[\] letters) {

	StringBuilder sb = new StringBuilder(new String(letters));

	

	

	public static int getRepeatingCharIndex(String str) {

		for (int i=0; i<str.length()-1; i++) {

if (str.charAt(i) == str.charAt(i+1))

return i;

		}

		return -1;

	}

	int index = getRepeatingCharIndex(sb.toString());

	

	while (index != -1) {

		int end = index;

		while (end < sb.length() && sb.charAt(end) == sb.charAt(index))

end++;

		sb.delete(index, end);

		index = getRepeatingCharIndex(sb.toString());

	}

	return sb.toString().toCharArray();

}

}


r/javahelp • • Nov 25 '15

Ticket prices calculator help

0 Upvotes

Hi guys I'm trying to write a ticket calculator for a Christmas fair, I need to be able to let the user write in how many adult tickets are needed and also how many child tickets. Then have it be calculated and the total price be displayed. The thing is that I can't see how I'm meant to lay it out to do this. I know what I have to do but I just can't lay it out properly so it will work. Does anyone have any examples of anything like this or could help walk me through it. Would be greatly appreciated thanks guys


r/javahelp • • Mar 11 '18

Farm Simulator java

0 Upvotes

Hi guys, I need help with my java project for school. I need to make a farm simulator where I will have two types of plants (tomatoes and cabbage), a farmer and sheeps. The objective of the game is win points by planting , caring and gather the plants. The farmer is controlled by the keyboard arrows and to do action you press space. How it works: It starts with a fixed configuration (a farm 7x5, without plants and the farmer in top right corner) 2.When you press a key it counts like a 1 game cycle for all objects. 3. You got tomatoes and cabbages. 4. The camps can be for plowing or plowerd already. 5. In plowerd camps you can have : nothing, small vegetables,vegetables ready to gather or ruined. Interactions: Farmer - for plowing camp: the camp get plowerd. Farmer- plowed camp: Plants randomly tomatoes or cabbages. Farmer - Small vegetables: Farmer takes care of platns, at the case of cabbages that speed up their growth, at the case of tomato it only get mature if the farmer had already interact with them. Farmer-Sheep: Feeds the sheep. Sheep-Plants- If the sheep isn't feed for the last 10 cycles she eats the platns. Tomato: mature after 15 cycles, ruined after 25 cycles. Cabbage: mature after 10 cycles,ruined after 30.

https://gyazo.com/476ca626054ea57bbe487b11b22953f3- Uml


r/javahelp • • Jun 08 '14

What is wrong with this basic code?

0 Upvotes

I've recently started learning java, (as in yesterday) and so today I decided that I was going to try to make a basic program that would tell you the volume of a cube. For some reason eclipse is saying The operator * is undefined for the arguement type(s) java.lane.String, java.lane.String on this line of code: answer = widthheightlength; Here is the whole code, and I should say that this is my first post so I apologize in advanced if I pasted the code incorrectly.

package stringvars;

import java.util.Scanner;
public class test{
    public static void main(String[] args){

Scanner user_input = new Scanner(System.in);

String width, height, length, answer; 
	System.out.println("Enter the width of the Cube ");
	width = user_input.next();
	System.out.println("Enter the height of the Cube ");
	height = user_input.next();
	System.out.println("Enter the length of the Cube");
	length = user_input.next();
	answer = width*height*length;
	System.out.println("The volume of your cube is " + answer);
           }
     }

r/javahelp • • Dec 09 '19

Trying to find a chat room

0 Upvotes

Am learning java.to discuss about some problems I want to join a chat room.can anoyone suggest me about it???


r/javahelp • • Aug 19 '18

Question about JVM.

0 Upvotes

I have heard that Java is considered secure because the code actually runs in JVM and not on OS which is fine for most apps. For example if I am making a to-do app. But what if I want to make an app like CCleaner, it will need to delete some files (cache, junk files) from system. How will I be able to access system files as my code is contained inside JVM. If Java does allow me to access the system(read/write system files) via OS level API's then this statement that Java code runs only inside JVM and this is more secure than other programming languages is false.

If JVM internally checks what should and what should not be allowed to accessed then how is it different from, say python. Even their interpreter must be capable of making them as secure as Java.


r/javahelp • • Jul 28 '19

What to do if your webhost just said they can’t help?

0 Upvotes

I have been hosting my Java EE site with a hosting company. Back then, I had no idea what a web hosting company does etc so when they helped me to host my pages I was immensely happy.

Now, I picked up more on programming and need to upload a new one. But, I find that whenever I uploaded something, the log in Tomcat indicated I have uploaded.

However, after re-start of my Tomcat thru a control panel, I did not see my web pages but it reflect something from my sub-domain instead.

I wrote to the support. As usual, they just said that it is my problem and I did not put in the logging mechanism.

Yesterday night, I went back to my emails 8 years ago and managed to find out that guy - I presume is the reseller and owner and talked to him.

And all he said is there was nothing wrong with it.

I really do not know how to handle them. And I need time to figure out how to host it somewhere else including AWS cos I still need to learn how.

Cos it seems there is a type of host that allows me to control the server but I may need to learn up linux commands etc...I am not even sure what are the free courses out there that can address my needs

With their attitude, I am worried that my transition to another webhost may be difficult.

Furthermore, the database I downloaded in csv and sql format just couldn’t be imported into another database.

I am dealing with so many problems I hope someone with a cool head will let me know how I should tackle all these headaches. Thanks.


r/javahelp • • May 18 '19

Help

0 Upvotes

can someone help me understand what this means? or what will it return.

public String getKey(String identifier, String secret, String unique)

throws Exception

{

return "'" + identifier + secret + unique + unique.charAt(0) + "',$21,'" + secret.charAt(2) + unique.charAt(1) + unique.charAt(3) + secret.charAt(0) + secret.charAt(4) + "iaM" + unique.charAt(2) + "',$20,'" + secret.charAt(3) + "',14,6,'D" + secret.charAt(1) + "Z&" + unique.charAt(5) + "',6,'1B" + unique.charAt(4) + "%'";

}


r/javahelp • • May 13 '19

JSF

0 Upvotes

Are JSF dead?