Monday, July 27, 2015

Today We will start with the basics of what you have read before and what you have skipped with.

Keep in your mind the important aspects and definitions :

1. Object Oriented Programming (OOP): OOP involves representing objects in a programming language and using them. Software is organized as a collection of discrete objects.

2. Class: A class represents a group of objects of the same kinds. for example: Class of Bikes represents Hero, Honda, Mahindra, TVS, Bajaj etc. 
Object with the same attributes (name, size and structure) & behavior (Operations) are grouped into a class.

3. A class as an Object Factory: Each & every class describes an infinite set of individual objects. Therefore it can be called a factory of objects.For example: Bikes can have various objects like TVS, Bajaj, Honda, Hero, Sujuki, etc. The features and functions of the objects are described within the class.

4. Object: Everything in the real world is an Object. All objects are classified under specific classes. 
An object is an instance of a class. For example: TVS is an instance of the class Bikes, Samsung is an instance of a Class Air conditioners.

5.The Java programming language has total of 50 reserved keywords which have special meaning for the compiler and cannot be used as variable names. Following is a list of Java keywords in alphabetical order, click on an individual keyword to see its description and usage example.

abstractassertbooleanbreakbyte
casecatchcharclassconst
continuedefaultdodoubleelse
enumextendsfinalfinallyfloat
forgotoifimplementsimport
instanceofintinterfacelongnative
newpackageprivateprotectedpublic
returnshortstaticstrictfpsuper
switchsynchronizedthisthrowthrows
transienttryvoidvolatilewhile

Some noteworthy points regarding Java keywords:
    • const and goto are resevered words but not used.
    • true, false and null are literals, not keywords.
    • all keywords are in lower-case.
 The following table shows the keywords grouped by category:
Category
Keywords
Access modifiers
private, protected, public
Class, method, variable modifiers
abstract, class, extends, final, implements, 
interface, native,new, static, 
strictfp, synchronized, transient, volatile
Flow control
break, case, continue, default, do, else, 
for, if, instanceof, return,switch, while
Package control
import, package
Primitive types
boolean, byte, char, double, float, int, long, short
Error handling
assert, catch, finally, throw, throws, try
Enumeration
enum
Others
super, this, void
Unused
const, goto


6. Identifiers: Identifiers are the names of variables, methods, classes, packages and interfaces. Unlike literals they are not the things themselves, just ways of referring to them. In the HelloWorld program, HelloWorld , String , args , main and println are identifiers.

7. Literals: Java Literals are syntactic representations of boolean, character, numeric, or string data. Literals provide a means of expressing specific values in your program. For example, in the following statement, an integer variable named count is declared and assigned an integer value.

8. Types of Literals: A literal is the source code representation of a fixed value.



Literals in Java are a sequence of characters (digits, letters, and other characters) that represent constant values to be stored in variables. Java language specifies five major types of literals. Literals can be any number, text, or other information that represents a value. This means what you type is what you get. We will use literals in addition to variables in Java statement. While writing a source code as a character sequence, we can specify any value as a literal such as an integer.
They are:

  • Integer literals
  • Floating literals
  • Character literals
  • String literals
  • Boolean literals

Each of them has a type associated with it. The type describes how the values behave and how they are stored. 



Integer literals:


Integer data types consist of the following primitive data types: int,long, byte, and short. byte, int, long, and short can be expressed in decimal(base 
10), hexadecimal(base 16) or octal(base 8) number systems as well. 
 Prefix 0 is used to indicate octal and prefix 0x indicates hexadecimal when using these number systems for literals.
Examples:

int decimal = 100;
int octal = 0144;
int hexa =  0x64;

Floating-point literals:

Floating-point numbers are like real numbers in mathematics, for example, 4.13179, -0.000001. Java has two kinds of floating-point numbers: float and double. The default type when you write a floating-point literal is double, but you can designate it explicitly by appending the D (or d) suffix. However, the suffix F (or f) is appended to designate the data type of a floating-point literal as float. We can also specify a floating-point literal in scientific notation using Exponent (short E ore), for instance: the double literal 0.0314E2 is interpreted as:



0.0314 *10² (i.e 3.14).

6.5E+32 (or 6.5E32)  Double-precision floating-point literal
7D  Double-precision floating-point literal
.01f  Floating-point literal

Character literals:

char data type is a single 16-bit Unicode character. We can specify a character literal as a single printable character in a pair of single quote characters such as 'a', '#', and '3'. You must know about the ASCII character set. The ASCII character set includes 128 characters including letters, numerals, punctuation etc. Below table shows a set of these special characters.

 Escape Meaning
 \n New line
 \t Tab
 \b Backspace
 \r Carriage return
 \f Formfeed
 \\ Backslash
 \' Single quotation mark
 \" Double quotation mark
 \d Octal
 \xd Hexadecimal
 \ud Unicode character

If we want to specify a single quote, a backslash, or a non-printable character as a character literal use an escape sequence.  An escape sequence uses a special syntax to represents a character. The syntax begins with a single backslash character. You can see the below table to view the character literals use Unicode escape sequence to represent printable and non-printable characters.

 'u0041' Capital letter A
 '\u0030' Digit 0
 '\u0022' Double quote "
 '\u003b' Punctuation ;
 '\u0020' Space
 '\u0009' Horizontal Tab 

String Literals:

The set of characters in represented as String literals in Java. Always use "double quotes" for String literals. There are few methods provided in Java to combine strings, modify strings and to know whether to strings have the same values.


 "" The empty string
 "\"" A string containing
 "This is a string" A string containing 16 characters
 "This is a " + "two-line string" actually a string-valued constant expression, formed from two string literals

Null Literals


The final literal that we can use in Java programming is a Null literal. We specify the Null literal in the source code as 'null'. To reduce the number of references to an object, use null literal. The type of the null literal is always null. We typically assign null literals to object reference variables. For instance

s = null;

Boolean Literals:
The values true and false are treated as literals in Java programming. When we assign a value to a boolean variable, we can only use these two values. Unlike C, we can't presume that the value of 1 is equivalent to true and 0 is equivalent to false in Java. We have to use the values true and false to represent a Boolean value. 
Example
boolean chosen = true;

Remember that the literal true is not represented by the quotation marks around it. The Java compiler will take it as a string of characters, if its in quotation marks.

9. Operators: Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:\
           1. Arithmetic Operators
           2. Relational Operators
           3. Bitwise Operators
           4. Logical Operators
           5. Assignment Operators
           6. Misc Operators

No comments:

Post a Comment