Java Bean Validation

Java Bean Validation

Overview Data validation is a crucial process in software development. Invalid data may easily break the application. So, ideally, the input data should be validated as soon as possible and handled in a corresponding way. Since data validation is one of the most common programming logic, it makes sense to find a way to reduce code duplication. Bean Validation 2.0, defined by JSR 380, is a specification of the Java API for bean validation. It defines a way to validate…

Read More Read More

Aspect-oriented programming (AOP) with Spring Boot

Aspect-oriented programming (AOP) with Spring Boot

Overview Aspect-oriented programming (AOP) is a programming paradigm that aims to increase modularity by allowing the separation of cross-cutting concerns. Cross–cutting concerns are parts of a program that rely on or must affect many other parts of the system. Commonly used cross-cutting concerns are: logging transaction management performance monitoring security checks etc. AOP concepts Aspect: The concern that cuts across multiple classes or modules. Transaction and security are examples. Spring Transaction is implemented as Aspects. Join point: A point during the execution of the program at which you…

Read More Read More

Sessions in Redis (Spring Boot)

Sessions in Redis (Spring Boot)

Overview HTTP is a stateless protocol. It means that every time a new request is sent from the client to the server the state information of the previous request is lost. Sessions are used to store some state between requests. When a client successfully authenticates into a website, a new session is created. The next time the client visits a website, he will get access immediately without passing credentials again. How does this work technically? After successful authentication, the new…

Read More Read More

WebSockets Spring Boot

WebSockets Spring Boot

Overview WebSocket is a bi-directional communication protocol between a browser and a server. Let’s imagine that we need to check new incoming messages without reloading a page. One way could be sending regular AJAX requests. It’s called polling. Another way could be long polling. In this case, a server holds an AJAX request and returns a response only when new messages appear. In mentioned approaches the client asks a server and gets a response. In case of web sockets, there…

Read More Read More

Google/Facebook OAuth (Spring)

Google/Facebook OAuth (Spring)

Overview Probably all modern websites or applications nowadays provide the possibility of authenticating to a system via Google/Facebook/Twitter/etc. It’s indeed more convenient because a user doesn’t have to create yet another account and remember credentials, but can just use e.g. Google account to get access to various services. This is possible thanks to OAuth. OAuth is an open standard for access delegation, commonly used as a way for Internet users to grant websites or applications access to their information on other websites but…

Read More Read More

Speech recognition: voice control (Java, Kaldi)

Speech recognition: voice control (Java, Kaldi)

Speech recognition is a field of computer science and computational linguistics that develops methodologies and technologies that enable the recognition and translation of spoken language into text by computers. The first speech recognition applications you may think of are Google Assistant, Alexa, Siri. It’s used in various fields: banking, e-commerce, workplace, IOT, language learning, etc. To be honest, this topic is not something you would easily dive in without a strong theoretical foundation. Though there are ready-to-use solutions with noticeable accuracy that may…

Read More Read More

UNIX “tail -f” (Java)

UNIX “tail -f” (Java)

Одной из часто встречающихся активностей во время отладки или поиска неисправностей является мониторинг обновлений файла. На UNIX системах это обычно делается при помощи команды “tail -f”. Например: Но что если нужно не только отслеживать изменения в файле, но и обрабатывать их в реальном времени в вашем приложении ? К счастью, имеются готовые решения для таких задач. Один из них и будет рассмотрен в данной статье – Apache Commons IO. Зависимости В первую очередь, нужно добавить Maven зависимости: Приложение Для практического…

Read More Read More

PhantomJS scraping on word translation example

PhantomJS scraping on word translation example

In the previous article, we’ve shown an example of web scraping using Jsoup. You may be interested in how it is different from PhantomJS scraping. Jsoup parses HTML content that is available on a page load. In most cases, it’s enough, but in some cases, modern websites have content that is loaded dynamically via JavaScript. Hence Jsoup may receive just an empty page without loaded data (e.g. products). In such cases, headless browsers are a way to go and PhantomJS…

Read More Read More

Web scraping using Jsoup (Java)

Web scraping using Jsoup (Java)

Web scraping is data extraction from websites and Jsoup is quite a popular tool to do it in a convenient way. It is is an open-source Java library designed to parse, extract, and manipulate data stored in HTML documents. There are lots of use-cases. For example, you may be looking for a new apartment to rent on a website or monitoring discounts on an e-commerce store. If the website does not have a feature to subscribe to newly added records,…

Read More Read More

UNIX “tail -f” functionality in Java

UNIX “tail -f” functionality in Java

Overview If it’s needed to monitor lines appended to the end of the file, UNIX utility “tail” with “-f” parameter is usually used to achieve that. Here is an example: tail -f /var/log/auth.log What if it’s needed not only to monitor lines, but also to process them in your application ? Luckily, there are easy-to-use solutions and one of them is going to be discovered in this article. Apache Commons IO provides a functionality that solves the problem mentioned above. Dependencies First…

Read More Read More