Basic Java Knowledge

Source: Internet
Author: User

Exception handling

Try{}Catch(Exception e) {}voidWork ()throwsException {}//Throw ExceptionThrow NewException ("the character entered cannot be empty!") "); classMyException1extendsException {//Custom Exception ClassesString msg =NULL;  PublicMyException1 (String m) { This. msg =m; }     PublicString toString () {return"Throw a Custom exception:" +msg; }} Public classTest { Public Static voidMain (string[] args) {inti = 10; Try{            if(I < 100) {                Throw NewMyException1 ("Input value less than 100");//Throw Exception             }        } Catch(MyException1 ex) {System.out.println (ex); //The ex.tostring () method is called           }    }}

Input stream

import Java.util.Scanner;  // Include this package Scanner in=New// New Stream object int a=in.nextint ();  // Enter int type double d=in.nextdouble ();  // Enter double type // Input String

Output

// output with wrapped lines System.out.println (a);  // can output various types of data such as int System.out.printf ("%d\n", a);  // a format similar to the C language // similar to cout // control the output of the format

Type conversions

String str= "abc"char[]  C=str.tochararray ();  // convert String to char[] Char [] c={' A ', ' B ', ' C '}; String str=new string (c);  // char[] Convert to String String s= ""; int // convert string to int Double // convert string to double
Math.Abs ();  // The absolute value function, a lot of math functions have to add math. To invoke
// control format converts numbers directly to strings
String[] Sub=s.split ("|\n");  // separates a string with some separators

Open array

Double [] a=newdouble// two-dimensional double int[] b=newint//  int type string[] s=new//String int//  more than a multi-dimensional c like a few []

Basic Java Knowledge

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.