Java learning notes --- use of some keywords, java learning notes ---

Source: Internet
Author: User

Java learning notes --- use of some keywords, java learning notes ---
I. instanceof: determines whether the object pointed to by a referenced type variable is an instance (or an interface, abstract class, or parent class. Usage: boolean result = object instanceof class. Ii. strictfp: used to ensure the accuracy of floating point calculation. If the strictfp keyword is not specified, the calculation result may be inaccurate. This keyword ensures that the Java compiler and runtime environment fully comply with the IEEE binary floating point Number Arithmetic standard. Usage:

public strictfp class Test{public static void testStrictfp(){float f=0.12356f;double d=0.03496421d;double sum =d+f;System.out.println(sum);}public static void main(String args[]){testStrictfp();}}


Running result: 0.15861420949932098 III. assert function: as a software debugging method, it provides several methods for checking the code correctness. Check a boolean expression. A program that runs properly must ensure that the value of this boolean expression is true. If the expression value is false, it indicates that the program is already in an incorrect state, and the system must provide warning information and release it. Usage: two expressions: assert expression1 and assert expression1: expression2
public class Test{public static void main(String args[]){assert 1+1==2;System.out.println("assert1 ok");assert 1+1==3:"assert2 faild ,exit";System.out.println("assert ok");}}


For the above Code, when the command javac Test. java and java Test are executed, the output result of the program is assert1 okassert2 OK.
When the javac Test. java and java-ea Test programs are executed, the output result is assert1 okException in thread "main" java lang. AssertionError: assert faild, exit ......

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.