[Solved] I’m writing my first ever java program and it’s not compiling for a certain reason [duplicate]

basically the compiler tells you whats wrong. It says, “class main is public, should be declared in a file named main.java”. Java has a naming rule, that a class inside a java file needs to match that file name. Example 1: Filename -> File.java inside that file: public class Main{ … does violate that rule … Read more

[Solved] In Pair.of() : Can you change the name of(S first, T second)? [closed]

Solution for Jackson: Declare serializer for specific class Pair public static class PairSerializer extends StdSerializer<Pair> { public PairSerializer() { this(null); } public PairSerializer(Class<Pair> t) { super(t); } @Override public void serialize(Pair value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { jgen.writeStartObject(); jgen.writeObjectField(“a”, value.getFirst()); // “a” is replacement for “first” jgen.writeObjectField(“b”, value.getSecond()); // “b” is replacement … Read more

[Solved] To store gps location in firebase real time database

You can send the location to Firebase by using the Firebase Database and DatabaseReference classes. First you have to make sure that you have these SDK’s in build.gradle: implementation ‘com.google.firebase:firebase-storage:16.0.4’ implementation ‘com.google.firebase:firebase-database:16.0.4’ Also, make sure that you have set up your Realtime Database in the Firebase Console. It would be best if you choose the … Read more

[Solved] When assigning a value Java gives the error ‘java: expected’, Why? [duplicate]

Your’re probably not using it in a method. Place it in a method as shown below : public static void main(String[] args) { char aCharacter=”A”; aCharacter=”\u0041″; } This is because assignments are statements and statements are allowed only inside blocks of code. 0 solved When assigning a value Java gives the error ‘java: expected’, Why? … Read more

[Solved] need to determine the positive, negative and zero numbers in program and add all the positive and negative numbers separately [closed]

Is the problem that you want to run the loop 10 times? You’ve got a count variable that you are not otherwise using. The loop should look something like: int count=0; while (count != 10) { … ++count; } Conventionally a for loop is used for this (if allowed): for (int count=0; count<10; ++count) { … Read more

[Solved] Can I call a .java file from a .html file with href or something else without using javascript in-between [closed]

Updated from OP comment: Thank you very much for your reply and let me correct the question can I call a function which is written in java directly from a html. – JAVA Coder Nov 5 at 9:08 Still the same answer. Methods or functions, terminology aside. What you’re proposing is like trying to power … Read more

[Solved] How to check if there are 2 upper case letters, 3 lower case letters, and 1 number in JAVA

This looks like a homework question so I won’t solve it directly. However here are some steps you could take: Create a method to validate the input (public static boolean isValid(String str)) Convert the String to a character Array. (There’s a method for that!) Iterate over the letters and keep track of how many upper … Read more

[Solved] why this lambda expression do not work when in statement ,but work in method?

In your second code version: Map<Object, Boolean> seen = new ConcurrentHashMap<>(); The map Map<> seen is initialized for every element x, therefore your filter always return true which will let all elements passthrough. Move the Map<> seen declaration to outside the lambda will correct your usage. In the first code version, the Map<> seen is … Read more

[Solved] why is it showing error . Like I thought the third loop will end and it will enter the first loop but didn’t else showed an exception

just replace the condition of the there loops with 26. Now the exception index out of bound will not occur public class SuggestingAppNames { public static void main(String[] args) { System.out.println(“the possible outcomes are”); String a = “A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z”; String d[] = a.split(“,”); String b = “A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z”; String e[] = b.split(“,”); String c = “A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z”; String … Read more

[Solved] How do I show a result from Random in a textview?

You have to add a TextView to display the result. Step 1. Adding ID to TextView, in the XML file. <TextView android:id=”@+id/myId” android:layout_width=”wrap_content” android:layout_height=”wrap_content” …. /> Step 2. Finding TextView using ID, under onCreate method: @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TextView myTextView = (TextView) findViewById(R.id.myId); } Step 3. Set the text with … Read more