


My girlfriend cried and said she couldn't learn Java. That night I taught her the basics...
Jul 26, 2023 pm 05:28 PMIntroduction to Java
What is Java
Let’s first take a look at Baidu Encyclopedia’s explanation:
Java is a programming language that generates software for multiple platforms. Developed in the mid-1990s by former Sun Microsystems computer scientist James A. Gosling. The compiled code runs on most operating systems.
From the above we understand that Java is a high-level language used to develop software. Java provides an integrated development toolkit JDK, which allows us to compile the Java code we write into a bytecode file. (class file), the Java Virtual Machine (JVM) is responsible for converting bytecode into machine code for execution on each operating system. The operating system controls the hardware to respond after receiving the instructions.

The process a programmer goes through from the beginning of coding to the end when the computer responds to the code It probably looks like this:

What can Java do
Server Programming
Java is currently one of the best languages ??in the field of server programming. Many banks' trading systems are developed using Java, and in most cases there is no front-end. They usually receive data from a server (upper level), process it and send it to another processing system (lower level processing)Developing websites
In the field of developing personal or commercial websites, Java provides very mature solutions for us to choose from. You can use many different frameworks to create web projects, such as SpringMVC , SpringBoot and so on.Development software
For example, the Java integrated development environments Eclipse and Idea that we are very familiar with are all developed using Java.Android
Most of the apps we use every day are actually developed using Java. Although Android uses different JVMs and different packaging methods, the code is still written in Java. language written.Embedded devices
Java has great room for development in the embedded field. To engage in embedded development, you need to download the J2ME development package from Sun. J2ME includes a dedicated virtual machine KVM for embedded devices, which is different from the JVM included in the ordinary JDK. In addition, you need to download the simulator from a specific embedded manufacturer.There are so many fields to list...
Why learn Java
Some people said: PHP is the best language in the world. Later, this sentence spread as a joke on the Internet. But many programmers who specialize in other languages ????have quit. Why? What's so arrogant about PHP, a scripting language? C Isn’t it delicious? Isn’t Python great? But I think Java is the most popular. Let’s take a look at the reasons:

Interested students can search online for language rankings in various years. list, Java has occupied the first place in the list for almost a long time, on par with C. As a low-level language among high-level languages, C is closely related to hardware and has high operating efficiency, so many low-level programs are developed in C. Because of its dominance in the field of server programming and its portability, Java will still become one of the most popular programming languages ??for many years to come.
#If you are learning a language to find a good job, then there is absolutely no problem in choosing Java. And I personally think that Java is relatively easy to learn. I will summarize the outline of Java learning based on the actual working environment, and list the key and difficult points and must-know knowledge points. As long as you study hard, you can master this language in a short period of time and develop programs independently.
After you have some basic foundation and practical experience, you can go to the company for internship and participate in the development of actual projects, and you will soon be able to enter the industry.
How to learn Java
Learning any programming language, in addition to the basic theory, is inseparable from coding, coding, coding . This is just like learning knowledge when we study. We will learn a lot of new knowledge points in every class. These knowledge points may be taught to you by the teacher in lectures, or you may have mastered them by yourself. You must do some exercises after class. What is the purpose of practice questions? It is to verify whether you have truly mastered the knowledge points you have learned and to check for any omissions.
Many students who learn Java like to watch videos, watching the teacher teach programming in the video, and then follow the teacher to type the code unchanged. If there is any small error in the teacher's program, or if the program fails to execute, you will be completely confused and don't know how to proceed. So I searched for information online, joined various study groups, and asked for help from experts in the groups. How did I do this? How did you adjust that?
I want to ask, is this the correct way to study? What is the purpose of watching the video? Quickly learn the basics of programming languages ??and master this programming language. So is this a learning method of asking others for help without thinking? Is it mastered? Note that what I am talking about here is completely copying the code learning method. This way of learning creates an embarrassing situation: I have no idea at all when writing code myself.
If this is the case, we can quickly learn the knowledge points of the chapter by watching the video, and then follow the teacher to type the code. After comparing the knowledge points, think about the meaning of each step of the code execution, and take notes ourselves. This is the effect. Isn’t it better? After class, we found some basic exercises and tried to implement programming without reading the materials. If we have no idea, we can enumerate steps 1, 2, 3, and 4 just like solving a problem to help us understand. Let me give you an example:
Question: Enter a line of characters and count the English letters. , spaces, numbers and the number of other characters
// 開始構(gòu)思 // 1. 我們需要輸出4個數(shù),那么先定義4個變量 int a,b,c,d = 0; // 2.獲取系統(tǒng)用戶輸入的字符串,再定義一個變量接收這個字符串 Sting s; // 3.一行字符必須拆開才能統(tǒng)計,所以把字符串轉(zhuǎn)換成數(shù)組; // 4.數(shù)組需要遍歷,拿到數(shù)組的每個字符; // 5.判斷每個字符是什么類型,找到對應(yīng)的字母、數(shù)字和空格類型就將對應(yīng)類型的變量+1,沒找到就按其他處理d+1; // 6.輸出每個字符的個數(shù)
This is a very simple exercise to practice loops and branch structures. Maybe you know how to do it, but you don’t know where to start when you start writing. This is the dilemma that many novice programmers are currently in. So if you sort out points 1, 2, 3, and 4 before writing code like me, and break down each step in detail, would it be helpful for you to write a program?
This kind of thinking analysis is called pseudocode. It means to use words to describe the work done by your program first, and then fill in the steps according to the steps to complete the program design. I hope that friends who are new to programming can refer to this method and really start writing code by themselves. The more code you write, the more comfortable you will be when writing, and the broader your programming ideas will be. This is a summary of my experience, I hope it can help you.
Java development environment installation
JDK download
As of now, the latest version of Java that has been released is Java SE 14, but The most used Jdk version is 1.8. If we study, I suggest we also study based on the 1.8 version.
Download address (Oracle official website): Jdk download address
After opening, find the required jdk version on the page. This time, take version Java SE 8u251 as an example, click the link to download

After clicking, a pop-up box like this will appear. We just need to check and confirm:

Next, you need to log in to Oracle. Of course, you need to register before logging in, so I won’t go into details here.

You can download it after logging in

For everyone’s convenience, I downloaded the installation package in advance and uploaded it to the network disk. You can download it yourself:
windows version extraction code: xpak
linux version extraction code: upse
mac version extraction code: kmv5
Jdk安裝
win版安裝
雙擊安裝,下一步按流程走完,不要裝jre,因為jdk包含了jre。
環(huán)境變量配置:
右擊我的電腦,選擇屬性,點擊高級系統(tǒng)設(shè)置:

選擇環(huán)境變量:

在系統(tǒng)變量里,點擊新建按鈕,創(chuàng)建JAVA_HOME目錄,變量值填入你的jdk安裝目錄:

然后點擊Path,再點擊編輯,輸入Java的bin目錄,格式如下:

注意:win7的話需要找到Path,雙擊打開后在后面手動輸入 %JAVA_HOME%/bin;
確定之后,打開cmd,輸入
java -version
如出現(xiàn)下面有版本號的結(jié)果,則表示Java安裝成功:

Linux版本安裝
請參考教程:Linux Java安裝教程
Mac版本安裝
請參考教程:Mac Java安裝教程
開發(fā)工具選擇
notepad++ 。初入門寫程序,可以用文本編輯器,對于熟悉Java語法非常有幫助。notepad++下載地址:
https://notepad-plus-plus.org/downloads/v7.8.6/Eclispe。我剛學Java的時候用的就是Eclipse,它是完全免費,使用也比較簡單。下載地址:https://www.eclipse.org/downloads/
下面這篇教程會教你如何下載安裝和使用:Eclipse 安裝(Neon 版本)IDEA。IDEA是我現(xiàn)在用的編輯器,個人感覺非常好用,是目前開發(fā)Java最好的編輯器,非常推薦大家使用。缺點是比較吃內(nèi)存,而且商用版的需要破解或者購買才能使用,不過社區(qū)版的可以免費使用,對于初學者來說足夠了。下載地址:https://www.jetbrains.com/idea/
第一個Java程序
入門程序HelloWorld
新建一個txt文件

修改后綴名變成 .java文件

HelloWorld的java程序代碼如下:
public class HelloWorld{ public static void main(String[] args) { // 打印一句話 "Hello World" System.out.println("Hello World"); } }
注意代碼不要寫錯,然后我們開始運行一下:
在文件夾路徑上輸入cmd
命令

打開這樣的黑窗口

輸入下面的命令:
javac HelloWorld.java
正常的話,文件夾會多出來一個 HelloWorld.class 文件:

然后再執(zhí)行命令(注意HelloWorld 后面沒有 .class)
java HelloWorld
我們可以看到,命令行打印了我們輸出的語句 Hello World, 這就說明我們的程序是完全正確的,沒有問題。是不是很簡單呢,你學廢了嗎?
解釋一下Hello World程序
這里首先我們定義了一個類,類是 “public” 公共類型的,類名為“HelloWorld”。另外,Java 中主類名必須和Java 文件名相同,也就是說,這里定義的類名是“HelloWorld”,則文件應(yīng)該保存為“HelloWorld.java”。
public static void main(String[] args)
這一句是Java 中的主運行方法,它和 C/C++中的main()作用是一樣的,就是所有的程序都從“main()”中開始執(zhí)行。要執(zhí)行 Java 程序,必須有一個包括主運行方法的類。
System.out.println("Hello world");
這一句是 Java.lang 包的一個方法,用來將字串“Hello world”輸出到命令行窗口。
The above is the detailed content of My girlfriend cried and said she couldn't learn Java. That night I taught her the basics.... For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

The settings.json file is located in the user-level or workspace-level path and is used to customize VSCode settings. 1. User-level path: Windows is C:\Users\\AppData\Roaming\Code\User\settings.json, macOS is /Users//Library/ApplicationSupport/Code/User/settings.json, Linux is /home//.config/Code/User/settings.json; 2. Workspace-level path: .vscode/settings in the project root directory

itertools.combinations is used to generate all non-repetitive combinations (order irrelevant) that selects a specified number of elements from the iterable object. Its usage includes: 1. Select 2 element combinations from the list, such as ('A','B'), ('A','C'), etc., to avoid repeated order; 2. Take 3 character combinations of strings, such as "abc" and "abd", which are suitable for subsequence generation; 3. Find the combinations where the sum of two numbers is equal to the target value, such as 1 5=6, simplify the double loop logic; the difference between combinations and arrangement lies in whether the order is important, combinations regard AB and BA as the same, while permutations are regarded as different;

To correctly handle JDBC transactions, you must first turn off the automatic commit mode, then perform multiple operations, and finally commit or rollback according to the results; 1. Call conn.setAutoCommit(false) to start the transaction; 2. Execute multiple SQL operations, such as INSERT and UPDATE; 3. Call conn.commit() if all operations are successful, and call conn.rollback() if an exception occurs to ensure data consistency; at the same time, try-with-resources should be used to manage resources, properly handle exceptions and close connections to avoid connection leakage; in addition, it is recommended to use connection pools and set save points to achieve partial rollback, and keep transactions as short as possible to improve performance.

DependencyInjection(DI)isadesignpatternwhereobjectsreceivedependenciesexternally,promotingloosecouplingandeasiertestingthroughconstructor,setter,orfieldinjection.2.SpringFrameworkusesannotationslike@Component,@Service,and@AutowiredwithJava-basedconfi

fixture is a function used to provide preset environment or data for tests. 1. Use the @pytest.fixture decorator to define fixture; 2. Inject fixture in parameter form in the test function; 3. Execute setup before yield, and then teardown; 4. Control scope through scope parameters, such as function, module, etc.; 5. Place the shared fixture in conftest.py to achieve cross-file sharing, thereby improving the maintainability and reusability of tests.

java.lang.OutOfMemoryError: Javaheapspace indicates insufficient heap memory, and needs to check the processing of large objects, memory leaks and heap settings, and locate and optimize the code through the heap dump analysis tool; 2. Metaspace errors are common in dynamic class generation or hot deployment due to excessive class metadata, and MaxMetaspaceSize should be restricted and class loading should be optimized; 3. Unabletocreatenewnativethread due to exhausting system thread resources, it is necessary to check the number of threads, use thread pools, and adjust the stack size; 4. GCoverheadlimitexceeded means that GC is frequent but has less recycling, and GC logs should be analyzed and optimized.

Use classes in the java.time package to replace the old Date and Calendar classes; 2. Get the current date and time through LocalDate, LocalDateTime and LocalTime; 3. Create a specific date and time using the of() method; 4. Use the plus/minus method to immutably increase and decrease the time; 5. Use ZonedDateTime and ZoneId to process the time zone; 6. Format and parse date strings through DateTimeFormatter; 7. Use Instant to be compatible with the old date types when necessary; date processing in modern Java should give priority to using java.timeAPI, which provides clear, immutable and linear

The core of mastering Advanced SpringDataJPA is to select the appropriate data access method based on the scenario and ensure performance and maintainability. 1. In custom query, @Query supports JPQL and native SQL, which is suitable for complex association and aggregation operations. It is recommended to use DTO or interface projection to perform type-safe mapping to avoid maintenance problems caused by using Object[]. 2. The paging operation needs to be implemented in combination with Pageable, but beware of N 1 query problems. You can preload the associated data through JOINFETCH or use projection to reduce entity loading, thereby improving performance. 3. For multi-condition dynamic queries, JpaSpecifica should be used
