JNCs - PowerPoint PPT Presentation

1 / 9
About This Presentation
Title:

JNCs

Description:

q = x.floatValue( ) converts x to a floating point ... greeting.toLowerCase( ) and greeting.toUpperCase( ) convert the string for you ... – PowerPoint PPT presentation

Number of Views:91
Avg rating:3.0/5.0
Slides: 10
Provided by: cseBu
Category:

less

Transcript and Presenter's Notes

Title: JNCs


1
JNCs
  • Java Native Classes can be declared as local
  • String userInput
  • String has methods userInput.equalTo( )
  • Integer myInt
  • myInt.parseInt( )
  • Exception e
  • Exception is a class with methods and
    variables - they can be accessed as e.methodName

2
Java Native Classes
  • Classes that are so useful, that Java now
    includes them with the language.
  • String is a JNC (thats why its capitalized).
  • Why a JNC instead of just using a type?
  • Because of the methods available with the JNC.

3
String as a JNC
  • methods valueOf( ), equals( ), compareTo( )
  • many many more methods that can be used.
  • Use like this
  • String userInput // userInput now has
    methods
  • if (userInput exit)
  • ..
  • if ( userInput.equals(exit) true )
  • System.exit(0)

4
JNC Declarations
  • Integer, Strings, and Double have JNC equivalents
  • Integer x is the same as
  • Integer x new Integer( )
  • String greeting is the same as
  • String greeting new String( )
  • Double y is the same as
  • Double y new Double( )

5
But
  • x, greeting, and y now have methods they can
    draw on
  • Integer x
  • int z
  • Double y
  • double q
  • q x.floatValue( ) converts x to a floating
    point
  • userInput x.toString( ) converts x to a String
  • y.intValue( ) truncates y to an int
  • y.toString( ) creates a String from y

6
But
  • x, greeting, and y now have methods they can
    draw on
  • String greeting
  • greeting.equals( anotherString ) yields a boolean
    result
  • greeting.length( ) yields an integer that
    reflects how many characters in the string
  • greeting.toLowerCase( ) and greeting.toUpperCase(
    ) convert the string for you

7
other Java Native Classes
  • Math some of the methods included in this class
    are sin, cos, exp, log, max, min, random, sqrt
    and tan.
  • Exception methods in this class help with
    computer errors during run time.
  • ActionEvent
  • Graphics

8
Change input to lowercase
  • makes true, True, TrUe, TRUE, tRuE, all the same
    true
  • String myString
  • myString stringToConvert.toLowerCase( )

9
String JNCs methods
  • String greeting Hello
  • String nextGreeting
  • boolean test
  • int x
  • test greeting.equals( hello )
  • x greeting.length( )
  • nextGreeting greeting.toLowerCase( )
  • nextGreeting greeting.toUpperCase( )
  • nextGreeting greeting.substring( 2, 4 )
Write a Comment
User Comments (0)
About PowerShow.com