Download presentation
Presentation is loading. Please wait.
Published byBlaze Dawson Modified over 9 years ago
1
JAVA 1.COMPARISON: JAVA AND C++ 2.KEYBOARD INPUT 3.OUTPUT 4.CONVERSION FROM STRING 5.OPERATORS AND EXPRESSIONS 6.DIALOG BOX – USER PROMPT January 20 2014
2
Comparison: Java and C ++ a) Java does not support operator overloading b) Java does not support multiple inheritance of classes. This is achieved using a new feature called 'interface'. c) Java does not support global variables. Every variable and method is declared within a class. d) Java does not use pointers. e) Java has replaced the destructor function with a finalize() function. f) There are no header files in Java.
3
KEYBOARD INPUT Accepting keyboard input in Java is done using a Scanner object. The Scanner class is in the package java.util nextInt() //get an int nextFloat() //get a float nextDouble() //get a double nextBoolean() //get a boolean value ( true or false ) next() //get a String ( 1 word - no space ) nextLine() //get line of String
4
OUTPUT Use the standard output object in the System class System.out Use PrintStream class methods printf() print() println() Examples : System.out.print("What is your name? "); String name = input.nextLine(); System.out.println("Hello there " + name + ", nice to meet you!"); float price = 178.34; System.out.printf("Your total is Rs %.2f\n", Price);
5
Conversions – Wrapper class Input is stored as string. To convert the String: use "wrapper" class methods in package java.lang Integer.parseInt( ) Double.parseDouble( ) Long.ParseLong( ) Float.parseFloat( )
6
MATH OPERATORS + - * / % Addition Subtraction Multiplication Division Modulus (remainder) OperatorDescription
7
RELATIONAL OPERATORS OperatorDescription = equal to ! = not equal to >greater than > = greater than or equal to <less than < = less than or equal to There are six relational (comparison) operators used in Java.
8
Assignment Operators x = y Also: x += y; is the same as x = x + y; x -= y; is the same as x = x - y; x *= y; is the same as x = x * y; x /= y; is the same as x = x / y; x %= y; is the same as x = x % y;
9
Equality : Strings The = = is NOT used with String variables. To test two String variables to see if they have equal values, s1.equals(s2) //checks for equality s1.equalsIgnoreCase(s2) //checks for equality ignoring case (upper or lower case)
10
DIALOG BOX – USER PROMPT Input using a dialog box [ JOptionPane.showInputDialog( ) ] String name; name = JOptionPane.showInputDialog("What is your name?"); Output using a dialog box [ JOptionPane.showMessageDialog( ) ] JOptionPane.showMessageDialog("Nice to meet you " + name + "!");
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.