Java Road (1) ---- Help you complete HelloWorld

zhaozj2021-02-16  50

Java Road ---- Help you complete HelloWorld

In the eyes of 9CBS, it has been full of moon. Seeing a lot of java's friends about the wrong tips of NoclassDeffounderror ......... I have been able to get into the head of this depressed problem when I am a beginner. Many problems will not be There are talks in the textbook, because the textbook does not capture our "exception" :). So I finalized the questions I have ever seen, I hope to help the later people.

1. System Environment Variable Settings (JDK) in Java Development:

Workers must be good, than the prostitute. Environmental variables are all, everyone must have to pass, the following is the environment setting in various operating systems.

Win2000 / WinXP:

Right click My Computer à Attribute à Advanced à Environmental Variables

Classpath = .; JDK installation / lib

PATH = JDK installation directory / bin

Note: You must not ignore ".", He said that our current work catalog, without him, there will be a lot of trouble.

WinME:

"Start à Program à Accessories à System Tools à System Information", choose Tool à System Configuration Utility à Environment

set up:

Classpath = .; JDK installation / lib

PATH = JDK installation directory / bin

Win98:

Modifying AutoCexe.bat is to modify the automatic batch file.

Add to:

Set classpath = .; JDK installation / lib

SET PATH = JDK installation directory / bin;% PATH%

Linux:

Suppose JDK is installed under /Home/jdk1.4.0/, open / etc / profile, where to join:

Path = "/ home / jdk1.4.0 / bin: $ PATH"

Classpath =.: / Home / jdk1.4.0 / jre / lib / rt.jar: /Home/jdk1.4.0/lib/tools.jar

Java_home = / home / jdk1.4.0

Export Path ClassPath Java_Home

2. After setting our work environment, let's take a look at our HelloWorld program.

Public class helloworld {

Public void helloworld () {

//Constructor

}

Public static void main (string args [])

{

System.out.println ("HelloWorld!");

}

}

There are three mistakes above, is it? Don't laugh, this error does happen. Below is the code that corrects it:

Public class helloworld {

Public helloworld () {

//Constructor

}

Public static void main (string args [])

{

System.out.println ("HelloWorld!");

}

}

Class and System's big lowercase, although this problem generally does not appear, the case is really worthy of attention in the entire Java world, so I wrote it out, I will wake up, as long as you don't use it for this The error is expensive, and it is great to think that I am just smiling for you. The constructor is originally available for HelloWorld, but I intend to add this constructor, there are two reasons: first, the constructor has not returned, everyone knows, even if it is a matter of beginners. , 1 1 = 2, still take it out. But there are still many beginners will return a void. Void is also a return value. This concept is my first purpose. Some beginners will think that Void is not returned, wrong! ! ! Second, you should write a default constructor for your class, even if he doesn't do anything, only the same role as the default constructor gives you. When you don't write a default constructor, the system will give you one, but the premise is that there is no constructor in this class. Ignore this problem may make your inheritance system problems. (Maybe these are too early, so the textbook will not be said, but these things always remember, so as not to carry the big finger.). (By the way, the constructor can also be protected and private, not necessarily public, don't blame me mushroom ^^. There are still many people think that the constructor must be Public, wrong !!!). 3 The program is no problem, the environment variable is no problem, or there will be a problem :) Look at our execution should pay attention to what?

Do not compile with bags:

Javac class name. Java

Java class name

Compilation without a bag As long as you pay attention, you should generally don't have problems.

Javac HelloWorld.java Don't write into Javac HelloWorld.java

Java HelloWorld Don't write to Java HelloWorld.class

In addition, in general, the catalog of everyone and HelloWorld.java are the same, this is the role of the first environment variable ".".

Compile with bag:

The parent catalog class name for Javac -d package .java

Java package name. Classification

It should be noted here that everyone's working directory is the same as the directory where the parent directory is located.

There is another problem, let's take a look at the problem (although it is not big with the HelloWorld relationship, the problem is also representative)

My package is as follows:

Package C05;

Public class packagedclass {

Public packagedclass () {

System.out.println ("Creating a packaged class);

}

Public static void main (string [] args) {}

}

The procedure is as follows:

// package c05;

Import c05.pagedclass; // If you change to Import C05. *;

Public class foreign {

Public static void main (String [] args) {

PackagedClass PC = New packagedClass ();

}

}

PackagedClass is not a c05 childbag, it is a class, why don't you use *?

This is a question in the forum. Very depressed :)

Here is the type and c05.packagedclass; the class and c05.packagedclass; in the same directory, the above problem will appear, the two classes don't let go, Hach, everyone solved themselves ^^. Hope this Article will have a beginner

Help, if you have encountered questions about "HelloWorld" here, I also hope that help quickly fill :).

By smiles bluesmile979@hotmail.com

转载请注明原文地址:https://www.9cbs.com/read-25227.html

New Post(0)