Home > Java > javaTutorial > body text

Set up a stall and write code live? Let's take a look at the new trendsetters in the era of street stall economy~

Release: 2023-07-26 17:45:09
forward
1498 people have browsed it

Hello everyone, I am brother node. I wonder if you have noticed recently, The street stall economy is booming! It is said that if you stand on the wind, even a pig can fly. No, you see, our brother Wu is very business-savvy, keenly aware of this wave of business opportunities, and is ready to take advantage of this opportunity to perform like a flying pig jumping over the dragon's gate.

On this day, Brother Wu drove over to see me early and was going to talk about setting up a stall together. Brother Wu is a very kind person. He never forgets to help his brothers when good things happen. It has profound meaning, but its shortcomings are also obvious, it’s too coquettish!

From afar, I saw Brother Wu with oily hair, lighting a cigarette and looking up at the sky at an angle of 45 degrees, as if he was the most charming person in the world (actually he is very flattering, and passers-by want to kick him when they see him) Two jio), I hurriedly went up to say hello.

I: (Pretending to flatter) Brother Wu, are you here? Long time no see, still so handsome!

武哥: (Turns his head to look at me, raises his eyebrows, and smiles gradually): Ouch, isn’t this little brother Node? We said goodbye last time and haven’t seen each other for many days. I really miss him! Remember that night? We were in the coffee shop, listening to romantic music, discussing life and ideals together...

Me: (Suddenly I felt a chill in my back and I shivered) Stop it, stop it! What life? What ideal? You are too ridiculous. Didn’t we learn Java data types last time? Did you forget it? 4 categories and 8 species, you also gave a few small examples. Although what you said is good, it does not mean that you can talk nonsense in broad daylight and the world is clear. Please pay attention to your status as a boss, okay?

武哥: Harmful! Just kidding~ Haha~ Seeing how anxious you are, your face is starting to turn red. (As he said that, he came closer to me)

I: (A bit square, but pretending to be calm, his aura cannot be lost) What the hell? Brother Wu, you don’t really have that kind of hobby, do you? ...

武哥: What’s your hobby?

: (a moment of disgust) Ahem...Nothing, by the way, didn't you come here to discuss setting up a street stall together? Any good ideas?

武哥: Yes! I almost forgot about business. I'm here just to discuss setting up a street stall with you. did you see it yet? Recently, the WeChat circle of friends has been circulating articles about street stalls, saying that the street stall economy is going to be popular.

: I saw it, indeed, there are many similar to this:

Set up a stall and write code live? Let's take a look at the new trendsetters in the era of street stall economy~

武哥: Haha~ This picture is so vivid, but why do I think this wig seller is a little bit murderous? Is it fashionable these days to return to nature? But I feel like this wig seller is going to be popular! As we all know, the most precious thing for a programmer is his hair. It is common for him to work overtime and stay up all night. Maybe he will have to work all night when the project is online. It was so hard, it hurt the liver, the kidneys, and the hair. They were worried when they saw the young man in his 20s turning into an old man. We can sell products on the street stalls, such as hair growth shampoo, conditioner, etc., or even a comprehensive care package. I have already thought of the title: Caring for programmers, starting from scratch! Ai, you can even get a few more boxes of Huiren Shenbao and Indian sacred oil! Do you think how many people today have family disharmony and unhappy lives because of that problem? We just want to solve the pain points of users! And they are specially sold at the entrance of the Science and Technology Park, so you will definitely make money!

I: Damn it? Brother Wu, do you want this? Could it be that you also have something to hide?

武哥: (rolled his eyes) It’s your sister! Only you have it, I’m still young! I really start from the user's needs! Give them benefits!

: Yes, there are still a lot of programmers in the science and technology park, and the daily traffic is also large. We are in urgent need of this, and maybe the supply will exceed the demand. We will take the opportunity to increase the price and make a lot of money. One stroke! Hahaha~

武哥: I seem to smell the smell of money...Haha~ I am really a business genius!

: Don’t be happy too early. We set up a stall, but there is nothing here. What are we doing? Do you have the goods? Do You have a Car? Do you know where it can be sold and where it is illegal? By then, if you break the rules and get caught, it will be over.

武哥: Oh. Too. We have to do a good job of summarizing. But you don’t have to worry too much. I heard that urban management officials now have a target to develop three street stall businesses per person.

I: Are you so naughty? Then we can rest assured! But I personally think that we should do a market research first to see what items are easy to sell, which areas are generally popular, and what the approximate proportion of daily income and expenses is. We don’t fight unprepared battles, what do you think?

武哥: You are right, let’s go and take a look first, this is not a hurry, we need to consider it in the long term.

: Yes, there are too many programmers who are half bald now, so building a related industry will definitely be popular.

武哥: Yes, start it.

...

Since then, Brother Wu and I started contacting businesses everywhere to sell goods, running around every day and living a very fulfilling life... .

After a while, we originally dreamed of getting rich, but we didn’t expect that our street stall closed down...

The reason was that Brother Wu was too coquettish and often ran over to find the street stalls passing by. My sister wants to use WeChat to hook up with girls and promote his Indian magic oil, saying that it can be applied on the body and massaged, and it will ensure that the skin is shiny and lubricated after use. The girl was so scared that she went to the consumer association to report it, and then... we are like this unemployed.

Brother Wu had no choice but to sell his car to pay off his debts and start a wandering life with me...

By chance, we saw the UP owner of a street stall live broadcasting Java. We secretly ran over and listened for a while. Damn it, it was full of useful information? We were so scared that we quickly liked and followed it to learn from the experiences of successful people.

I saw that the big guy was talking about the knowledge point of Java keywords. I recalled the scene when I first learned Java, and a feeling of hunger came in my stomach, accompanied by a gurgling sound. I did the math and realized I hadn't eaten in two days, and suddenly tears flowed down my face. If I had studied Java well, I wouldn't have ended up like this! I hate it so much!

This time, in order to prevent more people from going hungry, I decided to share the lecture notes of the boss. Don't thank me. If you want to thank me, just thank Brother Wu. It was really not easy for him. In order to get a lecture material, he had snot and tears all over his body. The boss was very desperate and had no choice but to share the useful information. Brother Wu gave up and looked as happy as A child weighing 100 pounds (only 100 pounds left)...

dry stuff

Java has a series of Keywords each have their own important uses and meanings in the code. Today I will take you to learn about Java keywords!

Java has many keywords. This article will first introduce the use of each keyword, and then focus on the three commonly used keywords final, static and this. When using other keywords, You can check it online.

Java keyword summary


Data type Meaning
abstract Indicates that the class or member method is abstract Attribute
assert Assertion, used for program debugging
boolean One of the basic data types 1. Boolean type
break Jump out of a block in advance
byte One of the basic data types 1. The byte type
case is used in the switch statement to represent one of the branches
catch Used in exception handling to catch exceptions
char One of the basic data types, character type
class Declare a class
const Reserved keyword, no specific meaning
continue Go back to the beginning of a block
default Default, for example, used in a switch statement to indicate a default branch
do Used in do-while loop structure
double One of the basic data types 1. The double-precision floating-point number type
else is used in conditional statements to indicate the branch when the condition is not true
enum Enumeration
extends Indicates that one type is a subtype of another type. Common types here include classes and interfaces
final is used to describe the final attribute, indicating that a class cannot derive subclasses, or member methods cannot be overridden, or the value of a member field cannot be changed. Used to Defining constants
finally is used to handle exceptions and declare a statement block that will basically be executed
float One of the basic data types, single-precision floating point number type
for Introduction to a loop structure
goto Reserved keywords, no specific meaning
if Guiding words for conditional statements
implements Indicates that a class implements the given interface
import Indicates that you want to access the specified class or package
instanceof Used to test whether an object is an instance object of a specified type
int Basic One of the data types, integer type
interface Interface
long One of the basic data types 1. The long integer type
native is used to declare that a method is implemented by a computer-related language (such as C/C/FORTRAN language)
new Used to create new instance objects
package Package
private An access control method: private mode
protected An access control method: protected mode
public An access control method: shared mode
return Return data from member methods
short One of the basic data types, short integer type
static Indicates that it has static attributes
strictfp is used to declare that FP_strict (single-precision or double-precision floating-point numbers) expressions follow the IEEE 754 arithmetic specification [1]
super Indicates the reference of the parent type of the current object or the construction method of the parent type
switch The guide word of the branch statement structure
synchronized Indicates that a piece of code needs to be executed synchronously
this Reference pointing to the current instance object
throw Throw an exception
throws Declare all exceptions that need to be thrown in the currently defined member method
transient Declare that no serialization is required Member fields
try Try a block that may throw an exception
void Declare that the current member method has no return value
volatile Indicates that two or more variables must change synchronously
while is used in loop structures

I don’t know if it is not listed, but I was shocked when it was listed. It turns out that there are so many keywords in Java, most of which we use in daily life, but we just don’t pay special attention to this. So most of them are familiar to everyone, and I won’t summarize some of them that are not commonly used. I will mainly summarize a few more representative keywords next.

final keyword

The final keyword in Java can be used to modify classes, methods and variables (including instance variables and local variables)

final modified class

If you use final to modify a class, the class cannot be inherited, and all members of the class cannot be inherited. Methods are implicitly defined as final methods (only use final to modify a class when you need to ensure that all methods in the class are not overridden). The member variables of the final modified class can be changed

public final class FinalClass{

 int i = 1;
    
 void test(){
  System.out.println("FinalClass:test");
 }
    
 public static void main( String[] args ){
  FinalClass ficl = new FinalClass();
    
  System.out.println("ficl.i = " + ficl.i);
  ficl.i = 2;
  System.out.println("ficl.i = " + ficl.i);
 }
}
Copy after login

final modified method

Using the final modified method can "lock" the method to prevent any inherited class from modifying the method. That is, using the final modified method, the subclass cannot rewrite (but it does not affect inheritance and overloading, that is, the subclass calls the parent class method is not affected).

final modified variables

Using the final keyword to modify variables is the most commonly used situation.

The value of a variable modified using final cannot be changed again, that is, it cannot be reassigned.

  1. 如果final修饰的变量是基本数据类型,则变量的值不可更改;
  2. 如果final修饰的变量是引用数据类型,则该变量不能再次指向其他引用(如重新指向新的对象或数组)但是该变量本身的内容可以再做修改(如数组本身的内容,或者对象的属性的修改)。

无论final修饰实例变量还是局部变量,都必须在使用前显式赋初值。

  1. Java中的实例变量系统会对其默认赋初值,但是局部变量必须先声明后赋值再使用。
  2. 虽然对于实例变量,系统会默认赋初值,但是Java仍然规定final修饰的实例变量必须显式赋初值。实例变量显式赋值的时机可以是在声明时直接赋值,也可以先声明,后在构造方法中赋值(对于含有多个构造方法,必须在每个构造方法中都显示赋值)。

我们来看个例子:

public void fun(){

 //BufferedImage src = null;//0. 声明的同时赋值
 BufferedImage src;//1. 这里不用赋初值,也不会出错
 try{
  src = ImageIO.read(new File("1.jpg"));//2.
 } catch (Exception e){
 //3. 如果出异常了就会进入这里,那么src可能无法被赋值
 }
 
 System.out.println(src.getHeight()); //4. src不一定有值,所以无法使用
}
Copy after login

如果静态变量同时被final修饰则可以将变量视为全局变量,即在整个类加载期间,其值不变。(static保证变量属于整个类,在类加载时只对其分配一次内存;final保证变量的值不被改变)

static keyword

static method is generally called a static method. Since static methods can be accessed without relying on any object, so for static methods It is said that there is no this, because it is not attached to any object. Since there is no object, there is no this.. And due to this feature, non-static member variables and non-static member methods of the class cannot be accessed in static methods, because non-static member methods/variables must rely on specific objects before they can be called.

But it should be noted that although non-static member methods and non-static member variables cannot be accessed in static methods, static member methods/variables can be accessed in non-static member methods. That said, the reverse is possible.

If you want to call a method without creating an object, you can set this method to static. The biggest function of static modified member methods is that you can use the method of "class name.method name" to call methods, which avoids the tediousness and resource consumption of new objects.

Our most common static method is the main method. As for why the main method must be static, this is because the program does not create any objects when executing the main method, so it can only be accessed through the class name.

static variable

static variable is also called a static variable. The difference between static variables and non-static variables is: Static variables are shared by all objects and have only one copy in memory. They are initialized if and only when the class is first loaded. Non-static variables are owned by objects and are initialized when the object is created. There are multiple copies, and the copies owned by each object do not affect each other.

The initialization order of static member variables is initialized in the order in which they are defined.

static 代码块

static块可以置于类中的任何地方,类中可以有多个static块。在类初次被加载的时候,会按照static块的顺序来执行每个static块,并且只会执行一次。为什么说static块可以用来优化程序性能,是因为它的特性:只会在类加载的时候执行一次。

所谓的代码块就是当我们初始化static修饰的成员时,可以将他们统一放在一个以static开始,用花括号包裹起来的块状语句中。例如:

class Person{
 private Date birthDate;
  
 public Person(Date birthDate){
  this.birthDate = birthDate;
 }
  
 boolean isBornBoomer(){
  Date startDate = Date.valueOf("1946");
  Date endDate = Date.valueOf("1964");
  return birthDate.compareTo(startDate)>=0 && birthDate.compareTo(endDate) < 0;
 }
}
Copy after login

isBornBoomer是用来这个人是否是1946-1964年出生的,而每次isBornBoomer被调用的时候,都会生成startDate和birthDate两个对象,造成了空间浪费,如果改成这样效率会更好:

class Person{
 private Date birthDate;
 private static Date startDate,endDate;
 static{
  startDate = Date.valueOf("1946");
  endDate = Date.valueOf("1964");
 }
  
 public Person(Date birthDate){
  this.birthDate = birthDate;
 }
  
 boolean isBornBoomer(){
  return birthDate.compareTo(startDate)>=0 && birthDate.compareTo(endDate) < 0;
 }
}
Copy after login

将一些只需要进行一次的初始化操作都放在static代码块中进行。

this 关键字

this代表它所在函数所属对象的引用。简单说:哪个对象在调用this所在的函数,this就代表哪个对象。this关键字主要有以下三个作用:

  1. this调用本类中的属性,也就是类中的成员变量;
  2. this调用本类中的其他方法;
  3. this调用本类中的其他构造方法,调用时要放在构造方法的首行。(this语句只能定义在构造函数的第一行,因为在初始化时须先执行)

引用成员变量

public class Person{ 
 String name; //定义成员变量name
 private void SetName(String name) { //定义一个参数(局部变量)name
  this.name=name; //将局部变量的值传递给成员变量
 }
}
Copy after login

虽然我们可以看明白这个代码的含义,但是作为Java编译器它是怎么判断的呢?到底是将形式参数name的值传递给成员变量name,还是反过来将成员变量name的值传递给形式参数name呢?也就是说,两个变量名字如果相同的话,那么Java如何判断使用哪个变量?此时this这个关键字就起到作用了。this这个关键字其代表的就是对象中的成员变量或者方法。也就是说,如果在某个变量前面加上一个this关键字,其指的就是这个对象的成员变量或者方法,而不是指成员方法的形式参数或者局部变量。

调用类的构造器方法

public class Person { 
 public Person(){ //无参构造器方法
  this(“Hello!”);
 }
 public Person(String name){ //定义一个带形式参数的构造方法
 }
}
Copy after login

在上述代码中,定义了两个构造方法,一个带参数,另一个没有带参数。在第一个没有带参数的构造方法中,使用了this(“Hello!”)这句代码,这句代码表示什么含义呢?在构造方法中使this关键字表示调用类中的构造方法。

如果一个类中有多个构造方法,因为其名字都相同,跟类名一致,那么这个this到底是调用哪个构造方法呢?其实,这跟采用其他方法引用构造方法一样,都是通过形式参数来调用构造方法的。

注意的是:利用this关键字来调用构造方法,只有在无参数构造方法中第一句使用this调用有参数的构造方法。否则的话,翻译的时候,就会有错误信息。这跟引用成员变量不同。如果引用成员变量的话,this关键字是没有位置上的限制的。

返回对象的引用

public HttpConfig url(String url) {
 urls.set(url);
 //return this就是返回当前对象的引用(就是实际调用这个方法的实例化对象)
 return this;
}
Copy after login

return this就是返回当前对象的引用(就是实际调用这个方法的实例化对象),就像我们平时使用StringBuilder一样,可以一直.append(),因为每次调用,返回的都是该对象的引用。

关于关键字,这篇文章就总结这么多,大佬的直播也刚好结束了。跟大佬互加了微信,聊了几句才知道原来大佬也是CSDN博客专家,半天才认出来武哥,毕竟武哥当初也是盛名在外,要不是搞什么神油…哎,不说了,都是泪水啊!

The above is the detailed content of Set up a stall and write code live? Let's take a look at the new trendsetters in the era of street stall economy~. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!