Tag Archives: Java based

The difference between classnotfoundexception and NoClassDefFoundError

Two exceptions that are commonly encountered in Java development are ClassNotFoundException and NoClassDefFoundError.
surface seems can’t find the abnormal, but specific what difference?
As their name suggests: NoClassDefFoundError is an Error, and ClassNotFoundException is an exception.
there is a difference between errors and anomalies in Java, we can recover from abnormal program but it should not be trying to recover from errors,
that is the Exception we can use the try… The catch… If an Error occurs, we cannot resume normal execution of the program.
ClassNotFoundException:
ClassNotFoundException is usually exposed at compile time, but can also occur at run time because of Java’s reflection and dynamic loading of classes. Java supports dynamically loading classes using the Class.forName method. Passing the Class name of any Class as an argument to the method will cause the Class to be loaded into the JVM memory. If the Class is not found in the classpath, then a ClassNotFoundException is thrown at runtime.
1) Missing JAR package.
1) missing JAR package.
2) There is no shortage of JARs, dependencies conflict, and dynamic loading (especially in frameworks such as Spring/Dubbo) can also occur.
3) There is no shortage of JARs and no conflicting dependencies, but class isolation is still possible (for example, there is a custom ClassLoader during framework execution that breaks the parental delegate mechanism), as is the Tomcat container.

NoClassDefFoundError:
ClassDefFoundError is not due to missing packages or class conflicts, but rather class initialization failure.
If the JVM or ClassLoader instance tries to load a class (either through normal method calls, or by using new to create new objects), the class definition is not found. The class you are looking for exists at compile time but cannot be found at run time. The error is when you use the new operator to create a new object but cannot find the corresponding class for that object. This will result in a NoClassDefFoundError. Since the NoClassDefFoundError is caused by a JVM, you should not attempt to catch this error.
1) private member variable initialization failed.
1) private member variable initialization failed.
2) Static member variable initialization failed.
3) Static code block execution exception…

Using DOS command to run Java program

Run Java programs using the DOS command
First find the location of the program and compile the program with javac
Open the DOS window at the location of the class


A file with the same name but with the suffix.class is generated in the current directory
You need to jump the pointer back to the root directory (SRC) and run it
Note: The runtime needs to be prefixed with the package name
F:\ViC_GymSystem\src> java com.aaa.ViC_GymSystem.Test
If you need to pass an argument, you can just add the argument and separate it with a space
Encoding – unicod utf-8

Error in the project tag in the POM file of Maven project: failure to transfer

Question:
The Maven project was detected from SVN today, and the project label of the POM file after it was imported into ECLISE reported an error. The error content was very long, and the initial content was roughly Failure to Transfer…. + the version of a JAR package +…..
Solution:
Select the error report item, right-click on the item –>; Maven – & gt; Update Project, Force Updateo of Snapshots/Releases:

 
Just wait for the execution to finish, at least that’s how my error was resolved.
 
 
 

Conversion between list and string array

List is converted to a String array

 public static void main(String[] args) {
List<String> list=new ArrayList<String>();
list.add("1");
list.add("2");
System.out.println(list);
String[] strings =list.toArray(new String[list.size()]);
for (String s:strings
     ) {
    System.out.println(s);
}
}

String array converted to List

  public static void main(String[] args) {
    String[] a=new String[]{"1","2"};

        List list= Arrays.asList(a);
        System.out.println(list);
    }

Java.lang.Character . isdigit() and isletter() methods

[LeetCode] – 125. The Valid Palindrome
In this problem, I encountered a new method to determine whether a string is a letter or a number. Here’s an explanation.
Use isDigit to determine if it is a number

public static boolean isNumeric(String str){
    for (int i = str.length();--i>=0;){
    if (!Character.isDigit(str.charAt(i))){
        return false;
    }
  }
  return true;
}

Use isLetter to determine if it is a letter

public class Test{
   public static void main(String args[]){
      System.out.println( Character.isLetter('c'));
      System.out.println( Character.isLetter('5'));
   }
}

Results:

 true
 false

HTTP 400 error – bad request

HTTP 400 error – invalid request (Bad request) is sometimes reported when ajax requests background data. The invalid request indicates that the request did not enter the background service;
Reasons: 1) The field name or field type of the data submitted by the front end is inconsistent with the entity class in the background, resulting in the failure of encapsulation;
2) The data submitted from the front end to the background should be of the JSON string type, while the front end did not convert the object to the string type;
Solutions:
1) Ensure consistency by comparing field names and types
2) Use Stringify to convert the object passed in front into string data: jSON.Stringify (param);

https://www.cnblogs.com/beppezhang/p/5824986.html

Java long type error: error: integer number too large

Java Basic data Types (let’s start with Java basic data types)
A variable is a memory request to store a value. That is, when creating variables, you need to request space in memory.
The memory management system allocates storage space for variables based on their type, which can only be used to store data of that type.

Therefore, by defining different types of variables, you can store integers, decimals, or characters in memory.
The two big data types in Java:
Built-in data types refer to data types


Built-in data type
The Java language provides eight basic types. There are six numeric types (four integers, two floats), one character type, and one Boolean type.
Byte:
A byte data type is an 8-bit, signed integer represented by a binary complement; The minimum is minus 128 times minus 2 to the seventh; The maximum is 127 (2^7-1); The default value is 0; Byte is used in large arrays to save space, replacing integers because byte variables take up only a quarter of the space of an int. Example: Byte a = 100, byte B = -50.
Short:
The minimum value of a 16-bit, signed integer represented by binary complement is -32768 (-2^15). The maximum is 32767 (2^15-1); Short data types can also save as much space as a byte. A short variable is one half of the space occupied by an int variable. The default value is 0; Example: Short s = 1000, short r = -20000.
Int:
The int data type is a 32-bit, signed integer represented as a binary complement; The minimum is -2,147,483,648 (-2^31); The maximum value is 2,147,483,647 (2^ 31-1); Generally, integer variables default to int; The default value is 0; Example: int a = 100000, int B = -200000.
Long:
The long data type is a 64-bit, signed integer represented as a binary complement; The minimum value is – 9223372036854775808 (2 ^ 63); Maximum is 9223372036854775807 (2 ^ 63-1); This type is mainly used on systems that require larger integers; The default value is 0L; Example: long A = 100000L, long B = -200000l.
“L” is not case-sensitive in theory, but if written as “L”, it is easy to confuse with the number “1” and cannot be easily distinguished. So it’s better to capitalize.
Float:
The float data type is a single-precision, 32-bit, IEEE 754 compliant float; Floats save memory when storing large floating point arrays. The default value is 0.0f; Floating-point Numbers cannot be used to represent exact values, such as currency; Example: Float F1 = 234.5F.
Double:
A double data type is a double-precision, 64-bit, IEEE 754 compliant floating point; The default type of floating-point Numbers is double; Double also does not represent exact values, such as currency; The default value is 0.0d; Example: Double D1 = 123.4.
Boolean:
Boolean data types represent bits of information; There are only two values: true and false; This type is used only as a flag to record true/false cases; The default value is false; Example: Boolean One = true.
Char:
Char is a single 16-bit Unicode character; The minimum value is \u0000 (i.e., 0); The maximum value is \ UFFFF (i.e. 65,535); Char data type can store any character; Char letter = ‘A’;

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Defined in Java:
Long len = 12345678901211;
Result error:
Error: Integer Number too Large: 12345678901211
Correct writing: long len = 12345678901211L;
Reason: The L is treated as long; If you do not add it and treat it as an int, an error will be reported.
 

Sync with Gradle for project ‘XXXX‘ failed: Connection timed out: connect

using android studio synchronization project, I could not download gradle-3.5.1. Pom, after analyzing the image of aliyun every time, I failed and went to dl.google.com

of Google
The

result therefore causes the connection to time out

each time

causes this problem because HTTPS causes it, and commenting out HTTPS will solve the problem

file path to be modified: C:\Users\Administrator\.gradle\gradle.properties

systemProp.http.proxyHost=127.0.0.1
systemProp.http.proxyPort=1080
#systemProp.https.proxyHost=mirrors.opencas.ac.cn
#systemProp.https.proxyPort=80