Tag Archives: Java Study Notes

Java class file operation and exception

The File class operates on files and directories
CreateNewFile create file
Mkdir mkdirs create file
Exists to determine whether a file or folder exists
Length gets the file length
LastModified Time
GetName gets the name of the file or folder
GetPath relative path
Absolute path of getAbsoultPath

Runtime Exception
ArithmeticmeticException
Abnormal ArrayIndexOutOfBoundsException array index of crossing the line
NullPointerException NullPointerException
Type cast exception ClassCastException
Illegal parameter exception IllegalArgumentException
Index overbounds Exception IndexOfBoundsException
Checked Exceptions are non-runtime exceptions
I/O exception IOException

Java learning error information 3 — Java notes

Java common error messages and solutions

compile error

common compile error on Windows

‘javac’ is not recognized as an internal or external command, operable program or batch file.

this prompt indicates that the Windows system cannot find the compiler (compiler).

solution: (suppose the JDK installation location is C:\jdk1.7.0)

1. Include the JDK installation path on the command line;

& gt; C: \ jdk1.7.0 \ bin \ javac HelloWorldApp. Java

by default, the compiler (javac) is in the bin folder under the JDK installation path.

2. Include the JDK installation path in the Windows environment variable.

1) Start & gt; Control Panel > System > Advanced > Environment Variables;
(start > Control panel & GT; System & gt; Advanced system Setup & GT; Environment variables…) 2) add the bin PATH under the installed JDK to the PATH variable and remember to add the semicolon (;) .

PATH variable has a value of: < The end of the original PATH value & GT; ; C: \ jdk1.7.0 \ bin
After adding the PATH variable
, you can use the compiler (javac) directly from the command line without entering the PATH where the compiler is located.

Class names, “HelloWorldApp”, are only accepted if annotation processing is explicitly requested

found this prompt at compile time, indicating that the.java suffix was not added at compile time. The command to compile the Java file is Javac HelloWorldApp.java instead of Javac HelloWorldApp.

UNIX system common compile error

javac: Command not found

this prompt indicates that the compiler (javac) cannot be found for UNIX systems.

solution :(assume JDK installation location is /usr/local/jdk1.7.0)

1. Include the JDK installation path on the command line;

/usr/local/jdk1.7.0/javac HelloWorldApp. Java

is mainly where the compiler (javac) is added.
2. Modify the system PATH variable.

needs to be modified according to the Shell used, and different Shell modification methods are different.

Class name, ‘HelloWorldApp’, are only accepted if annotation processing is explicitly requested

this prompt is the same as in Windows, indicating that the filename on the command line was not added when compiling the file. Java suffix.

syntax Errors (all platforms) – Synatx Errors

the compiler displays a syntax error message when there is a typo in the program source file. The error message contains the file name of the error, line number, error type, error line code, and error code location.

as the following error message:

testing.java:14:’; ‘ expected.

System.out.println(“Input has ” + count + ” chars.”)

^

1 error

error file name: testing. Java

error line number: line 14

error message: semicolon (;) required

error line: system.out.println (“Input has “+ count +” chars.”)

error location: ^ indicates location, end of error code

error number: 1

multiple error messages are given if the compiler cannot accurately locate the error due to indenting, block scope, missing semicolon, etc.

any compilation error will indicate that the compilation was unsuccessful and the.class file will not be generated. You need to find and fix all compilation errors, and then recompile.

semantic error
In addition to checking the syntax, the
compiler also checks the underlying semantics, such as undefined variables, objects not instantiated being used directly, and so on.

runtime error

runtime error message on Windows/UNIX systems

Exception in thread “main” java.lang.NoClassDefFoundError: HellowWorldApp
An error above
indicates that the initiator program (Java) did not find a bytecode file (.class) that could be executed. By default, the Java launcher looks for the.class file that has been started in the current directory. You need to switch the current working directory to the directory containing the target.class file and execute Java HelloWorldApp again.

Could not find or load main class HelloWorldApp.class
The error message above
indicates that Java helloworldapp.class was executed. On the command line, the Java command should be followed by the required class name, not the.clAS file name. The correct execution is Java HelloWorldApp.

Exception in thread “main” java.lang.NoSuchMethodError:main
The error message above
indicates that the class being used does not contain a main function. The Java virtual machine requires that classes executed by Java commands contain a main function.

Ref: http://docs.oracle.com/javase/tutorial/getStarted/problems/index.html