Javascript  
 
  ScriptJava  
 
  Perl  
 
  PHP  
 
  ROR  
 
  ask us  
 

 

Applications
  1. Getting started
  2. Definitions
  3. First program
  4. Characters and Strings
  5. Object and methods
  6. Arrays and Circles
  7. Exceptions
  8. The main method
  9. Reading
  10. Writing file
  11. Vectors
  12. Stacks
  13. Map The Dictionary
  14. Lists
  15. Linked lists
  16. Collection
  17. Interfaces
  18. Scanner
  19. StringTokenizer
  20. Generics
  21. JDBC
  22. DataBase Queries
  23. JSP, The main step

Graphics

Applets
  1. Regards
  2. One Picture
  3. Calculator
  4. Random pictures
  5. Bouncing picture

Swings
  1. Buttons listeners
  2. TextFields
  3. Swing Example

JavaBeans
  1. The first step
  2. Example

Search a word:
   



© The scientific sentence. 2010

Generics and linked list
Generics: Example: fifo Linked List

/**
Generics technique in Java allows us to build one class of a 
certain type T (anytype, wrapped as <T>). This class will 
lays the role of reference to any other kind of type such as char, 
String, Integer, Double, or any other built object.
In this example, we take a linked list, the Generics Node <T> 
class will be used to build a FIFO linked list. We will have the choice 
to fill out this list by values of any type. For this program, we use 
String type.
*/


import java.io.*;
import java.util.*;


//The main class: The  Node class: ----------------

class  Node <T> {//The main class of refernece
//Two variables
public T Data;//the value of the node
public Node <T> Next;
// The node itself. This is the key of the linked list.

public Node (){//Constructor
}

public Node (T TheData){//Constructor
Data = TheData;
}

public T getData() {//To get a value
return Data;
} 

public Node<T> getNext() {//To get a node
return Next;
}

public void setData (T TheData) {//To set a value
Data = TheData;
}

public void setNext (Node<T> Next){//To set a node
//Node Next = ThisNext;
this.Next= Next; //Move on the list
}


public void showType() {
// Just a  method to test the type of the value Data
System.out.println("Type of T is " + Data.getClass().getName());
}

}//End of the class Node


// Class to use the class Node: ---------------------

public class LifoList {// A class to use the class Node


public static void main (String [] args) throws IOException {
Node ThisList = ReadData();
Display (ThisList);
}

public static Node ReadData()throws IOException {   
//Initialisation:
char TheResponse;
//=================== Change here: ========== start===
//Change String to another TYPE in 1,2,3,4

String Data;//1
Node<String> Head = null;//2
Node<String> tempo = null;//3
//======================================== end ======

do {//Using Scanner method for the inputs to fill out the list
Scanner in = new Scanner(System.in);
System.out.print("\n\tEnter a data: --> "); 

//=================== Change here: ========== start =====
//Change nextLine() in Data = in.nextLine(); 
//to nextInt(), nextLong(), nextFloat(), 
//nextDouble(), or next();

Data = in.nextLine();			
tempo = new Node<String> (Data);//4
//============================================== end =======

tempo.setNext(Head);
Head = tempo;
//Read the inputs using the above calss ReadUtilities		
TheResponse = ReadChar ("\n\tDo you want to continue ? y/n: --> ");
TheResponse = (char) ( TheResponse + 'A' - 'a');
} while(TheResponse == 'Y');

return Head;
}

static void Display (Node  ThisList){
if (ThisList != null){
System.out.println ("\n\tIn the LIFO (First In First Out) 
order, the list contains :");
System.out.println ("\n");
int rank  = 0;
while(ThisList != null){
System.out.println ("\n\t" + ++rank + ")\t" + ThisList.getData());
ThisList = ThisList.getNext();// Move on the list
}
}else
System.out.println ("The list is empty \n");
}


// Method to read keybord character:
static char ReadChar(String info) throws IOException {     
	BufferedReader TheInput = 
	new BufferedReader ( new InputStreamReader(System.in));
	System.out.print(info);
	return TheInput.readLine().charAt(0);           
	}
	
	
}//End of LifoList



  
Google
Web
ScientificSentence
 




chimie labs
|
scientific sentence
|
java
|
php
|
green cat
|
contact
|


© Scientificsentence 2009. All rights reserved.