This can't really be done "simply" in any language. You can probably find some amateurish, or perhaps even decent attempts at this with some googling. Good luck understanding the code though. People can go through a lot of years in college and get paid a decent amount of money to put effective image segmentation algorithms in software. In all likely hood you're going to need to download a 3rd party library that has the functionality you want. There's some open source projects on the Internet if you just google "java ocr".