Home > Java > JavaBase > My girlfriend cried and said she couldn't learn Java. That night I taught her the basics...

My girlfriend cried and said she couldn't learn Java. That night I taught her the basics...

Release: 2023-07-26 17:28:17
forward
1730 people have browsed it

Introduction 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.

My girlfriend cried and said she couldn't learn Java. That night I taught her the basics...
java program execution process


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:

My girlfriend cried and said she couldn't learn Java. That night I taught her the basics...

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:

My girlfriend cried and said she couldn't learn Java. That night I taught her the basics...


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

// 开始构思
// 1. 我们需要输出4个数,那么先定义4个变量 int a,b,c,d = 0;
// 2.获取系统用户输入的字符串,再定义一个变量接收这个字符串 Sting s;
// 3.一行字符必须拆开才能统计,所以把字符串转换成数组;
// 4.数组需要遍历,拿到数组的每个字符;
// 5.判断每个字符是什么类型,找到对应的字母、数字和空格类型就将对应类型的变量+1,没找到就按其他处理d+1;
// 6.输出每个字符的个数
Copy after login

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

My girlfriend cried and said she couldn't learn Java. That night I taught her the basics...

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

My girlfriend cried and said she couldn't learn Java. That night I taught her the basics...


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.

My girlfriend cried and said she couldn't learn Java. That night I taught her the basics...

You can download it after logging in


My girlfriend cried and said she couldn't learn Java. That night I taught her the basics...
Insert image description here


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。

环境变量配置:
右击我的电脑,选择属性,点击高级系统设置:

My girlfriend cried and said she couldn't learn Java. That night I taught her the basics...


选择环境变量:

My girlfriend cried and said she couldn't learn Java. That night I taught her the basics...
在这里插入图片描述


在系统变量里,点击新建按钮,创建JAVA_HOME目录,变量值填入你的jdk安装目录:

My girlfriend cried and said she couldn't learn Java. That night I taught her the basics...
在这里插入图片描述


然后点击Path,再点击编辑,输入Java的bin目录,格式如下:

My girlfriend cried and said she couldn't learn Java. That night I taught her the basics...
在这里插入图片描述

注意:win7的话需要找到Path,双击打开后在后面手动输入 %JAVA_HOME%/bin;

确定之后,打开cmd,输入

java -version
Copy after login

如出现下面有版本号的结果,则表示Java安装成功:

My girlfriend cried and said she couldn't learn Java. That night I taught her the basics...
在这里插入图片描述

Linux版本安装

请参考教程:Linux Java安装教程

Mac版本安装

请参考教程:Mac Java安装教程

开发工具选择

  1. notepad++ 。初入门写程序,可以用文本编辑器,对于熟悉Java语法非常有帮助。notepad++下载地址:
    https://notepad-plus-plus.org/downloads/v7.8.6/

  2. Eclispe。我刚学Java的时候用的就是Eclipse,它是完全免费,使用也比较简单。下载地址:https://www.eclipse.org/downloads/
    下面这篇教程会教你如何下载安装和使用:Eclipse 安装(Neon 版本)

  3. IDEA。IDEA是我现在用的编辑器,个人感觉非常好用,是目前开发Java最好的编辑器,非常推荐大家使用。缺点是比较吃内存,而且商用版的需要破解或者购买才能使用,不过社区版的可以免费使用,对于初学者来说足够了。下载地址:https://www.jetbrains.com/idea/

第一个Java程序

入门程序HelloWorld

新建一个txt文件

My girlfriend cried and said she couldn't learn Java. That night I taught her the basics...
HelloWorld.txt

修改后缀名变成 .java文件

My girlfriend cried and said she couldn't learn Java. That night I taught her the basics...
.java文件

HelloWorld的java程序代码如下:

public class HelloWorld{
    public static void main(String[] args) {
        // 打印一句话  "Hello World"
        System.out.println("Hello World");
    }
}
Copy after login

注意代码不要写错,然后我们开始运行一下:
在文件夹路径上输入cmd 命令

My girlfriend cried and said she couldn't learn Java. That night I taught her the basics...
cmd


打开这样的黑窗口

My girlfriend cried and said she couldn't learn Java. That night I taught her the basics...


输入下面的命令:


javac HelloWorld.java
Copy after login

正常的话,文件夹会多出来一个 HelloWorld.class 文件:

My girlfriend cried and said she couldn't learn Java. That night I taught her the basics...


然后再执行命令(注意HelloWorld 后面没有 .class)


java HelloWorld
Copy after login

我们可以看到,命令行打印了我们输出的语句 Hello World, 这就说明我们的程序是完全正确的,没有问题。是不是很简单呢,你学废了吗?

解释一下Hello World程序

这里首先我们定义了一个类,类是 “public” 公共类型的,类名为“HelloWorld”。另外,Java 中主类名必须和Java 文件名相同,也就是说,这里定义的类名是“HelloWorld”,则文件应该保存为“HelloWorld.java”。

public static void main(String[] args)
Copy after login

这一句是Java 中的主运行方法,它和 C/C++中的main()作用是一样的,就是所有的程序都从“main()”中开始执行。要执行 Java 程序,必须有一个包括主运行方法的类

System.out.println("Hello world");
Copy after login

这一句是 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!

Related labels:
source:Java学习指南
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template