This question already has answers here:
Closing Streams in Java
(6 answers)
Closed 6 years ago.
With huge advancements in CUPs able to process mass amounts of information in fractions of seconds, why is it important that I close a file stream?
Remember that not all devices are the same, platforms like mobile(smartphones and tablets) need to be as efficient as possible. Or if the application has a big user base, maybe when 400 people are logged in there wont be that many problems, but what happens when it goes to ~40k? You have to make your code as versatile as possible, always think about scalability.
Related
This question already has answers here:
Is there a concurrent List in Java's JDK?
(8 answers)
Closed 5 years ago.
I have a list of accounts that will be updated - not too frequent ~1-2 times a day.
There would be a 'contains' lookup on this data at much regular interval.
An ideal data structure would have been ConcurrentLinkedList ,which unfortunately isnt around.
Is CopyOnWriteArrayList the sole preferred option?
If you are reading mostly , why you need concurrent data structure. Instead you can use HashSet or HashMap. It will make read faster. It is updated so less frequently then u can synchronise the writing part explicitly.
This question already has answers here:
How many characters can a Java StringBuilder hold?
(3 answers)
Stringbuilder maximum length
(2 answers)
Android - Set max length of logcat messages
(14 answers)
Closed 5 years ago.
I'm creating a StringBuilder with it's initial capacity to be 8192 and appending lines to fill it with a little under 6000 characters in this case.
When I write the StringBuilder.toString() value out to the log it cuts off the last 1/4 or so of the whole String. This isn't the first time I've noticed android doing this with strings of similarly large sizes written out to the log.
When I run the same in java on a Linux desktop machine, I've no such problem / behaviour - everything is written out.
Is there some sort of limit I don't know about? Do I have to write out everything line by line in separate calls?
Thank you.
Is Android java StringBuilder limit 4096 characters?
No.
Is there some sort of limit I don't know about?
Yes. LogCat will not log arbitrarily-long messages.
Do I have to write out everything line by line in separate calls?
Well, I would log something smaller, or perform other sorts of diagnostics. But, yes, you could split the string into chunks and log those chunks individually.
This is a debugger issue, the full content should be there but not everything is displayed
See: https://stackoverflow.com/a/43537128/2890156
This question already has answers here:
Turn Image into Text - Java [duplicate]
(4 answers)
Closed 7 years ago.
I want to search a word from image(scanned copy), retrieve values from image, highlight the location. Is there any API or library available for processing images. I am using Swing for displaying images.
You need something to convert the pixels into characters. That something is a program that provides OCR.
Keep in mind that any program you use will provide its best approximation of what it thinks the character is. While technology has improved a lot, there are many fonts, sufficient noise, and various other confounding factors that could result in false input (where the character is not what you would have deemed it to be). There are also scenarios where the input cannot be mapped to a character. Write your software defensively to handle both cases, as this should be considered "non validated input".
Check out "tesseract". It isn't Java, put available for most platforms open-source, and you can call the command-line program from java via System.exec()
https://code.google.com/p/tesseract-ocr/
given the images in the correct format, it's recognition rate is even better than many commercial OCR software products.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I have been experimenting with ways to use the processing power of two computers together as one (not by physically connecting them, but by splitting the task in half and each computer does a half, then the result from the "helper" computer is sent back to be combined with the result from the "main" computer via internet)
I've been using this method to compute fractal images and it works great. The left half and the right half of the image are computed on separate computers, then combined into one. The process of sending one half of the image to the other computer and combining them takes maybe a second, so the efficiency is great and cuts time down by about half.
The problem comes when you want to do this "multi computer processing" with something that needs data exchanged very frequently.
For example, I'd like to use this for something like an n-body simulation. You need the data exchange to happen multiple times per second, so if the exchange takes about a second it actually takes much longer to try and use two computers then it would with one.
So how do online video games do it? The players around you, what they are doing, what they are wearing, everything going on has to be exchanged between everyone playing many times per second.
I'm just looking for general ideas on how to send larger amounts of data and at fast speeds.
The way I have been doing it is with PHP on a free hosting site. The helper computer will compute its half of the data then sends it to the PHP file which saves that data somewhere. Then the main computer reads this and combines it with the data it computed already.
I have a feeling PHP isn't the way to go, but I don't know much about this sort of thing.
Your first step will be to move from using HTTP Requests to using Sockets directly - this will give you much more control over the communication, and give you improved performance by reducing the overhead of the HTTP protocol (this is potentially pretty significant). Plus, with sockets you can more easily have your programs communicate to each other directly, rather than through the PHP-based software.
There are a ton of guides online as to how you would do this sort of system, and I would recommend Googling things like "game networking" and "distributed computing".
Here is one series of articles that I have found useful in the past, that covers the sort of things that you will want to read about: http://gafferongames.com/networking-for-game-programmers/
(He doesn't use Java, but the ideas are universal)
This question already has answers here:
Microphone level in Java
(2 answers)
Closed 10 years ago.
I know there are some questions already like that but always only a part of the answer.
I just want to get the current decibels which are "recorded" by the microphone.
I got as far that i have opened a TargetDataLine but the read method only returns confusing bytes :/
Could you tell me how i can read the decibels?
If you are interested in measuring, for example, dB SPL, This is not possible, at least not in the sense you probably mean. Here is one of several answers about using a computer mike to measure absolute sound intensity: How can I calculate audio dB level?
If you are confused about what the bytes mean and are interested in, for example, measuring change in volume/sound intensity/something like that over time, that is doable, but it's a different question. There are many questions about how to interpret the raw data that comes out of javasound and other audio apis here on SO, but a better source is a tutorial. One good place to start is with some of the examples and tutorials over at java sound resources. You might also be interested in my slides from a talk on the basics of computer audio.