Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts

Saturday, 2 February 2013

Introduction to Control Statements in Java


Control statements decide flow of a program

JAVA CONTROL STATEMENTS

if, if-else, switch, nested if, switch, for, while, do-while, break, continue and return control statements


Control statements are used in programming languages to cause the flow of control to advance and branch based on changes to the state of a program. The statements inside your source files are generally executed from top to bottom, in the order that they appear. Control flow statements, however, break up the flow of execution by employing decision making, looping, and branching, enabling your program to conditionally execute particular blocks of code.
In Java, control statements can be divided under the following three categories:

Friday, 11 January 2013

Java Keywords

Keywords in Java

Java language has reserved 49 words as keywords.


Java Keywords also called a reserved word. Keywords are identifiers that Java reserves for its own use. These identifiers have built-in meanings that cannot change. Thus, programmers cannot use these identifiers for anything other than their built-in meanings. Technically, Java classifies identifiers and keywords as separate categories of tokens. Keywords are an essential part of a language definition. There are 49 reserved keywords currently defined in the Java language and they are shown in the below table.


abstract
double
int
switch
assert
else
interface
synchronized
boolean
extends
long
this
break
false
native
throw
byte
final
new
transient
case
finally
package
true
catch
float
private
try
char
for
protected
void
class
goto
public
volatile
const
if
return
while
continue
implements
short
default
import
static
do
instanceof
super


The keywords const and goto are reserved but not used. In the early days of Java,several other keywords were reserved for possible future use. 




Monday, 7 January 2013

Data Types in Java

Different Data Types used in Java

Data type defines a set of permitted values on which the legal operations can be performed.

There are two data types available in Java:

  • Primitive Data Types
  • Reference/Object Data Types

Primitive Data Types


     Primitive Data Types defines 8 simple types of data: byte, short, int, long, char, float, double, and boolean. These can be put in four groups.

Integer:

This groups include byte, short, int, and long which are for whole valued signed number. 

Floating:

This group includes float and double, which represents numbers with fractional precision. 

Characters:

This group includes char, which respresents symbls in a character set like letters and numbers. 

Boolean:

This group includes boolean, which is a special type for representing true/false.

Data Type Default Value (for fields) Size (in bits) Minimum Range Maximum Range
 byte  0 8 bits  -128  +127
 short  0 16 bits  -32768  +32767
 int  0 32 bits  -2147483648  +2147483647
 long  0L 64 bits  -9223372036854775808  +9223372036854775807
 float  0.0f 32-bit 1.40129846432481707e-45  3.40282346638528860e+38
 double  0.0d 64-bit  4.94065645841246544e-324d  1.79769313486231570e+308d
 char  '\u0000' 16-bit  0 to 65,535
 boolean  false 1- bit  NA  NA

Reference Data Types


     Reference variables are created using defined constructors of the classes. They are used to access objects. Class objects, and various type of array variables come under reference data type. Default value of any reference variable is null. These non-primitive types are often called "reference types" because they are handled "by reference"--in other words, the address of the object or array is stored in a variable, passed to methods, and so on. By comparison, primitive types are handled "by value"--the actual primitive values are stored in variables and passed to methods. The reference data types are arrays, classes and interfaces that are made and handle according to a programmer in a java program  which can hold the three kind of values as:

    • Array Type
    • class type
    • Interface Type

        Tuesday, 1 January 2013

        Introduction to Java



        An Introduction to Java Programming.


        Java is an object-oriented programming language with a built-in application programming interface (API) that can handle graphics and user interfaces and that can be used to create applications. Java is a high-level, third generation programming language, like C, FORTRAN, Perl, and many others. You can use Java to write computer applications that play games, store data or do any of the thousands of other things computer software can do. Compared to other programming languages, Java is most similar to C and C++. However, it is not mandatory to learn C or C++ to learn Java. 

        One major difference is that Java does not have pointers. However, the biggest difference is that you must write object oriented code in Java. Procedural pieces of code can only be embedded in objects. In the following we assume that the reader has some familiarity with a programming language. In particular, some familiarity with the syntax of C/C++ is useful.

        To actually execute Java programs, they developed Java interpreters that ran on various machines and under various operating systems. Thus, Java became a language that would execute on a number of systems and now has implementations for virtually all common computers and operating systems.The most string feature of Java is that it is platform-neutral language. Java is the first programming language that is not tied to any particular hardware or Operating System. Programs developed in Java can be executed anywhere on any system. 

        Java is an Object Oriented Language. It enables us not only to organize our program code into logical units called objects but also to take advantage of encapsulation, inheritance, and polymorphism.