RUVIDEO
Поделитесь видео 🙏

Thoughts on Java - Episode 3

📁 Лайфстайл 👁️ 17 📅 05.12.2023

Thoughts on Java - Episode 3

December 12, 2022

This is an improved version of the third Java program that I created this year, on April 17, 2022. I encountered an unresolved compilation problem "The local variable age may not have been initialized" when I ran the original version of this program. Thanks to a user on Stack Overflow, this compilation problem was resolved. The objective of this Java program is to achieve a similar and more user-friendly result than that of the Java program mentioned in Thoughts on Java - Episode 2. By instantiating a GUI component of javax.swing package, it is possible to create something that is arguably more visually appealing than an indefinite number of lines of plain text displayed in the console. This GUI component is JOptionPane, which is one of the first GUI components that I have learned to instantiate and utilize. Next, I am going to expound the syntactic details of this program. I am also going to explain the fundamental syntactic usage of JOptionPane with an illustrative example of this program.

In the beginning of the improved version of this Java program, a wildcard import statement with javax.swing followed by an asterisk was typed. This means that all classes in this package have been imported. Some argue that wildcard import statements are a bad practice, while others do not. In this program, the only class that needs to be imported is JOptionPane, therefore it is possible to replace the asterisk with JOptionPane. In the beginning of method main, I incorporated an infinite loop, namely the while(true) statement, which is the most important feature of the Java program that I mentioned in Thoughts on Java - Episode 2. This statement is followed by an opening curly bracket, the try keyword, then another opening curly bracket. This means that all the if-else-if statements should be included in the try block. Then, a double variable representing age was declared final, as suggested by the user on Stack Overflow. It is considered that the final keyword in Java is equivalent to the const keyword in C++. If a variable is declared final in Java, or declared const in C++, the value of this very variable is immutable. After the double variable representing age is declared final on the left-hand side of the assignment, I typed the parseDouble() method of Java Double class. It is possible to use this method to parse String to double, therefore a String value should be included in the pair of parentheses of this method, in which I included the showInputDialog() method of the JOptionPane class. Later in the program, the showMessageDialog() method of this class is used each time after the if statement and each else-if statement. The parameters of such methods of the JOptionPane class may vary. Next, I am going to expound the syntactic details of such methods.

In this program, there are two parameters for the showInputDialog() method. Its first parameter is "parentComponent" to which the null value is assigned, whereas its second parameter is "message" to which String literals can be assigned. All the showMessageDialog() methods also have these two parameters, but a few of them have four parameters. of The null value is assigned to the first parameters of the showInputDialog() method as well as all the showMessageDialog() methods, because it is unnecessary to define any parent component for the question-message dialog. In order to define any parent component for any question-message dialog, it is required to instantiate a Swing object such as JFrame. Then, it is possible to define the existing JFrame object to be the parent component of the question-message dialog. In the second parameters of the showInputDialog() method, string literals are bracketed by double quotes. Nevertheless, it should be noted that the showInputDialog() method returns a String denoting user input, whereas the return type of the showMessageDialog() method is void. Therefore, it is not permitted to define a showMessageDialog() method within the pair of parentheses of the parseDouble() method. After I typed all the else-if statements with the age ranges, and all the showMessageDialog() methods with String literals bracketed by double quotes, the try block was finished with a closing curly bracket.

Then, it is necessary to catch two different exceptions. After the closing curly bracket, I typed the catch keyword followed by an opening parenthesis, NumberFormatException, the default letter 'e' as a reference to the instance of this exception, a closing parenthesis, and an opening curly bracket. I think that NumberFormatException resembles InputMismatchException in terms of their functionalities. The difference between these two exceptions is that the first exception applies to the type of the token retrieved by the Scanner object in the console, whereas the second exception applies to the format of the String literal entered in the message in the dialog box. In the catch block for ...

Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «Thoughts on Java - Episode 3», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.

Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.

Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!

Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.