📜 ⬆️ ⬇️

Tasks for Java Beginners

In continuation of my post " Beginning Java Programmers " I publish my next cheat sheet, namely the list of tasks that I usually give to beginners. To experienced developers, they will seem trivial, but only for beginners to learn Java, and independently, I hope they will be just right. Also, if you use any other tasks for training, then share them, please. :) Since I sometimes feel uneasy at the same time, ... tell the interns the same task - even they hear it for the first time :)

Tasks are arranged in order of increasing complexity. Each task also has several degrees of "development", each of which is aimed at attracting new packages, etc.

Task: Grep Analog


It is necessary to implement a console program that would filter the flow of textual information supplied to the input and output showed only those lines that contain the word transmitted to the program as an argument.

The complication options are:
  1. The program should not be case sensitive.
  2. In the arguments can be passed not one word, but several
  3. The argument can be given not a specific word, but a regular expression.

')

Task: Analog Sort


Write a console program that would sort the text submitted to it to the standard input alphabetically.

The complication options are:
  1. The program should ignore case when sorting
  2. The program should not sort by alphabet, but by the number of characters in the string
  3. The program as an argument can receive the ordinal number of a word in a line by which it is necessary to sort the lines


Task: chat


A task consists of stages, at the end of which a standard console chat should turn out.
  1. Implement a console program that would open a server socket on port 1234. When a client connects, the program should output everything that the client sent. You can make sure that you are working by trying to connect using the telnet system program. In the future we will call this program the server part.
  2. Complicate the program and make it possible for several clients to connect simultaneously via telnet
  3. Implement another console program, which in essence would be analogous to telnet - i.e. connect to the specified IP on port 1234 and send the line entered by the user to the server by pressing enter. In the future, we will call this program the client part or just the client.
  4. Complicate the server part of the program so that the incoming message from one user is sent immediately to all users who are currently connected to the server.
  5. Complicate the server part of the program so that when you connect a new user, it displays the last 10 messages
  6. When starting, the client part should ask the user for his name. Further, when sending messages to the server, the following template should be used: “Username: text”
  7. Up to this point, the message between the server and the client is plain text. It is difficult to transmit the same accompanying information, for example: username, date the message was received by the server, etc. In this task, you need to translate the exchange of information to use Serialization . Those. the exchange of information between the client and the server should be done via the serialized Message class, which in turn contains, in addition to the text, additional attributes: the date the message was created, the user name, the sender's IP, the sender's mode (as in ICQ: sleep, eat, work :) )
  8. Add the server part so that it monitors the number of connected users and does not allow more users to connect than 10
  9. At the moment, many server parameters are written in the code of the program itself, for example: the port on which to open the server, the number of messages issued during connection, the maximum number of connected users, etc. Transfer all these configuration parameters to the XML file.
  10. The server should only allow users who know the corresponding password for their username to connect. To do this, at startup, the client must also ask for the password. When connecting a new user, the server should verify the username / password with the available data in the configuration file. If the password does not match, or such a user does not exist, the server should disconnect the client with the appropriate message.


Task: Java Command Line (JCL)


This task is usually given by me as a qualifier for the entire course of J2SDK.
Implement a console program in Java that would represent some kind of command line implementation, that is, it could execute commands entered line by line by the user. The command is the following line:
" " " â„–1" " â„–2" ... " â„–N"
The code that executes the necessary command of the user, should be made out as a separate Java class. The correspondence between the class and the command name must be specified in the configuration (XML) file of the program. A command at runtime can also interact with the user using standard I / O.
The program must support the following commands:



The complication options are:
  1. The program must support the command "! System_name, argument # 1 ... argument #N", which starts the system program with the corresponding arguments - the same input JCL must be fed to the input of the system program and the same with its output
  2. The program should support the following syntax: “command1 arguments && command2 arguments” and “command1 arguments || command2 arguments ". In the first case, “command2” is launched only if “command1” has completed successfully. In the second case, “command2” is launched only when the execution of “command1” has not completed successfully.
  3. The program must support the ability to run commands in the background. To do this, at the end of the command line, enter the "&" sign. The program should also support the “jobs” command, which lists the tasks that are performed in the background.
  4. Implement the ability to run the program in a network version: i.e. the program opens the port and you can work with it using regular telnet from a remote machine. The program must support the connection of several users at once, as well as the who and write commands, which show who is connected and send a message to everyone, respectively.


PS If someone tries himself in Java for these tasks, then he is ready to check the solved problems and, if possible, to give useful comments :)

PPS What do you think, is it worth supplying the material with links to packages and libraries, the knowledge of which is needed to implement this or that item?

Source: https://habr.com/ru/post/44031/


All Articles