Java Programing laungage

Core Java Tutorial

Introduction of Core Java

How To Install JDk and Set of Path

Syntax of java Program

Difference between Java and C/C++

Advantage and Disadvantage of Java

What is Java

Why Java is not Pure Object Oriented Language

Java has Following Features/Characteristics

Limitation of Java Language and Java Internet

Common Misconception about Java

Simple Program of Java

Integrated Development Environment in java

Compile and Run Java Program

Applet and Comments in Java

Tokens in Java

Keywords in Java

Identifier and Variables in Java

Literals/Constants

Data Type in Java

Assignments and Initialization in Java

Operators in Java

Rule of Precedence in Java

Operator on Integer and Separators in Java Programming

Java Control Flow of Statements

If and If-else Selection Statement

Nested If-else and If-else-If Selection Statement

switch case and conditional operator Selection Statement

for and while Loop

do..while and for each Loop

break and labeled break statement

continue and labeled continue statement

return Statement and exit() Method

Escape Sequence for Special Characters and Unicode Code

Constants and Block or Scope

Statement in Java

Conversions between Numeric Types in Java

Import Statement in Java

User Input in Java using Scanner Class

User Input in Java using Console Class

Array in Java

One Dimensional Array

Two Dimensional Array

Two Dimensional Array Program

Command Line Argument in Java

String args Types in Java

Uneven/Jagged array in java

Math Class Function and Constant

Math Class all Function used in a program

Enumerated Types in Java

Object Oriented Programming v/s Procedural Programming

Object Oriented Programming Concepts in Java

Introduction to Class,Object and Method in Java

Class Declaration in Java

Class & Objects in java

Encapsulation in Java

Modifiers/Visibility for a Class or Interrface or member of a Class

Polymorphism in Java

Runtime polymorphism (dynamic binding or method overriding)

A program contains trim(), getChar() ,setlength(),append() method

used trim() method ,used GetChar() method ,used setlength() method, used append() method

Previous Home Next

example

//following Program using trim(), GetChar(), setlength(), append().
package r4r.co.in;
public class NewClass {
public static void main(String[] args) {
StringBuffer s1 = new StringBuffer("Increament in StringBuffer  ..");
System.out.println("Output= " + s1 + "\nLength of String = " + s1.length()
	//String Concatenation 
+ "\ncapacity of String = " + s1.capacity());
String s3 = "Increament in StringBuffer     ".trim();    
//whitespace is Trim
System.out.print(s3 + "\nNew Length of String after Trime:" + s3.length());
System.out.print("\nValue at position 8  = " + s1.charAt(8));    
//GetChar at position
s1.setCharAt(8, 't');
System.out.println("\nNewChar at position 8  = " + s1.charAt(8));
//Char change at position
s1.setLength(6); //GetChar length
System.out.println("String value upto position 8 = " + s1);
int s2 = 52;    //capacity increase
String s = s1.append("\nNew Capacity s2 = ").append(s2).append("!").toString();
System.out.println(s);
    }
}

Output:

	  Output= Increament in StringBuffer  ..
      Length of String = 30
      capacity of String = 46
      Increament in StringBuffer
      New Length of String after Trime:26
      Value at position 8  = n
      NewChar at position 8  = t
      String value upto position 8 = Increa
      Increa New Capacity s2 = 52!
Program to Shorting of an Array in String
// Program to sorting an Array in Strings.
package r4r.co.in;
public class NewClass {
static String arr[] = {
 "That", "Happen", "This", "Clock", "Ticking",
"Evil", "Habbit", "Java", "Skype", "Bb",
 "Ca", "Too", "Gone", "Send", "Message", "Add", 
 "Of", "Where", "country", "Addidas", "Nike", "Aa"};
    public static void main(String[] args) {
        {
            //Shortion of an Array in Increasing order
            System.out.println("Array in Increasing order:");
            for (int j = 0; j < arr.length; j++) {
                for (int i = j + 1; i < arr.length; i++) {
                    if (arr[i].compareTo(arr[j]) < 0) {
                        String t = arr[j];
                        arr[j] = arr[i];
                        arr[i] = t;
                    }
                }
                System.out.println(arr[j]);
            }
        }
        {
            //Shortion of an Array in Decreasing order
            System.out.println("\nArray in Decreasing order");
            for (int j = arr.length - 1; j > 0; j--) {
                for (int i = j - 1; i < arr.length; i++) {
                    if (arr[i].compareTo(arr[j]) < 0) {
                        String t = arr[j];
                        arr[j] = arr[i];
                        arr[i] = t;
                    }
                }
                System.out.println(arr[j]);
            }
        }
    }
}

Output:

Array in Increasing order:
Aa
Add
Addidas
Bb
Ca
Clock
Evil
Gone
Habbit
Happen
Java
Message
Nike
Of
Send
Skype
That
This
Ticking
Too
Where
country

Array 
in Decreasing order
Where
Too
Ticking
This
That
Skype
Send
Of
Nike
Message
Java
Happen
Habbit
Gone
Evil
Clock
Ca
Bb
Addidas
Add
Aa
Previous Home Next