Java Code: package strategyPattern; public class Warrior { private AttackBehaviour attackBehaviour; public String name; void setAttackBehaviour(AttackBehaviour aB) { this.attackBehaviour = aB; } void attack() { attackBehaviour.attack(); } } package strategyPattern; public interface AttackBehaviour { void attack(); } package ...
package strategyPattern; public class Warrior { private AttackBehaviour attackBehaviour; public String name; void setAttackBehaviour(AttackBehaviour aB) { this.attackBehaviour = aB; } void attack() { attackBehaviour.attack(); } } package strategyPattern; public interface AttackBehaviour { void attack(); } package
Java Code: package observerPatternBuiltIn; import java.util.Observable; public class MyObservable extends Observable { int integerToBeObserved; public void setInt(int i) { integerToBeObserved = i; setChanged(); notifyObservers(); } public int getInt() { return integerToBeObserved; } } package observerPatternBuiltIn; import ...
package observerPatternBuiltIn; import java.util.Observable; public class MyObservable extends Observable { int integerToBeObserved; public void setInt(int i) { integerToBeObserved = i; setChanged(); notifyObservers(); } public int getInt() { return integerToBeObserved; } } package observerPatternBuiltIn; import
Java Code: package decoratorPattern; public abstract class Beverage { String description; int size; public Beverage(int size) { this.size = size; } public String getDescription() { String mySize = null; if(size == 1) mySize = "Small"; else if(size==2) mySize="Medium"; else if(size==3) mySize="Large"; ...
package decoratorPattern; public abstract class Beverage { String description; int size; public Beverage(int size) { this.size = size; } public String getDescription() { String mySize = null; if(size == 1) mySize = "Small"; else if(size==2) mySize="Medium"; else if(size==3) mySize="Large";
Originally Posted by heart_throbber Hi all, I have 2 DTOs & 2 Entities, 1 controller & 1 service implementation over here. Now, my problem is at the service implementation setStates. I dont know how to set states to address entity from addressDTO's getStatesList. because address entity includes state entity while addressDTO using stateDTO . My Address Entity: Java Code: public class Address { private List<State> states; public List<State> ...
public class Address { private List<State> states; public List<State>
Hi sir, I have been working with one application i dont know whats best and how to begin it please help me with it. Problem statement: I have a application it's a attendence application for teachers. Every person needs to submit the week's attendence by tueseday. few people are forgetting it. I have all the people list who have not submitted attendence by tueseday morning everyweek. the IP addresses of them. Now (1).I want to write a program which ...
Hi When my application is going through an Scanner I am getting AppDos Vulnerability with BufferedReader.readLine() can anyone help me out on this.My Sample code is as follows: while((line = reader.readLine())!= null) { // Remove JavaScript if (isPartOfString(SCRIPT_OPEN_TAG, line)) { while ((!isPartOfString("somestring", line)) && ((line = reader.readLine())!= ...
Java Code: import javax.swing.UIManager; public class TestClass { public static void main(String args[]) { UIManager.LookAndFeelInfo laf[] = UIManager .getInstalledLookAndFeels(); for (int i = 0, n = laf.length; i < n; i++) { System.out.print("LAF Name: " + laf[i].getName() + "\t"); System.out.println(" LAF Class name: " + laf[i].getClassName()); } System.exit(0); ...
import javax.swing.UIManager; public class TestClass { public static void main(String args[]) { UIManager.LookAndFeelInfo laf[] = UIManager .getInstalledLookAndFeels(); for (int i = 0, n = laf.length; i < n; i++) { System.out.print("LAF Name: " + laf[i].getName() + "\t"); System.out.println(" LAF Class name: " + laf[i].getClassName()); } System.exit(0);
Java Code: package myPaackkage; import java.util.*; public class SomeClass implements Iterable<String> { @Override public Iterator<String> iterator() { System.out.println("Hello!!"); return new Iterator<String>() { private int i = 0; @Override public boolean hasNext() { while(i<words.size()) return true; ...
package myPaackkage; import java.util.*; public class SomeClass implements Iterable<String> { @Override public Iterator<String> iterator() { System.out.println("Hello!!"); return new Iterator<String>() { private int i = 0; @Override public boolean hasNext() { while(i<words.size()) return true;
Updated 02-21-2012 at 11:33 PM by fatabass (Code tags.)
Java Code: package myPaackkage; import java.util.ArrayList; import java.util.HashMap; import java.util.ListIterator; import java.util.Random; public class SayisalGenerator { static Random myRandomGenerator = new Random(); public static void main(String[] args) { HashMap<Integer,Integer> myHashMap = new HashMap<Integer,Integer>(); for(int i=0;i<1000;i++) { ...
package myPaackkage; import java.util.ArrayList; import java.util.HashMap; import java.util.ListIterator; import java.util.Random; public class SayisalGenerator { static Random myRandomGenerator = new Random(); public static void main(String[] args) { HashMap<Integer,Integer> myHashMap = new HashMap<Integer,Integer>(); for(int i=0;i<1000;i++) {
Java Code: package myPaackkage; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.TreeMap; import java.util.TreeSet; public class ...
package myPaackkage; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.TreeMap; import java.util.TreeSet; public class
Java Code: package myPackage2; public abstract class Event { private long eventTime; protected final long delayTime; public Event(long delayTime) { this.delayTime = delayTime; start(); } public void start() { eventTime = System.nanoTime() + 2*delayTime; } public boolean ready() { return System.nanoTime() >= eventTime; } ...
package myPackage2; public abstract class Event { private long eventTime; protected final long delayTime; public Event(long delayTime) { this.delayTime = delayTime; start(); } public void start() { eventTime = System.nanoTime() + 2*delayTime; } public boolean ready() { return System.nanoTime() >= eventTime; }
Java Code: package myPackage; public class SprinklerSystem { private String valve1; private int valveStrength; private WaterSource source = new WaterSource(); static { System.out.println("You are in Static block!"); } { System.out.println("You are in initi block!"); this.valve1 = "Valve1 "; } SprinklerSystem() ...
package myPackage; public class SprinklerSystem { private String valve1; private int valveStrength; private WaterSource source = new WaterSource(); static { System.out.println("You are in Static block!"); } { System.out.println("You are in initi block!"); this.valve1 = "Valve1 "; } SprinklerSystem()
Java Code: public class ClassCasts { public static void main(String args[]) { Building b = new House(); Class<House> houseType = House.class; House h = houseType.cast(b); System.out.println(b.getClass()); } }
public class ClassCasts { public static void main(String args[]) { Building b = new House(); Class<House> houseType = House.class; House h = houseType.cast(b); System.out.println(b.getClass()); } }
Java Code: package myPackage1; interface HasBatteries{}; interface Waterproof{}; interface Shoots{}; class Toy { Toy(){}; Toy(int i){}; } class FancyToy extends Toy implements HasBatteries,Waterproof,Shoots { FancyToy() { super(1); } } public class ToyTest { static void printInfo(Class cc) { System.out.println("Class name: ...
package myPackage1; interface HasBatteries{}; interface Waterproof{}; interface Shoots{}; class Toy { Toy(){}; Toy(int i){}; } class FancyToy extends Toy implements HasBatteries,Waterproof,Shoots { FancyToy() { super(1); } } public class ToyTest { static void printInfo(Class cc) { System.out.println("Class name:
Java Code: package myPackage; import java.awt.Container; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JTextField; public class FileOrganizer extends JFrame implements ActionListener { public ...
package myPackage; import java.awt.Container; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JTextField; public class FileOrganizer extends JFrame implements ActionListener { public
Java Code: public static void main(String[] args) { File myText = new File("c:/myDir/myText.txt"); try { InputStream myByteReader = new FileInputStream(myText); System.out.println("Available total bytes:" + myByteReader.available()); int firstByte = myByteReader.read(); System.out.println("First byte:" + firstByte); System.out.println("Char of first byte:" + (char) firstByte); ...
public static void main(String[] args) { File myText = new File("c:/myDir/myText.txt"); try { InputStream myByteReader = new FileInputStream(myText); System.out.println("Available total bytes:" + myByteReader.available()); int firstByte = myByteReader.read(); System.out.println("First byte:" + firstByte); System.out.println("Char of first byte:" + (char) firstByte);
Java Code: package myPackage; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FilterOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.OutputStream; import java.io.PrintStream; import java.io.PrintWriter; import java.io.Serializable; ...
package myPackage; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FilterOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.OutputStream; import java.io.PrintStream; import java.io.PrintWriter; import java.io.Serializable;
Java Code: package myPackage; import java.awt.BorderLayout; import java.awt.FlowLayout; import java.awt.GridLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; public class SimpleCalculator { public static void main(String[] args) { JFrame myFrame = new JFrame( "Testing" ); ...
package myPackage; import java.awt.BorderLayout; import java.awt.FlowLayout; import java.awt.GridLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; public class SimpleCalculator { public static void main(String[] args) { JFrame myFrame = new JFrame( "Testing" );
Java Code: package myPackage; import java.awt.Container; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; public class GridLayoutFrame extends JFrame implements ActionListener { private JButton[] buttons; // array of buttons private static final String[] names = {"one", "two", "three" ...
package myPackage; import java.awt.Container; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; public class GridLayoutFrame extends JFrame implements ActionListener { private JButton[] buttons; // array of buttons private static final String[] names = {"one", "two", "three"
Java Code: package myPackage; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JList; import javax.swing.JScrollPane; import javax.swing.ListSelectionModel; public class MultipleSelectionFrame extends JFrame { private static final long serialVersionUID = 1L; private JList colorJList; ...
package myPackage; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JList; import javax.swing.JScrollPane; import javax.swing.ListSelectionModel; public class MultipleSelectionFrame extends JFrame { private static final long serialVersionUID = 1L; private JList colorJList;
Java Code: package myPackage; import java.awt.FlowLayout; import java.awt.GridLayout; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JList; import javax.swing.JScrollPane; import javax.swing.ListSelectionModel; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; public class ListFrame extends JFrame { JList myJList; String[] colorrs; ...
package myPackage; import java.awt.FlowLayout; import java.awt.GridLayout; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JList; import javax.swing.JScrollPane; import javax.swing.ListSelectionModel; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; public class ListFrame extends JFrame { JList myJList; String[] colorrs;
Writing Better Java Code This is a compilation of advice on writing more efficient Java code. Whenever I find more I'll add them to the list. If you spot something fishy do say so, so that I will correct it. Faster code: 1. Use integer instead of long (long is a 64bit integer, most processors are 32bit so operations can run 2-4 times faster with an int) 2. Use local variables instead of class members 3. Use shorthand when evaluation booleans Java Code: return ...
return
Updated 12-27-2011 at 11:26 PM by ozzyman
Originally Posted by keffie91 Hello I have created an optionwindow for my chat program, but if i open the option window and click the cross in the right corner, not only the optionwindow terminates but also the chatprogram. Can someone tell what i can do about it, and are there other ways to make a kind of optionwindow? thanks keffie91 this is the source: ChatProgram.java Java Code: import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; ...
import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*;
Java Code: package myPackage; import java.awt.Color; import java.awt.FlowLayout; import javax.swing.*; @SuppressWarnings("serial") public class SamsLearning extends JFrame { public SamsLearning() { super(); this.setTitle("My Title"); this.setLookAndFeel(); this.setSize(500,500); MyButtonClass myButton = new MyButtonClass("Play"); MyButtonClass myButton2 = new MyButtonClass("Stop"); ...
package myPackage; import java.awt.Color; import java.awt.FlowLayout; import javax.swing.*; @SuppressWarnings("serial") public class SamsLearning extends JFrame { public SamsLearning() { super(); this.setTitle("My Title"); this.setLookAndFeel(); this.setSize(500,500); MyButtonClass myButton = new MyButtonClass("Play"); MyButtonClass myButton2 = new MyButtonClass("Stop");
SyncML is the standard for data synchronization and is accepted by Open Mobile Alliance (OMA). All the major players, including Ericsson, Nokia, IBM, Motorola, and Symbian support this protocol. The synchronization of data has great importance in today’s world. You carry email applications, contact database, files and other stuff on your handheld devices. It would be great of you can synchronize those with your desktop/notebook. For that there has to be a agreed format. ...
In this post, I will present an example to show how to use the DocumentBuilderFactory. First step is to import the required classes. Java Code: import java.io.File; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.Writer; // JAXP import javax.xml.parsers.FactoryConfigurationError; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.DocumentBuilderFactory; ...
import java.io.File; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.Writer; // JAXP import javax.xml.parsers.FactoryConfigurationError; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.DocumentBuilderFactory;
You will be introduced to the working of DOM parser in this post. We can get a DocumentBuilder instance as soon as we have a DOM factory. The methods available for the DocumentBuilder instance are very similar to those available to its SAX counterpart. But there is a slight difference when we talk about the parse() method. The parse method in case of DOM do not take an instance of the SAX DefaultHandler class. It returns a DOM Document instance representing the XML document that was ...
RSS (Really Simple Syndication) is a family of Web feed formats used to publish frequently updated content such as blog entries, news headlines, and podcasts. It is actually a specification for XML files to provide syndicated data. To read RSS feeds in a Java application is easy. You have to use Informa API which is availabel at: http://informa.sourceforge.net/. The code snippet given below shows how to read RSS using Informa API. Java Code: try { ...
try {
We all know that javac command is used to compile the java classes. Even if we are using some IDE (Eclipse, JBuilder, NetBeans), javac is called at the background for compilation. But with the release of Java 6, it has become possible to compile Java class from a Java class. The classes related to Java compiler are packed into javax.tools package. There is a class called ToolProvider (javax.tools) whose getSystemJavaCompiler() method returns an instance of some class ...