TopBottom

Followers

Followers



Click on more
SUBSCRIBE



VIDEO

Announcement: wanna exchange links? contact me at ravikrak@yahoo.com
Showing posts with label JAVA. Show all posts
Showing posts with label JAVA. Show all posts

String Concatenation in Java

Posted by Ravi Kumar at Sunday, March 15, 2009
Share this post:
Ma.gnolia DiggIt! Del.icio.us Yahoo Furl Technorati Reddit

Strings are sequences of characters, such as "hello".
String a = ""; // an empty string
String greeting = "Hello";

Java allows you to use the + sign to join (concatenate) two strings together.
String a = "hello";
String b = "hai";
String message = a + b;
The above code makes the value of the string variable message "hellohai".

When you concatenate a string with a value that is not a string, the latter is converted to a string.
int age = 25;
String a = "hi" + age;
sets variable a to the string "hi25".

Share |

Labels:

Type conversion in Java

Posted by Ravi Kumar at Saturday, March 14, 2009
Share this post:
Ma.gnolia DiggIt! Del.icio.us Yahoo Furl Technorati Reddit

The type conversion in java of two types.
a)Automatic type conversion
b)Casting

Automatic type conversion: When one type of data is assigned to another type of variable an automatic type conversion will take place.
Conditions 1)The two types are compatible 2)The destination type is larger than the source type.
Ex:
int x=10;
byte y=2;
x=y; byte to int automatic conversion.


Casting: It is used to perform conversion between incompatible types.
Syntax: (Target_type)value
Target type specifies the desired type of convert the specified value to.
Ex:
Int i=257;
Byte b;
B=(byte)i; //now b value is 1.

Share |

Labels:

Relational Operators in Java

Posted by Ravi Kumar at Friday, March 13, 2009
Share this post:
Ma.gnolia DiggIt! Del.icio.us Yahoo Furl Technorati Reddit

In java to test for equality we can use a double equal sign, ==. For example, the
value of
5 == 8
is false.

Use a != for inequality. For example, the value of
5 != 8
is true.

Also we have the usual < (less than), > (greater than), <= (less than or equal),
and >= (greater than or equal) operators.

Share |

Labels:

Increment and Decrement Operators in JAVA

Posted by Ravi Kumar at Friday, March 6, 2009
Share this post:
Ma.gnolia DiggIt! Del.icio.us Yahoo Furl Technorati Reddit

We know that one of the most common operations with a numeric variable is to add or subtract 1. ++ adds 1 to the current value of the variable, and -- subtracts 1 from it.
There are two forms of these operators. 1)postfix 2)prefix

Postfix: Postfix form of the operator that is placed after the operand (i++).
For example, the code
int i= 12;
i++;
changes i to 13.

Prefix: The prefix form is ++i. Both prefix and postfix change the value of the variable by 1. The difference between the two only appears when they are used inside expressions. The prefix form does the addition first; the postfix form evaluates to the old value of the variable.
Example:
int m = 7;
int n = 7;
int a = 2 * ++m; // now a is 16, m is 8
int b = 2 * n++; // now b is 14, n is 8

We can not apply increment operator to numbers themselves. 8++ is not a legal statement.

Share |

Labels:

Operators in Java

Posted by Ravi Kumar at Thursday, March 5, 2009
Share this post:
Ma.gnolia DiggIt! Del.icio.us Yahoo Furl Technorati Reddit

The arithmetic operators +, –, *, / are used in Java for addition, subtraction, multiplication, and division. The / operator denotes integer division if both arguments are integers, and floating-point division otherwise.
Integer remainder (that is, the mod function) is denoted by %. For example, 17/2 is 8, 17%2 is 1, and 17.0/2 is 8.5.

Example:
int n = 5;
int a = 2 * n; // a is 10

In java x += 4; is equivalent to x = x + 4;

Share |

Labels:

Assignments and Initialization in Java

Posted by Ravi Kumar at Wednesday, March 4, 2009
Share this post:
Ma.gnolia DiggIt! Del.icio.us Yahoo Furl Technorati Reddit

After declaring a variable, we initialize a value by using assignment statement. We assign to a previously declared variable using the variable name on the left, an equal sign (=), and then some Java expression that has an appropriate value on the right.

Int Days; // this is a declaration
Days = 30; // this is an assignment

Another feature of Java is we can do both declare and initialize a variable on the same line.
Ex: Int Days = 30; // this is an initialization

In Java you can put declarations anywhere in your code.

Share |

Labels:

Variables and rules in JAVA

Posted by Ravi Kumar at Tuesday, March 3, 2009
Share this post:
Ma.gnolia DiggIt! Del.icio.us Yahoo Furl Technorati Reddit

In Java we declare a variable by placing the type first, fallowed by the name of the variable. Semicolon at the end of each declaration is necessary.

Rules for a variable name:

A variable name must begin with a letter, and must be a sequence of letters or digits.

A letter is defined as 'A'–'Z', 'a'–'z', '_', or any Unicode character that denotes a letter .

Digits are '0'–'9' and any Unicode characters that denote a digit.

Symbols like '+' or '©' cannot be used inside variable names, nor can spaces.

All characters in the name of a variable are significant and case is also significant. The length of a variable name is essentially unlimited.

Examples:

Int days;

Double salary;

Long population;

Char name;

Share |

Labels:

Data Types in Java

Posted by Ravi Kumar at Sunday, March 1, 2009
Share this post:
Ma.gnolia DiggIt! Del.icio.us Yahoo Furl Technorati Reddit

In java every variable must have a declared data type. Java defines eight simple types of data. They are
byte,short,int,long,char,float,double and boolean.

These can be put in four groups:
1.Integer: This group includes byte,short,into and long, which are for whole-valued signed numbers.
Type Storage Requirement Range

2.Floating-point numbers: This group includes float and double, which represent numbers with fractional precision.

3.Characters: This group includes char, which represents symbols in a character set, like letters and numbers.

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

Type Storage Requirement Range:
Int: 4 bytes -2,147,483,648 to 2,147,483, 647 (just over 2 billion)

Short: 2 bytes -32,768 to 32,767

Long: 8 bytes -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807

Byte: 1 byte -128 to 127

Float: 4 bytes approximately ±3.40282347E+38F (6–7 significant decimal digits)

Double: 8 bytes approximately ±1.79769313486231570E+308 (15 significant decimal digits)

Share |

Labels:

Comments in Java

Posted by Ravi Kumar at Saturday, February 28, 2009
Share this post:
Ma.gnolia DiggIt! Del.icio.us Yahoo Furl Technorati Reddit

Like comments in other languages (c,c++), java also supports comments in the program.
Comments are not shown in the executable program.

The most common method of comment in java is //. You use this for a comment that will run from the // to the end of the line.
Ex: // This is my first program


Another method is /* and */ comment. You use this for a comment that will run from /* to */.

Ex: /* This is my first program
This is another way of comment */

Share |

Labels:

Java Tools in Application Development

Posted by Ravi Kumar at Friday, February 27, 2009
Share this post:
Ma.gnolia DiggIt! Del.icio.us Yahoo Furl Technorati Reddit

The development tools are part of the Java Development Kit (JDK), and the classes are part of Java Standard Library(JSL).

They include:

Javac: javac.exe is java compiler, which translates java source code into byte code files that are later run by the java interpreter.It also checks for errors.

Java: Java.exe is the java interpreter. This program runs the byte code and displays the result of the program.

Appletviewer: Appletviewer.exe is a file used to run java applets if we are not having a java compatible browser, then we use appletviewer to run java applets.

Javadoc: Javadoc is the java document tool. It creates HTML documents for the java program.

Javah: Javah produces header files for use with other programming languages like c/c++.

Javap: Javap is a disassembler, which enables us to convert byte code files into a program description.

Jdb: Jdb is a java debugger which is used to debug our programs.

Share |

Labels:

Java Programming Environment

Posted by Ravi Kumar at Tuesday, February 24, 2009
Share this post:
Ma.gnolia DiggIt! Del.icio.us Yahoo Furl Technorati Reddit

Using The Command Line Tool:

There are two methods for running java program:
1. From the command line.
2. From another program, such as an integrated development environment or a text
editor.

From the command line.
Open a shell or terminal window. Go to the
CoreJavaBook/v1ch2/Welcome directory.

Then enter the following commands:
javac Welcome.java
java Welcome

You have just compiled and run your first Java program.
The javac program is the Java compiler. It compiles the file Welcome.java into the file Welcome.class. The java program is the Java interpreter. It interprets the
bytecodes that the compiler placed in the class file.

Share |

Labels:

Advantages Of Java

Posted by Ravi Kumar at
Share this post:
Ma.gnolia DiggIt! Del.icio.us Yahoo Furl Technorati Reddit

There are plenty of advantages in java.
Few of them are:

1. Java is fully object oriented, when comparing with C++.
2. Run time environment that provides platform independence. No problem where ever you use.
3. You can use the same code on Windows, Solaris, Linux, Macintosh.
4. Java has syntax similar to that of C++, making it easy for C and C++ programmers
5. Memory in Java is automatically garbage collected. So that, there is no chance for memory corruption.
6. Java designers eliminated pointers concept, multiple inheritance.

Share |

Labels:

Introduction To JAVA

Posted by Ravi Kumar at Monday, February 23, 2009
Share this post:
Ma.gnolia DiggIt! Del.icio.us Yahoo Furl Technorati Reddit

Java As a Programming Tool:

Java is certainly a good programming language.
It is one of the better languages available to serious programmers.
Java derives much of its characters from C and C++. This is by intent.
The java designers knew that using the familiar syntax of C and echoing
the object oriented features of C++ would make their language better.

Where did the dramatic improvements of Java come from? The answer is
that they didn't come from changes to the underlying Java programming language,
they came from major changes in the Java libraries. Over time, Sun Microsystems changed everything from the names of many of the library functions (to make them
more consistent), to how graphics works (by changing the event handling model and rewriting parts from scratch), to adding important features like printing that were not part of Java 1.0.

The internet helped catapult java to the forefront of programming, and java, in turn, has a profound effect on the internet. The reason is simple: java expands the universe of objects that can move about freely in cyberspace.

Share |

Labels: