Phase III API

Keywords: Java REST JDK Hadoop

Phase 3: API

One: What you need to focus on when looking at API s

1. Watching bags

2. Look at the explanation.

3. Look at the structure

4. Look at the method: Look at the explanation of the method, look at the modifier, then return the value, and see if the parameters and the type of parameters are needed.

The default return value of hashcode in java is the decimal address value

When equals is used to compare reference types, it compares address values

If you want to compare specific values, you need to rewrite the equals method yourself

How to rewrite:

Source - --- hashcodeAndequals method

In fact, many classes override equals methods.

Compare the basic types and compare whether the values are the same.

Compare reference types to address values

Object:

Protected Object clone () deep cloning: the effect of replicas does not affect the theme

Shallow cloning: copy is ontology, copy changes, ontology changes completely copy a new object out

Create and return a copy of this object

Boolean equals (Object obj)*** is just whether another object is "equal" to that object

Protevoid finalize ()*** When the garbage collector determines that there is no more application for this object, the object garbage collector calls this method.

Class <?> getClass ()*** Reflects that the object runs as a class.

Int hashcode ()*** returns the hash code value of the object.

String to String ()********* returns the string representation of the object.

public class Demo1 implements Cloneable{
	
	String name;
	String age;
	
	
	
	public Demo1(String name, String age) {
		super();
		this.name = name;
		this.age = age;
	}

	

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((age == null) ? 0 : age.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}


	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Demo1 other = (Demo1) obj;
		if (age == null) {
			if (other.age != null)
				return false;
		} else if (!age.equals(other.age))
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}
	


	@Override
	public String toString() {
		return "Full name=" + name + ", Age=" + age ;
	}



	public static void main(String[] args) throws CloneNotSupportedException {
		Demo1 demo1 = new Demo1("huguanyu","30");
		Demo1 demo2 = new Demo1("huguanyu","30");
		Demo1 d1 = demo1;
		
		Object obj = demo1.clone();
		Demo1 d2 = (Demo1)obj;
		
		System.out.println(demo1.name);
		System.out.println(d1.name);
		System.out.println(d2.name);
		
		String s1 = new String("helloworld");
		String s2 = "helloworld";
		
		System.out.println(demo1 == demo2);
		System.out.println(demo1.equals(demo2));
		System.out.println("----------------------------");
		System.out.println(s1 == s2);//false   
		System.out.println(s1.equals(s2));//true
		System.out.println(demo1.hashCode());
		System.out.println(demo1);
		

		
	}
}

Boolean equals (object obj) comparing character sequences of strings

Boolean equals IgnorCase (String str) compares string sequences, regardless of case

Does loolean contains (String str) contain a string?

Boolean startsWith (String str) to... Start

Boolean endWith (String str) Ending

String concat (String s) -- Adds a specified string to the end of another string

Boolean is Empty to determine whether it is empty

Int length () Gets string length

Charat (int index) calculates the character corresponding to the corner label according to the angle label

Int index of (String str) computes index values based on characters

String substring (int start) intercepts strings

String substring (int start, int end) intercepts strings from start to end

/*
 * 3.Simulate login, give three chances, and hint that there are still several chances
 *  1.Assuming that both the user name and password are admin,
 *  If the input is correct, console output: admin is welcome to log in
 *   If input error, console output: input error,
 *   You have two more opportunities (up to three)
 */
public class text10 {
public static void main(String[] args) {
	String name="admin";
	String password="admin";
	for (int i = 1; i <4; i++) {
		Scanner sc = new Scanner(System.in);
		System.out.println("Please enter your username");
		String user=sc.next();
		System.out.println("Please enter your password.");
		String password1=sc.next();
		if (name.equals(user)&&password.equals(password1)) {
			System.out.println("Welcome admin Sign in");
		}else {
			System.out.println("You also have"+(3-i)+"Secondary Opportunities");
		}
	}
	
}
}

String s = "abcJJLKjlkJLKJ89HKJhhHJ789HJ889H";
	//Classroom exercises:
	1: Traverse to get each character in the string
	2: Statistics of the occurrence of capital letters, lowercase letters and numeric characters in a string.(No other characters considered)

 */
public class Demo4 {

	public static void main(String[] args) {
		String s1 = "woaijavawofeichangaijavagun";
		System.out.println(s1.length());
		
		char ch = s1.charAt(5);
		System.out.println(ch);
		
		int i = s1.indexOf("java");
		System.out.println(i);
		
		
		System.out.println(s1.substring(5));
		System.out.println(s1);
		
		System.out.println(s1.substring(5, 10));
	}

}

/*2.The keyboard enters a string and counts the occurrence of capital letters, lowercase letters, numeric characters and other characters in the string.
 *  For example, keyboard entry: ABCDEabcd 123456! @%%^
 *  Output: ABCDEabcd 123456! @%^ There are five capital letters, four lowercase letters, six numeric characters and six other characters.
 * 
 */
public class text9 {
public static void main(String[] args) {
    String s="ABCDEabcd123456!@#$%^";
    int upper=0;
    int lower=0;
    int num=0;
    int character=0;
    System.out.println(s);
    for (int i = 0; i < s.length(); i++) {
		if (s.charAt(i)>='a'&&s.charAt(i)<='z') {
			lower++;
		}
		if (s.charAt(i)>='A'&&s.charAt(i)<='Z') {
			upper++;
		}
		if (s.charAt(i)>='0'&&s.charAt(i)<='9') {
			num++;
		}if (s.charAt(i)=='!'||s.charAt(i)=='@'||s.charAt(i)=='#'||s.charAt(i)=='$'||s.charAt(i)=='%'||s.charAt(i)=='^') {
			character++;
		}
			
		
		}			
    System.out.println("Capital letters"+lower+"Number");
    System.out.println("Have lowercase letters"+upper+"Number");
    System.out.println("There are numbers."+num+"Number");
    System.out.println("There are other symbols"+character+"Number");
}
}

package com._51doit.demo;

/*
 * 
 * 
 * 	byte[] getBytes()     Converting strings to byte arrays
	char[] toCharArray()	Converting strings to char arrays
	static String valueOf(int i)	Converting an int-type number to a String
	String toLowerCase()	Change strings to lowercase
	String toUpperCase()	Change strings to uppercase
	String concat(String str)	Splicing strings in parentheses onto the caller's body and buttocks
	
	Object This class dominates the entire java
	But only the basic type did he not rule.
	But in order to consolidate his power, the java company
	Define a reference type wrapper class for the base type
	So Object indirectly rules the basic types again.
	
	
	Classroom exercises: put one
	The first letter of the string is capitalized and the rest is lowercase. (Consider only upper and lower case letters in English)
	Write a program to change + "jdk"+all into capitals and output to the screen% intercept substring "DK"+and output to the screen

 * 
 */
public class Demo6 {
	public static void main(String[] args) {
		String ss = "hellojianguo";
		
		byte[] bytes = ss.getBytes();
		
		char[] ch = ss.toCharArray();
		
		System.out.println(bytes);
		
		for (int i = 0; i < bytes.length; i++) {
			System.out.print((char)bytes[i]);
		}
		System.out.println();
		System.out.println("===========================");
		for (int i = 0; i < ch.length; i++) {
			System.out.print(ch[i]);
		}
		System.out.println();
		System.out.println("===========================");
		
		System.out.println(String.valueOf(true));
		String sss = ss.toUpperCase();
		System.out.println(sss);
		System.out.println(sss.toLowerCase());
		
		System.out.println(ss.concat("Study hard,Make progress every day,Strive for 20 K"));
	}
	
}
Replacement function
	String replace(char old,char new)
	String replace(String old,String new)
	
	Remove header and tail spaces of strings	
	String trim() can only remove header and tail spaces
	
	Compare two strings in dictionary order  
	int compareTo(String str)   
	Subtraction is done from beginning to end, which converts characters in each position into ints and subtracts them.
	If the number of digits is different, but the previous elements are the same from the redundancy, then the return value is
	A few more returns
	int compareToIgnoreCase(String str) 
	
	cutting
	String[] split(String regex) 
    Split the string according to the matching of a given regular expression. 
 */
public class Demo8 {
	public static void main(String[] args) {
		String ss = "helloworld";
		System.out.println(ss.replace('l', 'L'));
		System.out.println(ss);
		
		System.out.println(ss.replace("world", "hadoop"));
		
		String s = "   hello   java    world   ";
		System.out.println(s.trim());
		
		
		String s1 = "huguanyu";
		String s2 = "huguanyuha";
		
		int i = s1.compareTo(s2);
		System.out.println(i);
		
		String sss = "woaijavawoshifenaijavaniaimawobuaijavagun";
		String[] sp = sss.split("java");
		
		for (int j = 0; j < sp.length; j++) {
			System.out.print(sp[j]+"	");
		}
	}
}

tringBuffer:Thread-safe variable sequence string container variable string slowness
 * StringBuilder:Thread insecurity in a variable character sequence		fast
 * String:Immutable character sequence
 * 
 * 
 * 	Adding functionality
	public StringBuffer append(String str)
	public StringBuffer insert(int offset,String str)
	//Delete function
	public StringBuffer deleteCharAt(int index)
	public StringBuffer delete(int start,int end)   Semi-open interval Baotou does not cover tail
	//Replacement function
	public StringBuffer replace(int start,int end,String str)
	//Reversal function	 
	public StringBuffer reverse()
 * 
 * Write a method to determine whether a string is symmetrical
 * 
 */
public class Demo9 {
	public static void main(String[] args) {
		StringBuffer sb = new StringBuffer("helloworld");
		System.out.println(sb);
		
		System.out.println(sb.append("javaissoeasy"));
		System.out.println(sb);
		
		System.out.println(sb.insert(0, "woshidashazi"));
		System.out.println(sb);
		
		System.out.println(sb.deleteCharAt(0));
		System.out.println(sb.delete(0, 5));
		
		System.out.println(sb.replace(0, 5, "jiaochentao"));
		
		
		System.out.println(sb.reverse());
		
		System.out.println(sb.substring(0, 10));
		System.out.println(sb);
		
		
		
//		Chain programming
		StringBuffer sb2 = new StringBuffer("a");
		System.out.println(sb2.append("b").append("c").append("d"));
		
		
	}
}	

Advanced Applications of Arrays

Selective Sorting: Outer Control Wheel, Inner Control Number

Format: for (int I = 0; I < arr. length - 1; I ++;){

for(int j=i+1;j<arr.length;j++;){

if(arr[i]>arr[j]){

int temp=arr[i];

arr[i]=arr[j];

arr[j]=temp;

}

}

}

public static void main(String[] args) {
		// This is selection sort.
		// Scanner sc=new Scanner(System.in);
		// System.out.println("Please enter an array");
		// int a=sc.nextInt();
		// int []arr={};
		int[] arr = { 89, 98, 12, 56, 99, 100, 65 };
		for (int i = 0; i < arr.length - 1; i++) {
			for (int j = 0; j < arr.length - i - 1; j++) {
				if (arr[i] > arr[j]) {
					int temp = arr[i];
					arr[i] = arr[j];
					arr[j] = temp;
					if (arr[i] < arr[j]) {
						temp = arr[i];
						arr[i] = arr[j];
						arr[j] = temp;
					}
					System.out.println(Arrays.toString(arr));
				}
			}

Bubble sort

Format: for (int I = 0; I < arr. length - 1; I ++;){

for(int j=i+1;j<arr.length-i-1;j++;){

if(arr[j]>arr[j]+1){

int temp=arr[j];

arr[j]=arr[j+1];

arr[j+1]=temp;

}

}

}

// This is bubble sort.
			int[] arr1 = { 89, 98, 12, 56, 99, 100, 65 };
			for (int i1 = 0; i1 < arr.length - 1; i1++) {
				for (int j1 = 0; j1 < arr.length - i1 - 1; j1++) {
					if (arr[j1] > arr[j1 + 1]) {
						int temp = arr[j1];
						arr[j1] = arr[j1 + 1];
						arr[j1 + 1] = temp;
					}
				}
			}
			System.out.println(Arrays.toString(arr));

Half Search: You need to define a maximum, a minimum, and an intermediate value in advance.

If the number we're looking for is larger than the median, it proves that it's useless before the median.

So let's change the minimum to the position of the median angle plus 1.

/**
	 * Binary search
	 * @param arr
	 * @param key
	 */
	public static void binarySearch(int[] arr, int key) {
		int max = arr.length -1;
		int min = 0;
		int middle = (max + min)/2;
		
		
		while (min < max) {
			if (arr[middle] == key) {
				System.out.println(middle);
				return;
			}else if (key > arr[middle]) {
				min = middle + 1;
			}else if (key < arr[middle]) {
				max = middle - 1;
			}
			middle = (min + max) / 2;
		}
		
		System.out.println("There is no such number.");
	}
	
	
	
}
/**
 * 	public static String toString(int[] a)  
	public static void sort(int[] a)   The default ascending order does not do descending order for this sort
	public static int binarySearch(int[] a,int key)  Binary search can only find ascending order   
 *
 */
public class Demo5 {
	public static void main(String[] args) {
		int[] arr = {5,10,16,78,95,100};
		
		int key = 10;
		
		ArrayUtil.binarySearch(arr,key);
		int[] arr1 = {10,9,8,7,6,5,4};
		
		System.out.println(Arrays.binarySearch(arr, 10));
		System.out.println(Arrays.binarySearch(arr1, 10));
		
		int[] arr2 = {5,6,7,4,2,3,1,97};
		Arrays.sort(arr2);
		System.out.println(Arrays.toString(arr2));
		
		
		
	}
}
/*
 * Basic types of packaging
 * Object  The ancestor of superclass and superclass
 * He ruled over all types of citations but abandoned the eight basic types.
 * Later, in order to strengthen the rule of the emperor, the basic category was upgraded to packaging category.
 * byte				Byte
 * short			Short
 * int				Integer
 * long				Long
 * float			Float
 * double			Double
 * char				Character
 * boolean			Boolean
 * 
 * Basic Type Packaging Class: Conversion between Basic Data Types and Strings
 * 
 * The eight basic types of packaging class operations are strings of basic types and basic types.
 * 
 * Construction method:
 * 	Integer(int value) 
          Construct a newly allocated Integer object that represents the specified int value. 
	Integer(String s) 
          Construct a newly allocated Integer object that represents the int value indicated by the String parameter. 
		Here String must be all numbers
 * 
 * 	JDK1.5 In the future, java provides convenience for all wrapping classes
 * 	Provides an operation called automatic unpacking.
 * 	Besides the automatic unpacking, there is also automatic packing.
 * 
 * Membership method
 * 	int Conversion of Types and String Types
	int – String: Direct addition of empty strings
	String – int: public static int parseInt(String s)

 * 
 * 
 * 	Common Basic Binary Conversion
	public static String toBinaryString(int i)   Convert to binary
	public static String toOctalString(int i)	Convert to octal
	public static String toHexString(int i)		Conversion to hexadecimal
	
	
	Decimal to other decimal   
	public static String toString(int i,int radix) Decimal to any decimal
	Minimum Binary and Maximum 36 Binary
	
	static String toString(int i) 
          Returns a String object representing the specified integer. 
	
	Other decimal to decimal systems
	public static int parseInt(String s,int radix)
	The first parameter represents the number string you want to convert.
	The second parameter is to tell the system what type of string you have in front of you belongs to.
 * 
 * 
 * 
 * 
 * 
 */
public class Demo6 {
	public static void main(String[] args) {
		
		Integer in = new Integer(10);
		System.out.println(in);
		
		Integer in1 = new Integer("123456");
		System.out.println(in1);
		
		
		
		int i =20;
		Integer integer = new Integer(i);
		
//		Why is it possible to run successfully because the auto-disassembly operation is done here?
		i = integer + i;
		System.out.println(i);
		
		
//		This is the automatic packing operation.
		Integer in2 = 100;
		
		String ss = in2 + "1234";
		System.out.println(Integer.parseInt(ss));
		
		
		
		
		String bs = Integer.toBinaryString(80);
		System.out.println(bs);
		
		String os = Integer.toOctalString(80);
		System.out.println(os);
		
		
		String ohx = Integer.toHexString(80);
		System.out.println(ohx);
		
		
		
		
		String str = Integer.toString(100, 2);
		System.out.println(str);
		
		System.out.println(Integer.toString(20));
		
		
		System.out.println(Integer.parseInt("64", 8));
		
		
	}
}
/*
 * 
 * 	Character Class overview
	Character Class wraps the value of a basic type char in an object
	In addition, this class provides several ways to determine the type of characters (lowercase letters, numbers, etc.) and convert characters from uppercase to lowercase, and vice versa.
	
	
	Construction method
	public Character(char value)
 * 
 * 
 * 	public static boolean isUpperCase(char ch)
	public static boolean isLowerCase(char ch)
	public static boolean isDigit(char ch)
	public static char toUpperCase(char ch)
	public static char toLowerCase(char ch)
 * 
 * 
 *
 */
public class Demo7 {
	public static void main(String[] args) {
		Character ch = 'A';
		
//		String s = "JKLhHKKjhkHKJHkgk*(n^*&6788)()9090JJLLJhbjkkljl";
//		Statistics of the occurrence of capital letters, lowercase letters and numeric characters in a string. (No other characters considered)

		Scanner sc = new  Scanner(System.in);
		
		System.out.println("Please enter a string");
		
		String line = sc.next();
		
		int upper = 0;
		int lower = 0;
		int num = 0;
		
		for (int i = 0; i < line.length(); i++) {
			if (Character.isUpperCase(line.charAt(i))) {
				upper++;
			}else if (Character.isLowerCase(line.charAt(i))) {
				lower++;
			}else if (Character.isDigit(line.charAt(i))) {
				num++;
			}
		}
		
		System.out.println("Capital letters are"+upper);
		System.out.println("The lowercase letters are"+lower);
		System.out.println("Numbers are"+num);
		
		
		
		
	
		 
	}
}
//		Change the initial letter of s into lowercase and the other letters into uppercase and output
public static void main(String[] args) {
	String s="Guodingding";
	String s1=s.substring(0, 1);
	String s2=s.substring(1);
StringBuffer sb	=new StringBuffer(s1.toLowerCase()).append(s2.toUpperCase());
	System.out.println(sb);
	System.out.println();
	System.out.println("=============");
	StringBuilder sb1=new StringBuilder();
	for (int i = 0; i < s.length(); i++) {
	if (i==0) {
		sb1.append(Character.toLowerCase(s.charAt(i)));
	}else {
		sb1.append(Character.toUpperCase(s.charAt(i)));
	}	
	}
	System.out.println(sb1);
}
//public BigInteger(String val)

//Public Big Integer add (Big Integer val) add
//Public Big Integer subtract (Big Integer val) subtraction
//Public Big Integer multiply (Big Integer val) multiplication
//Public Big Integer div ide (Big Integer val) Division
//Public BigInteger [] dividend AndRemainder (BigInteger val) division and redundancy

public class Demo9 {
	public static void main(String[] args) {
		BigInteger bi = new BigInteger("123456789");
		
		System.out.println(bi);
		
		System.out.println(bi.add(new BigInteger("10000000000000000")));
		System.out.println(bi.subtract(new BigInteger("10000000000000000")));
		System.out.println(bi.multiply(new BigInteger("10000000000000000")));
		System.out.println(bi.divide(new BigInteger("10000000000000000")));
		
		BigInteger[] ddr = bi.divideAndRemainder(new BigInteger("10000000000000000"));
		
		System.out.println(Arrays.toString(ddr));
	}
}
//Public Big Decimal Add (Big Decimal augend)
//Public Big Decimal Subract (Big Decimal Subrahend) Subtraction
//Public Big Decimal Multiplication
//Public Big Decimal divide (Big Decimal divisor)
//public BigDecimal divide(BigDecimal divisor,int scale, int roundingMode)


public class Demo10 {
	public static void main(String[] args) {
//		System.out.println(0.08 + 0.02);
//		System.out.println(1.0 - 0.32);
//		System.out.println(1.013 * 100);
//		System.out.println(1.201 / 100);
		
		BigDecimal bdc = new BigDecimal("1.0");
		System.out.println(bdc);
		
		BigDecimal bdc2 = new BigDecimal("0.32");
		System.out.println(bdc2);
		
		
		System.out.println(bdc.add(bdc2));
		System.out.println(bdc.subtract(bdc2));
	}
}
//public static int abs(int a)
//public static double ceil(double a) rounding up
//public static double floor(double a) downward rounding
//B power of public static double pow(double a,double b) a
//public static double random() random number 0.0 - 1.0
//Self-learning rounding with public static int round(float a) parameter double
//public static double sqrt(double a) square root
//65535 port (port number)
//Pseudo-random Number
public class Demo11 {
	public static void main(String[] args) {
		System.out.println(Math.abs(13));
		System.out.println(Math.abs(-13));
		
		System.out.println(Math.ceil(13.2));
		System.out.println(Math.ceil(-13.2));
		
		
		System.out.println(Math.floor(-13.2));
		System.out.println(Math.floor(13.2));
		
		System.out.println(Math.pow(2, 16));
		
		System.out.println(Math.random());
		
		System.out.println(Math.round(3.5));
		
		System.out.println(Math.sqrt(8));
	}
}
//Overview of System Classes
//The System class contains some useful class fields and methods. It cannot be instantiated.

//Membership method
//public static void gc()   
//		Make sure that the object you want to retrieve is null referenced before shipping the gc method
//		Garbage Recycling Mechanism   
//		finalize() garbage collector
//public static void exit(int status)
//Millisecond value of the current time of public static long current Time Millis ()
//	1566033662870
//public static void arraycopy(Object src,int srcPos,Object dest,int destPos,int length)
//First parameter: From which array to copy
//Second parameter: Copy from the index of the original array
//Third parameter: target array
//Fourth parameter: Start with the index of the target array
//Fifth parameter: how many elements are copied and pasted

public class Demo12 {
	public static void main(String[] args) {
		long c = System.currentTimeMillis();
		
		System.out.println(c);
		
		int[] arr = {1,2,3,4,6,7,8,9};
		int[] arr1 = new int[10];
		
		System.arraycopy(arr, 2, arr1, 0, 6);
		
		System.out.println(Arrays.toString(arr1));
	}
}
//August 17, 2019, 17:45.

//Overview of the Date class
//Class Date represents a specific instant, accurate to milliseconds.

//Construction method
//public Date()
//public Date(long date)

//Membership method
//public long getTime() converts the Date object to its corresponding millisecond value
//public void setTime(long time)

//SimpleDateFormat Construction Method

//public SimpleDateFormat()
//public SimpleDateFormat(String pattern)

//Membership method
//public final String format(Date date) converts a Date object to a string
//public Date parse(String source) converts strings to Date objects


public class Demo13 {
	public static void main(String[] args) throws ParseException {
		Date date = new Date();
		System.out.println(date);
		
		Date d = new Date(1566033662870l);
		System.out.println(d);
		
		
		System.out.println(date.getTime());
		date.setTime(1566033662870l);
		System.out.println(date);
		
		SimpleDateFormat sdf = new SimpleDateFormat("HH spot mm branch ss second  yyyy year MM month dd Number ");
		System.out.println(sdf);
		String time = sdf.format(date);
		System.out.println(time);
		
		
		SimpleDateFormat sdf1 = new SimpleDateFormat("HH spot mm branch ss second yyyy year MM month dd Number");
		Date da = sdf1.parse(time);
		System.out.println(da);
	}
}

Posted by kam_uoc on Sun, 18 Aug 2019 07:02:45 -0700