Java Development Common Classes

Source: Internet
Author: User

Object class: Superclass, parent class for all classes
Equals (String str): Used to compare whether two objects (strings) are equal
ToString (): Returning a string
System classes: Systems classes
Out: Output
In: Receive keyboard input
Exit (): Stop program
Currenttimemillis (): Returns the current time in milliseconds
Math class: Algorithm class
Ceil (double D): Zero integer After the decimal point, not zero-rounding
Double d = 212.9;
Math.ceil (d);---->213;
Double D2 = 212.1;
Math.ceil (D2);--->213
Floor (double D): Rounding down
Double d = 212.9;
Math.floor (d);---->212;
Double D2 = 212.1;
Math.floor (D2);--->212;
Round (Double R): rounding
Double d = 212.9;
Math.Round (d);---->213;
Double D2 = 212.1;
Math.Round (D2);--->212;
Max (double d,double D2): Returns the maximum value of two values
Min (Double d,double D2): Returns the minimum value of two values
Random (): Generating random numbers between 0.0--1.0
Date Class: Time action Class (Java.util.Date)
Date date = new Date ();//Get current time
Date date = new Date (int year, int month, int day);//Create a specified date
Note: The year Y is represented by an integer y-1900.
The month is represented by an integer from 0 to 11, 0 is a month, 1 is February, etc., so 11 is December.

System.out.println ("Year:" + (Date.getyear () +1900));
System.out.println ("Month:" + (Date.getmonth () +1));
System.out.println ("Date:" +date.getdate ());
System.out.println ("When:" +date.gethours ());
System.out.println ("min:" +date.getminutes ());
System.out.println ("SEC:" +date.getseconds ());
System.out.println ("Week:" +date.getday ());

  Time Format: DateFormat
  dateformat df = dateformat.getdateinstance (constant value);
  Time format: SimpleDateFormat
  simpledateformat sdf = new SimpleDateFormat ();
   non-parametric formatting: generated format:   14-9-30 morning 10:18
  simpledateformat sdf = new SimpleDateFormat ("Yyyy-mm-dd");
   Parameter formatting: The generated format is the form specified by the parameter

   generally use SimpleDateFormat to create an object using its parent class
  dateformat df = new SimpleDateFormat ();
  Calendar abstract class (Calendar)
   The first instantiation method:
  calendar cal = Calendar.getinstance ();//Get instance method of calender
  
   Second instantiation mode:
  calendar cal2=new GregorianCalendar ();
   System.out.println ("Year:" +cal.get (Calendar.year));//Get Year
  system.out.println ("Month:" + (Cal.get ( Calendar.month) +1));
  system.out.println ("Day:" +cal.get (calendar.date));
  system.out.println ("When:" +cal.get (Calendar.hour_of_day));
  system.out.println ("Cent:" +cal.get (Calendar.minute));
  system.out.println ("Seconds:" +cal.get (Calendar.second));
  system.out.println ("Week:" + (Cal.get (Calendar.day_of_week)-1));

Note: Get month: plus 1
Week: minus 1;
Random: Classes that generate random numbers
Instantiated:
Random rd = new Random ();
Generate integer random number: 1.rd.nextint ();
2.rd.nextint (int d);
The second, which is used to generate a random number of the specified size, between the specified number of 0--, excluding the specified number
Generate double random number (between 0.0--1.0): Rd.nextdouble ();
Equivalent to: Math.random ();

Object
System
Math
Date
SimpleDateFormat
Calendar
Random

String: String manipulation class
 1.length (): To find the length of the string: Here is the method, and the array length is the property
 2.startswith (String val To determine whether the string starts with Val, returns True No returns False
 3.endswith (string val); Determines whether the string ends in Val, and returns True No returns False
 4.charat (int index): Searches for subscript content in a string based on index value, cannot be negative, and cannot exceed string length
 5.indexof (character): Returns the subscript position for the first occurrence of this character in a string, and does not return-1
 6. IndexOf (String): Returns the subscript position for the first occurrence of this substring in the string, and does not return-1
 7.lastindexof (): Returns the subscript for the first occurrence of this character in the string from the back, and does not return-1
 8. subString (int index): intercepts a string (starting from index subscript to end)
 9.substring (int beginindex,int endindex): Intercepts a string (from beginindex subscript to Endindex end (excluding endindex subscript))
 10.concat (String str): to concatenate str into the specified string to generate a new

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.