class Link {
public int data1;
public double data2;
public Link nextLink;
//Link constructor
public Link(int d1, double d2) {
data1 = d1;
data2 = d2;
}
//Print Link data
public void printLink() {
System.out.print("{" + data1 + ", " + data2 + "} ");
}
}
class LinkList {
private Link first;
//LinkList constructor
public LinkList() {
first = null;
}
//Returns true if list is empty
public boolean isEmpty() {
return first == null;
}
//Inserts a new Link at the first of the list
public void insert(int d1, double d2) {
Link link = new Link(d1, d2);
link.nextLink = first;
first = link;
}
//Deletes the link at the first of the list
public Link delete() {
Link temp = first;
first = first.nextLink;
return temp;
}
//Prints list data
public void printList() {
Link currentLink = first;
System.out.print("List: ");
while(currentLink != null) {
currentLink.printLink();
currentLink = currentLink.nextLink;
}
System.out.println("");
}
}
class LinkListTest {
public static void main(String[] args) {
LinkList list = new LinkList();
list.insert(1, 1.01);
list.insert(2, 2.02);
list.insert(3, 3.03);
list.insert(4, 4.04);
list.insert(5, 5.05);
list.printList();
while(!list.isEmpty()) {
Link deletedLink = list.delete();
System.out.print("deleted: ");
deletedLink.printLink();
System.out.println("");
}
list.printList();
}
}
Monday, April 29, 2013
Thursday, April 25, 2013
Best Java IDE
NetBeans and Eclipse
NetBeans &Eclipse are certainly the two best free IDEs for Java. NetBeans is still slightly more Java-centric, even though it has been adding features for other languages lately. Eclipse has been doing this for years. I like the GUI editor that ships built in to NetBeans (Eclipse has one available as a plug-in), but other than that the two have a very similar feature set for Java development. |
What is Java Design Pattern ?
What is Java Design Pattern ?
“Design patterns are recurring solutions to design problems.”
Patterns: According to commonly known practices, there are 23 design patterns in Java. These patterns are grouped under three heads:
1. Creational Patterns
2. Structural Patterns
3. Behavioral Patterns
Adopt Adapter
Software usually consists of a mixture of in-house and purchased software that must work together to produce a seamless user interface. But disparate software packages are not aware of each other's object models, so they can't work together—without adapters. Adapters let objects from unrelated software packages collaborate by adapting one interface to another. Learn how the Adapter design pattern can save you a lot of time and effort by combining disparate software systems.
David Geary, September 2003
Follow the Chain of Responsibility
The Chain of Responsibility (CoR) pattern decouples the sender and receiver of a request by interposing a chain of objects between them. In this installment of Java Design Patterns, David Geary discusses the CoR pattern and two implementations of that pattern in the Java APIs—one from client-side Java and the other from server-side Java.
David Geary, August 2003
Make your apps fly
Allocating numerous objects can be detrimental to your application's performance. In this installment of Java Design Patterns, David Geary shows you how to implement the Flyweight design pattern to greatly reduce the number of objects your application creates, which decreases your application's memory footprint and increases performance.
David Geary, July 2003
Façade clears complexity
The Façade design pattern simplifies complex APIs by providing a simplified interface to a complex subsystem. In this installment of Java Design Patterns, David Geary explores a built-in Swing façade for creating dialog boxes and a custom façade for getting a Swing application off the ground.
David Geary, May 2003
Simply Singleton
The Singleton pattern is deceptively simple, even and especially for Java developers. In this classic JavaWorld article, David Geary demonstrates how Java developers implement singletons, with code examples for multithreading, classloaders, and serialization. He concludes with a look at implementing singleton registries in order to specify singletons at runtime.
David Geary, April 2003
An inside view of Observer
The Observer pattern lets you build extensible software with pluggable objects by allowing communication between loosely coupled objects. In his latest Java Design Patterns column, David Geary explores the Observer pattern, how it's used throughout the Java 2 SDK, and how you can implement the pattern in your own code.
David Geary, March 2003
A look at the Composite design pattern
The Composite design pattern lets you treat primitive and composite objects exactly the same. In his latest Java Design Patterns column, David Geary explores how to implement the Composite pattern and how to use it with the Tiles tag library from the Apache Struts application framework.
David Geary, September 2002
Take command of your software
The Command pattern lets an application framework make requests of application-specific objects, without the framework knowing the objects' exact type or the application-specific behavior they implement. In his latest Java Design Patterns column, David Geary explores how to use the Command pattern both in client-side Java to attach application-specific behavior to Swing menu items and in server-side Java to implement application-specific behavior with the Apache Struts application framework.
David Geary, June 2002
Strategy for success
The Strategy design pattern embodies two fundamental tenets of object-oriented (OO) design: encapsulate the concept that varies and program to an interface, not an implementation. In this article, David Geary shows how to use the Strategy pattern to implement an extensible design.
David Geary, April 2002
Take control with the Proxy design pattern
The Proxy design pattern lets you substitute a proxy for an object. In that capacity, proxies prove useful in many situations, ranging from Web services to Swing icons. In this latest Java Design Patterns installment, David Geary explores the Proxy pattern.
David Geary, February 2002
Amaze your developer friends with design patterns
Design patterns are proven techniques for implementing robust, malleable, reusable, and extensible object-oriented software. To launch his Java Design Patterns column, David Geary introduces design patterns to Java developers and explores Strategy, Composite, and Decorator -- three common, yet powerful, design patterns employed throughout the JDK.
David Geary, October 2001
“Design patterns are recurring solutions to design problems.”
Patterns: According to commonly known practices, there are 23 design patterns in Java. These patterns are grouped under three heads:
1. Creational Patterns
2. Structural Patterns
3. Behavioral Patterns
Java Design Patterns
Software usually consists of a mixture of in-house and purchased software that must work together to produce a seamless user interface. But disparate software packages are not aware of each other's object models, so they can't work together—without adapters. Adapters let objects from unrelated software packages collaborate by adapting one interface to another. Learn how the Adapter design pattern can save you a lot of time and effort by combining disparate software systems.
David Geary, September 2003
Follow the Chain of Responsibility
The Chain of Responsibility (CoR) pattern decouples the sender and receiver of a request by interposing a chain of objects between them. In this installment of Java Design Patterns, David Geary discusses the CoR pattern and two implementations of that pattern in the Java APIs—one from client-side Java and the other from server-side Java.
David Geary, August 2003
Make your apps fly
Allocating numerous objects can be detrimental to your application's performance. In this installment of Java Design Patterns, David Geary shows you how to implement the Flyweight design pattern to greatly reduce the number of objects your application creates, which decreases your application's memory footprint and increases performance.
David Geary, July 2003
Façade clears complexity
The Façade design pattern simplifies complex APIs by providing a simplified interface to a complex subsystem. In this installment of Java Design Patterns, David Geary explores a built-in Swing façade for creating dialog boxes and a custom façade for getting a Swing application off the ground.
David Geary, May 2003
Simply Singleton
The Singleton pattern is deceptively simple, even and especially for Java developers. In this classic JavaWorld article, David Geary demonstrates how Java developers implement singletons, with code examples for multithreading, classloaders, and serialization. He concludes with a look at implementing singleton registries in order to specify singletons at runtime.
David Geary, April 2003
An inside view of Observer
The Observer pattern lets you build extensible software with pluggable objects by allowing communication between loosely coupled objects. In his latest Java Design Patterns column, David Geary explores the Observer pattern, how it's used throughout the Java 2 SDK, and how you can implement the pattern in your own code.
David Geary, March 2003
A look at the Composite design pattern
The Composite design pattern lets you treat primitive and composite objects exactly the same. In his latest Java Design Patterns column, David Geary explores how to implement the Composite pattern and how to use it with the Tiles tag library from the Apache Struts application framework.
David Geary, September 2002
Take command of your software
The Command pattern lets an application framework make requests of application-specific objects, without the framework knowing the objects' exact type or the application-specific behavior they implement. In his latest Java Design Patterns column, David Geary explores how to use the Command pattern both in client-side Java to attach application-specific behavior to Swing menu items and in server-side Java to implement application-specific behavior with the Apache Struts application framework.
David Geary, June 2002
Strategy for success
The Strategy design pattern embodies two fundamental tenets of object-oriented (OO) design: encapsulate the concept that varies and program to an interface, not an implementation. In this article, David Geary shows how to use the Strategy pattern to implement an extensible design.
David Geary, April 2002
Take control with the Proxy design pattern
The Proxy design pattern lets you substitute a proxy for an object. In that capacity, proxies prove useful in many situations, ranging from Web services to Swing icons. In this latest Java Design Patterns installment, David Geary explores the Proxy pattern.
David Geary, February 2002
Amaze your developer friends with design patterns
Design patterns are proven techniques for implementing robust, malleable, reusable, and extensible object-oriented software. To launch his Java Design Patterns column, David Geary introduces design patterns to Java developers and explores Strategy, Composite, and Decorator -- three common, yet powerful, design patterns employed throughout the JDK.
David Geary, October 2001
How to Install Eclipse for Developing software using Java ?
How to Install Eclipse for Developing software using Java ?
Prerequiement of Eclipse.
JDK (Java development kit ) must installed in your pc. you can download jdk from following link
Download Jdk.
After this You can Install Eclipse.
Step 1. Download Eclips from Link http://www.eclipse.org/downloads/.
Step 2. Extract Eclipse Folder in Drive path eg c:\eclipse.
Step 3. Open Eclipse Folder.
Step 4. Double click on eclipse.exe.
Step 5. Now you can use Eclipse.
Prerequiement of Eclipse.
JDK (Java development kit ) must installed in your pc. you can download jdk from following link
Download Jdk.
After this You can Install Eclipse.
Step 1. Download Eclips from Link http://www.eclipse.org/downloads/.
Step 2. Extract Eclipse Folder in Drive path eg c:\eclipse.
Step 3. Open Eclipse Folder.
Step 4. Double click on eclipse.exe.
Step 5. Now you can use Eclipse.
Saturday, April 13, 2013
5 Best Core Java Books for Developer
5 Best Core Java Books for Developer
1) Thinking in Java: By: Bruce Eckel
Thinking in Java is a great book. This award-winning book by Bruce Eckel is designed for those who want to migrate from other object-oriented languages such as C++ to JAVA. The book covers everything there is to know about JAVA and it brings readers up to speed with the latest features of JAVA 2. The book pays particular attention to object design and it covers different APIs in JAVA 2. Some of the notable topics that are covered include object-design basics, JAVA I/O classes, inheritance and polymorphism, deployment to JAR files, object lifetimes, exception handling, and multi-threading and persistence, among others.
2) Java(TM) Puzzlers: Traps, Pitfalls, and Corner Case
By: Joshua Bloch , Neal Gafter
A well-liked option with JAVA students and teachers is Java(TM) Puzzlers: Traps, Pitfalls, and Corner Cases. The book by Joshua Bloch, a Jolt Award-winner, has many brainteasers about JAVA coding language and JAVA's core libraries. The book is intended to challenge those who have a working knowledge of the JAVA programming language. The 95 diabolical puzzlers in the book are grouped according to the features employed.
3)Effective Java (2nd Edition) By: Joshua Bloch
. One of the most popular books on JAVA is Effective Java (2nd Edition). The book is written by a successful Java developer, Joshua Bloch. The strongest selling point of the book is the over 50 tips and best practices for writing a better JAVA code. The book offers advice on effective coding and it offers an insider insight into design choices that have been made in Sun's JAVA libraries over the years. The highly-readable book has 57 free-standing items in 9 chapters and it describes many idioms, patterns and anti-patterns
4)Java Concurrency in Practice By: Brian Goetz, Tim Peierls, Joshua Bloch, Joseph Bowbeer, David Holmes, Doug Lea
If you want to master JAVA Threading concepts, you should read Java
Concurrency in Practice. Java Concurrency in Practice covers basic
concepts of thread safety and concurrency, applicable techniques in
building and composing classes that are thread-safe, the use of
concurrency building blocks in java.util.concurrent, the dos and don'ts
of performance optimization, the testing of concurrent programs, and
advanced topics such as non-blocking algorithms, the JAVA memory model,
and atomic variables. This is a must-have book because threads are an
integral part of the JAVA platform and the use of concurrency for
optimized performance is becoming the norm with the use of multi-core.
The 2007 book is written by Brian Goetz and Tim Peierls.
5)Head First Java, 2nd Edition By: Kathy Sierra, Bert Bates
Those looking to learn coding in JAVA, should refer to Head First Java, 2nd Edition. The book, written by Kathy Sierra and Bert Bates, is an introductory JAVA coding book designed for those with little knowledge of the programming language. However, this is not your average 'Hello, World' introductory guide. Readers are exposed to object-oriented design, object-oriented implementation, network programming, serialization, Remote Method Invocation or RMIs and threads
Thursday, April 11, 2013
Simple example of key press listener
Simple key press listener
<-------------------------------------------------------->
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import javax.swing.JFrame;
import javax.swing.JTextField;
public class Main {
public static void main(String[] argv) throws Exception {
JTextField textField = new JTextField();
textField.addKeyListener(new MKeyListener());
JFrame jframe = new JFrame();
jframe.add(textField);
jframe.setSize(400, 350);
jframe.setVisible(true);
}
}
class MKeyListener extends KeyAdapter {
@Override
public void keyPressed(KeyEvent event) {
char ch = event.getKeyChar();
if (ch == 'a' ||ch == 'b'||ch == 'c' ) {
System.out.println(event.getKeyChar());
}
if (event.getKeyCode() == KeyEvent.VK_HOME) {
System.out.println("Key codes: " + event.getKeyCode());
}
}
}
---------------------------------------------output-----------------------------------------------------------------
Wednesday, April 10, 2013
Automatic or Robot writing using Java Programme
Automatic writing using Java
Code show below
<----------------------------------------------------------------------------------------------------------->
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
public class RobotKeyboardEvent {
public static void main(String[] args) {
try {
Robot robot = new Robot();
robot.delay(1000);
robot.keyPress(KeyEvent.VK_H);
robot.delay(1000);
robot.keyPress(KeyEvent.VK_E);
robot.delay(1000);
robot.keyPress(KeyEvent.VK_L);
robot.delay(1000);
robot.keyPress(KeyEvent.VK_L);
robot.delay(1000);
robot.keyPress(KeyEvent.VK_O);
robot.delay(1000);
robot.keyPress(KeyEvent.VK_SPACE);
robot.delay(1000);
robot.keyPress(KeyEvent.VK_W);
robot.delay(1000);
robot.keyPress(KeyEvent.VK_O);
robot.delay(1000);
robot.keyPress(KeyEvent.VK_R);
robot.delay(1000);
robot.keyPress(KeyEvent.VK_L);
robot.delay(1000);
robot.keyPress(KeyEvent.VK_D);
} catch (AWTException e) {
e.printStackTrace();
}
}
}
Code show below
<----------------------------------------------------------------------------------------------------------->
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
public class RobotKeyboardEvent {
public static void main(String[] args) {
try {
Robot robot = new Robot();
robot.delay(1000);
robot.keyPress(KeyEvent.VK_H);
robot.delay(1000);
robot.keyPress(KeyEvent.VK_E);
robot.delay(1000);
robot.keyPress(KeyEvent.VK_L);
robot.delay(1000);
robot.keyPress(KeyEvent.VK_L);
robot.delay(1000);
robot.keyPress(KeyEvent.VK_O);
robot.delay(1000);
robot.keyPress(KeyEvent.VK_SPACE);
robot.delay(1000);
robot.keyPress(KeyEvent.VK_W);
robot.delay(1000);
robot.keyPress(KeyEvent.VK_O);
robot.delay(1000);
robot.keyPress(KeyEvent.VK_R);
robot.delay(1000);
robot.keyPress(KeyEvent.VK_L);
robot.delay(1000);
robot.keyPress(KeyEvent.VK_D);
} catch (AWTException e) {
e.printStackTrace();
}
}
}
Subscribe to:
Posts (Atom)