Home Java javaTutorial Memo for beginners learning Java (1)

Memo for beginners learning Java (1)

Dec 20, 2016 pm 01:44 PM
java


Although I occasionally read some books in the past, most of them were just scratching the surface and couldn't get into the main seats. I never dared to say that I knew Java. Contact with a new technology is the same as first love, it is the first time, but the difference is that the latter usually starts out very sweet, but ends very painfully, while the former often starts out very painful, but becomes more interesting as time goes by. I can't stop. Now I'm in this very painful stage. I can't even run the simplest Helloworld. I always prompt Excepion in thread "main" java.lan.NoClassDefFoundError. I have to go online to check and search. My memory is lost. It’s not good, so search it out and save it quickly so that you are always ready.

Generally speaking, after installing the JDK, you must follow the steps to configure it before it can be compiled and run correctly
(assuming that the jdk version is 1.4.0)
1. jdk1.4.0-Installed in the root directory of a certain drive letter of your own machine, for example, it can be installed under C:jdk.
***(The c:jdk that appears below is changed to the directory where you installed JDK)***
2. If your running environment is win98, in the root directory of drive C, in the autoexec.bat file, add the following Two statements:
set Path=%PATH%;c:jdk in
set CLASSPATH=.;c:jdklibdt.jar;c:jdklib ools.jar
After saving, restart the machine and complete the installation of jdk1.4 Install.
3. If your running environment is win2000, you need to add two user variables in the "Environment Variables" of the "Advanced" option under "System" in the "Control Panel".
The name of one of the user variables is "path" and the value is ".;d:j2sdk1.4.0_01 in",
The name of the other user variable is "CLASSPATH" and the value is ".;d"j2sdk1.4.0_01libdt .jar;d:j2sdk1.4.0_01lib ools.jar", click "OK". The installation of jdk1.4.0 is completed.

As for the meaning of this, I think it should be to let the Java system compile the words What kind of support is needed when editing code (.java)? If you don’t tell it where to put this thing, it will be stupid?!

I saw Hello world finally displayed on the screen. It’s of great significance. This is the first program I’ve written in the past year! I feel like I’m in another world when I embark on the road of programming again. I can’t find my place anymore. Fortunately, I learned some about C++ and oriented I haven’t forgotten the surface of the object, so after a little trouble and familiarity with the JDK environment, the next thing will be much easier to handle, and I will feel more at ease.

Using the String class to directly define string variables is less annoying than using C Pointers, I feel much better. I am used to Object Pascal. If I go back to count * *, I will really go crazy.

The definition of array seems to be slightly different from that of C and C++. I can’t remember clearly. First, Write it down and talk about it later

int[] number=new int[5]
String[] message=new String[5]

There is only so much to explain in this part of variables. Even though I am a newbie, I know it. , people who are always obsessed with grammar like Tan Haoqiang are simply idiots: in most cases, beautiful programs do not need unnecessary embellishments at all, they just need to be neat and clear in ideas.
But for the framework of Java programs, I I just want to take a note, a simple java program seems to have a framework like this

class PRogramName
{
public static void main(String[] args)
{
file://The main body of the program
}

public static int othermethod()
{
file://other method
}
}

The entire program is in a large class. The concept of this class should be similar to the unit in pascal. Like pascal, the file name is also the same. It must be the same as the unit name - in this case, the class name. Java has very strict requirements on capitalization. I made several syntax errors because of this.
A Java program consists of one or more or many methods in such a large
In the above code, the meaning of the parameters of the defined method are:

public means that this member function is public and can be called directly by other classes

static means that the main member function is in the ProgramName class It is unique among all objects, and Java will allocate permanent storage space for it

(January 17) Regarding Static, I would like to extend it a little further. Sometimes we create a class and hope that all instances of this class share a variable. That is to say, all objects of this class only have a copy of the instance variable. Then the memory of such a static instance variable cannot be used to create instances of the class. It is allocated at the time, because everyone uses this one and does not need to be reallocated. Therefore, Java allocates permanent storage space for it.
For example:
class Block{
static int number=50
}
After this definition, all instances of the Block class, whether Block1 or Block2, access the same number. This number is called a variable of the class, not an instance Variables. In fact, static variables are also called class variables.

(January 17) Continue to go deeper. Static member functions or static variables defined with Static can be directly called through the name of the class to which they belong. Why is this possible? Because since all objects of this class use this variable, then Of course I don't need to reference it from any of the objects, but just reference it through the class name. Doesn't this make it convenient to implement some global functions and global variables? Put all global functions or global variables Defined in a static class, you can easily access all global variables and global functions directly through this class name when calling.

(January 20) You need to use
to define global variables that all programs must access. public final static

In addition, I encountered a problem that beginners often encounter
non-static variable mainframe cannot be referenced from a static context
That is, non-static variables cannot be referenced in static methods
Why?
Because we know that static methods can be used when no instance is created, and a member variable declared as non-static is an object property, which is only referenced when the object exists, so if we call it in a static method when the object does not create an instance Non-static member methods are naturally illegal, so the compiler will give errors at this time.

Simply put, static methods can be called without creating an object, while non-static methods must have an instance of the object before they can be called. Therefore It is impossible to reference a non-static method in a static method, because which object's non-static method does it refer to? The compiler cannot give an answer, because there is no object, so an error will be reported.

Finally, let's see Looking at the incisive explanation in Think in Java, I think this issue is very, very clear

2.6.3 static keyword
Usually, when we create a class, we will point out the appearance and behavior of the objects of that class. Unless you use new to create an object of that class, you don't actually get anything. Only after new is executed, the data storage space will be formally generated and the corresponding methods can be used.
But in two extraordinary situations, the above method is not useful. One situation is when you only want to use a storage area to hold a specific data - no matter how many objects are created, or even no objects are created at all. Another situation is when we need an extraordinary method that is not associated with any object of this class. In other words, even if the object is not created, a method is needed that can be called. To meet these two requirements, the static keyword can be used. Once something is made static, the data or method is not associated with any object instance of that class. So even though an object of that class has never been created, you can still call a static method, or access some static data. Before that, for non-static data and methods, we had to create an object and use that object to access the data or methods. This is because non-static data and methods must know the specific object they operate on. Of course, before formal use, since static methods do not need to create any objects, they cannot simply call other members without referencing a named object, thereby directly accessing non-static members or methods (because non-static members and methods must be associated with a specific object).

Whoops! Now we should be back to the main thing

void means that the type of the value returned by the method is empty. If it returns a specific type, the method is actually a function, otherwise it is just a process.

I don’t know if these things have lost their teeth due to old age. If you want to smash it, just smash it. And let me ask the experts. Question, why is the compilation speed of jdk so slow?

The above is the content of the memo (1) for beginners learning Java. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Java Spring Interview Questions Java Spring Interview Questions Aug 30, 2024 pm 04:29 PM

In this article, we have kept the most asked Java Spring Interview Questions with their detailed answers. So that you can crack the interview.

Break or return from Java 8 stream forEach? Break or return from Java 8 stream forEach? Feb 07, 2025 pm 12:09 PM

Java 8 introduces the Stream API, providing a powerful and expressive way to process data collections. However, a common question when using Stream is: How to break or return from a forEach operation? Traditional loops allow for early interruption or return, but Stream's forEach method does not directly support this method. This article will explain the reasons and explore alternative methods for implementing premature termination in Stream processing systems. Further reading: Java Stream API improvements Understand Stream forEach The forEach method is a terminal operation that performs one operation on each element in the Stream. Its design intention is

PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

TimeStamp to Date in Java TimeStamp to Date in Java Aug 30, 2024 pm 04:28 PM

Guide to TimeStamp to Date in Java. Here we also discuss the introduction and how to convert timestamp to date in java along with examples.

Java Program to Find the Volume of Capsule Java Program to Find the Volume of Capsule Feb 07, 2025 am 11:37 AM

Capsules are three-dimensional geometric figures, composed of a cylinder and a hemisphere at both ends. The volume of the capsule can be calculated by adding the volume of the cylinder and the volume of the hemisphere at both ends. This tutorial will discuss how to calculate the volume of a given capsule in Java using different methods. Capsule volume formula The formula for capsule volume is as follows: Capsule volume = Cylindrical volume Volume Two hemisphere volume in, r: The radius of the hemisphere. h: The height of the cylinder (excluding the hemisphere). Example 1 enter Radius = 5 units Height = 10 units Output Volume = 1570.8 cubic units explain Calculate volume using formula: Volume = π × r2 × h (4

PHP vs. Python: Understanding the Differences PHP vs. Python: Understanding the Differences Apr 11, 2025 am 12:15 AM

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

Create the Future: Java Programming for Absolute Beginners Create the Future: Java Programming for Absolute Beginners Oct 13, 2024 pm 01:32 PM

Java is a popular programming language that can be learned by both beginners and experienced developers. This tutorial starts with basic concepts and progresses through advanced topics. After installing the Java Development Kit, you can practice programming by creating a simple "Hello, World!" program. After you understand the code, use the command prompt to compile and run the program, and "Hello, World!" will be output on the console. Learning Java starts your programming journey, and as your mastery deepens, you can create more complex applications.

How to Run Your First Spring Boot Application in Spring Tool Suite? How to Run Your First Spring Boot Application in Spring Tool Suite? Feb 07, 2025 pm 12:11 PM

Spring Boot simplifies the creation of robust, scalable, and production-ready Java applications, revolutionizing Java development. Its "convention over configuration" approach, inherent to the Spring ecosystem, minimizes manual setup, allo

See all articles