[Solved] Where does Java store the data?

Constructor create object in memory only, and once your app is closed or pc shutdown your data will be lost, store data in a file is useful to store application settings, you have to use an xml or a properties file. If you want to store your business or other data in a database, you … Read more

[Solved] Java questions using only for-loops [closed]

For a consider this : /*Outputs a serious of 5 numbers, starting at 1. The difference between one number to the next one is a sequence of numbers, starting at 1 and incremented by 1 i.e: 1,2,3,4,5 */ //represents the difference between one number and the next one. //the first difference is 1. int step … Read more

[Solved] How to remove numbers from string which starts and ends with numbers?

simple using replaceAll() using ^\\d+|\\d+$ regex that looks for digits in the beginning and ending of the line. System.out.println(“1adfds23dfdsf121”.replaceAll(“^\\d+|\\d+$”, “”)); output: adfds23dfdsf EDIT Regex explanation: ^ Start of line \d+ Any digit (one or more times) | OR \d+ Any digit (one or more times) $ End of line 3 solved How to remove numbers … Read more

[Solved] Return as ByteArrayOutputStream instead of FileOutputStream

I am slightly confused to what you are asking. I have not used Apache Fop, but will try answer this question. If you want to read PDF file as byte array use input streams instead. But if you want to use ByteArrayOutputStream that is writing bytes you basically answered your own question, try using existing … Read more

[Solved] How to sort numeric value in file

To read a file of “lines” in Java you can use the Files class like this: final List<String> l = Files.readAllLines(Paths.get(“/some/path/input.txt”)); This reads a file and stores each line in a List. When you have the List of String objects you can use a simple Comparator and the Collections.sortmethod. Check this code out: final List<String> … Read more

[Solved] In Java, how can I get a variable to print two doubles separately instead of adding them?

You just need to print the number as a string. replace outputDegreesF() with public static void outputDegreesF(double degreesC) { double fahrenheit = 32.0 + (degreesC * 9.0 / 5.0); System.out.print(degreesC + ” ” + fahrenheit); // Easier // Or System.out.printf(“%.7f %.7f”, degreesC, fahrenheit); // Used more and lets you format } If you want to … Read more

[Solved] Spring Mvc method argumrnts

This is basic Java and has nothing to do with Spring. Local variables and method parameters are initialized differently. For a method parameter the initialization is implicit because you must give some value to the method call. Example: // Declaration public String showForm(Model theModel) { } // Call showForm(null); You cannot ommit the argument and … Read more

[Solved] Unable to get data from Sql Server 2005 (connection time out exception)

As the jTDS FAQ states, the URL must be in the form jdbc:jtds:<server_type>://<server>[:<port>][/<database>][;<property>=<value>[;…]] Infering from your connection: mindmill is the name of your_computer/server where Sql Server 2005 is installed. 1433 is the (default) port to connect with Sql Server 2005. employ is the database name. mahesh is your user and password to connect to server. … Read more

[Solved] I want to find all words using java regex, that starts with “#” and ends with space or “.”

This one should be the way: #(\w+)(?:[, .]|$) # matches # literally \w is a word with at least one letter (?:) is non-capturing group [, .]|$ is set of ending characters including the end of line $ For more information check out Regex101. In Java don’t forget to escape with double \\: String str … Read more

[Solved] How can i use less than or equal to for a string? [closed]

user_bal is a String data type and hence <= is not preferred. If you sure the value of this variable will be numbers (integer as variable lim is of type int, used for compare) , then try this String user_bal = (String) dataSnapshot.child(“balance”).getValue(); int userBalance = Integer.parseInt(user_bal); if (userBalance <= lim){ // do something Toast.makeText(PostActivity.this, … Read more

[Solved] Big double number up to two decimal places [closed]

The number is being rounded up correctly The scientific notation 1.13452289575668E8 means 1.3 x 108 which is 113452289.5756680071353912353515625 double d = 1.13452289575668E8; System.out.println(new BigDecimal(d)); gives 113452289.5756680071353912353515625 round to 2 decimal places is 113452289.58 2 solved Big double number up to two decimal places [closed]

[Solved] My loop boolean is not compiling

I’m guessing you want something like this. List<ZipCode> myZips = // create all ZipCode’s somehow public ZipCode findZip(int zip){ //look at all zips for(ZipCode zipCode : myZips){ //if we find one that matches the one we want, return it if(zipCode.getZipCode() == zip){ return zipCode; } } // we checked all our zip’s and couldn’t find … Read more