Java example


In this chapter, we will introduce common examples of Java. Through example learning, we can master Java applications faster.

Java environment setting example

  1. Java example – How to compile a Java file?

  2. Java Example - How to run a compiled class file in Java?

  3. Java Example - How to execute a specified class file directory (classpath)?

  4. Java Instance – How to check the version of Java currently running?


Java String

  1. Java Example – String comparison

  2. Java Example – Find the last occurrence of a string

  3. Java Example – Delete a string A character in

  4. Java Example - String Replacement

  5. Java Example - String Reverse

  6. Java Example-String Search

  7. Java Example-String Splitting

  8. Java Example-String Lowercase Conversion to Uppercase

  9. Java Example - Test whether two string areas are equal

  10. Java Example - String Performance Comparison Test

  11. Java Example-String Optimization

  12. Java Example-String Formatting

  13. Java Example-Concatenation String


Java Array

  1. Java Example – Array Sorting and Element Search

  2. Java Example – Adding Elements to Array

  3. Java Example – Get Array Length

  4. Java Example – Reverse Array

  5. Java Example – Array output

  6. Java example – Array gets the maximum and minimum value

  7. Java example – Array merge

  8. Java Example – Array Filling

  9. Java Example – Array Expansion

  10. Java Example – Array Sorting and Search

  11. Java Example – Delete Array Elements

  12. Java Example – Array Difference

  13. Java Example – Array Intersection

  14. Java Example – Find the specified element in the array

  15. Java Example – Determine whether the array is equal

  16. Java Example - Array Union


Java Time Processing

  1. Java Example - Formatted Time (SimpleDateFormat)

  2. Java Example - Get the current time

  3. Java Example - Get the year, month, etc.

  4. Java Example - Timestamp conversion Time to complete


Java Method

  1. Java Example – Method Overload

  2. Java Example – Output Array Elements

  3. Java Example – Tower of Hanoi Algorithm

  4. Java Example – Fibonacci Sequence

  5. Java Instance – Factorial

  6. Java Instance – Method Override

  7. Java Instance – instanceOf Keyword Usage

  8. Java Example – break keyword usage

  9. Java Example – continue keyword usage

  10. Java Example – Label (Label)

  11. Java Example – Use of enum and switch statements

  12. Java Example – Use of Enum (enumeration) constructor and method

  13. Java Example – Use of for and foreach loops

  14. Java Example – Use of Varargs variable parameters

  15. Java Example – Overloading Using Varargs in the (overloading) method


Java File Operation

  1. Java Example - File Writing

  2. Java Example - Read file content

  3. Java Example - Delete file

  4. Java Example - Copy file content to another A file

  5. Java Example - Append data to the file

  6. Java Example - Create a temporary file

  7. Java Example - Modify the last modification date of the file

  8. Java Example - Get the file size

  9. Java Example - File Rename

  10. Java Example - Set file read-only

  11. Java Example - Check whether the file exists

  12. Java Example- Create a file in the specified directory

  13. Java instance-get file modification time

  14. Java instance-create file

  15. Java Example - File Path Comparison


Java Directory Operation

  1. Java Example - Recursive Directory Creation

  2. Java Example - Delete Directory

  3. Java Example - Determine whether the directory is empty

  4. Java Example - Determine File Whether to hide

  5. Java instance-get directory size

  6. Java instance-find files in the specified directory

  7. Java Example - Get the upper-level directory of the file

  8. Java Example - Get the last modification time of the directory

  9. Java Example - Print directory structure

  10. Java Example - Traverse all directories under the specified directory

  11. Java Example - Traverse all files under the specified directory

  12. Java Example - Find files in the specified directory

  13. Java Example - Traverse the system root directory

  14. Java Example - View the current Working Directory

  15. Java Example - Traversing Directory


##Java Exception Handling

  1. Java Example-Exception handling method

  2. Java Example-Multiple exception handling (multiple catches)

  3. Java Example-Usage of Finally

  4. Java Example-Use catch to handle exceptions

  5. Java Example-Multi-threaded exception handling

  6. Java Example- Get exception stack information

  7. Java instance - overloaded method exception handling

  8. Java instance - chain test exception

  9. Java Example – Custom Exception


Java Data Structure

  1. Java Example – Number Sum Operation

  2. Java Example – Convert infix expression to suffix using stack

  3. Java Example – At the beginning and end of LinkedList

  4. Java instance – Get the first element of the linked list (LinkedList)

  5. Java instance – Delete the element in the linked list

  6. Java Example – Get the elements of the linked list

  7. Java Example – Get the index value of the vector element

  8. Java Example – implementation of stack

  9. Java example – search for linked list elements

  10. Java example – method of pushing and popping the stack to implement string reversal

  11. Java Example – Queue Usage

  12. Java Example – Get the Maximum Element of a Vector

  13. Java Example – Linked List Modification

  14. Java Example – Rotation Vector


Java Collection

  1. Java Example – Convert Array to Set

  2. Java Example – Set Comparison

  3. Java Example – HashMap Traversal

  4. Java Example – Collection Length

  5. Java Example – Collection Shuffle Order

  6. Java Example – Collection Traversal

  7. Java Example – Reverse Collection

  8. Java Example – Delete the specified element in the collection

  9. Java Example – Read Only Collection

  10. Java Example – Collection Output

  11. Java Example – Collection to Array

  12. Java Example – List loop moves elements

  13. Java example – Find the maximum and minimum value in List

  14. Java example – Traverse the key values ​​of HashTable

  15. Java Example – Use Enumeration to traverse HashTable

  16. Java Example – Add different types of elements to the collection

  17. Java Example – List element replacement

  18. Java example – List interception


Java network example

  1. Java instance – Get the IP address of the specified host

  2. Java instance – Check whether the port is already in use

  3. Java instance – Get the local ip Address and host name

  4. Java instance – Get remote file size

  5. ##Java instance – Socket implements multi-threaded server program

  6. Java Example – View the last modification time of the specified file on the host

  7. Java Example – Use Socket to connect to the specified host

  8. Java Example – Web scraping

  9. Java Example – Obtain the date information of the URL response header

  10. Java Example – Obtain the URL response header information

  11. Java instance – parsing URL

  12. Java instance – ServerSocket and Socket communication instance


Java Thread

  1. Java Instance – Check whether the thread is alive

  2. Java Instance – Get the current thread name

  3. Java instance – status monitoring

  4. Java instance – thread priority setting

  5. Java instance – deadlock and solution

  6. Java instance – Get thread id

  7. Java instance – Thread hangs

  8. Java instance – Terminate thread

  9. Java Instance – Producer/Consumer Issue

  10. Java Instance – Get Current Thread Name

  11. Java Instance – Status Monitoring

  12. Java Instance – Thread Priority Setting

  13. Java Example – Deadlock and Solution

  14. Java Example – Obtain Thread Status

  15. Java Example – Get all threads

  16. Java instance – view thread priority

  17. Java instance – interrupt thread