Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
52 views

Java Commands

This document discusses key concepts in Java programming including classes, objects, methods, and instance variables. It also covers input/output methods like readString() and println() as well as operators like + for addition and string concatenation.

Uploaded by

thiruvengadam c
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views

Java Commands

This document discusses key concepts in Java programming including classes, objects, methods, and instance variables. It also covers input/output methods like readString() and println() as well as operators like + for addition and string concatenation.

Uploaded by

thiruvengadam c
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15

JAVA PROGRAMMING

BASIC
Mr.C.Thiruvengadam
Associate Professor
Det. Of ECE
Anjalai Ammal Mahalingam Engineering College
Kovilvenni
class, object, methods, and instance
variables
 When we consider a Java program, it can be defined as a collection of objects that
communicate via invoking each other's methods. Let us now briefly look into what
do class, object, methods, and instance variables mean.

  Object - Objects have states and behaviors. Example: A dog has states - color,
name, breed as well as behavior such as wagging their tail, barking, eating. An
object is an instance of a class.

  Class - A class can be defined as a template/blueprint that describes the


behavior/state that the object of its type supports.

  Methods - A method is basically a behavior. A class can contain many methods.


 It is in methods where the logics are written, data is manipulated and all the actions
are executed.

  Instance Variables - Each object has its unique set of instance variables. An object's
state is created by the values assigned to these instance variables.
 The above class contains the following methods:
  
  public static String readString ()
 o Reads and returns a string, to the end of the
line, from standard input.
  public static String readWord ()
 o Reads and returns one space-delimited word
from standard input.
  public static boolean readBoolean ()
 o Reads and returns a boolean value from
standard input. Returns false if an exception
occurs during the read.
 The above class contains the following methods:

  public static char readChar ()


 o Reads and returns a character from standard
input. Returns MIN_VALUE if an exception occurs
during the read.
  public static int readInt ()
 o Reads and returns an integer value from standard
input. Returns MIN_VALUE if an exception occurs
during the read.
  public static long readLong ()
 o Reads and returns a long integer value from
standard input. Returns MIN_VALUE if an
exception occurs during the read.
Printing
 Printing is done with System.out.print,
System.out.println, System.out.print,
System.out.printf
 The above class contains the following
methods:
 o Reads and returns a float value from
standard input. Returns NaN if an exception
occurs during the read.
  public static double readDouble ()
 o Reads and returns a double value from
standard input. Returns NaN if an exception
occurs during the read.
  public static int getErrorCount()
 o Returns the number of errors recorded since
the Keyboard class was loaded or since the last
error count reset.
 The above class contains the following
methods:
  public static void resetErrorCount (int count)
 o Resets the current error count to zero.
  public static boolean getPrintErrors ()
 o Returns a boolean indicating whether input
errors are currently printed to standard output.
  public static void setPrintErrors (boolean
flag)
 o Sets the boolean indicating whether input
errors are to be printed to standard input.
The + Operator
 Use + for addition
 If both arguments are numbers, + means addition. –
Example: double result = 2.3 + 4.5; •

 Use + for string concatenation


 If either argument is String, + means concatenation – +
is only overloaded operator (operator with multiple
meanings) in all of Java

 Examples String result1 = "Hello, " + "World"; // "Hello,


World" String result2 = "Number " + 5; // "Number 5"

You might also like