EJB / EE :: Life Cycle Call Back Methods
Apr 17, 2014
Life Cycle Call back methods(init(), destroy(),...) are not transactional by default and expecting this in coming EJB releases (EJB 3.x / EJB 4.x). I was expecting next EJB release along with Java 8, but it stays at 3.2
View Replies
ADVERTISEMENT
Apr 16, 2015
how come you can call non static methods from other classes(objects when they are created from main) but not static methods in the same class as the main method??
example I cannot call the method maximum from the main method aslong as its not static BUT i can call other objects non static methods from main??
class test{
public static void main(String [] args){
Scanner input = new Scanner(System.in); //create new Scanner object
//for input
int number1;
int number2;
[Code]...
View Replies
View Related
Jun 2, 2014
If I had this code:
<h:dataTable value="#{customer.customerList}" var="c"
styleClass="order-table"
headerClass="order-table-header"
rowClasses="order-table-odd-row,order-table-even-row"
>
And in the server getCustomerList() accessed to database, how many times getCustomerList() would be called from I request the xhtml page?. I have read this would be called several times because of JSF internals and It would be better to store it in a variable and access this variable.
1. Is this true this would be called several times? why?
2. If the previous statement was true, how to avoid it, I mean not call the method from a service?
View Replies
View Related
Mar 25, 2015
I am trying to make a 2d graphical animation using the java swing classes in order to make a frame. I had a basic version working when all of the code was under the main method, but when I moved some into another method it broke it. With y understanding of java my code should work as I create a variable of the method containing the code and then assign the size and exit button. However this causes many problems such as my BeaconFrame method informing me that it is unused when I have used it. Here is my code:
import javax.swing.*;
import java.awt.*;
public class BelishaBeacon {
public void BeaconFrame() {
JFrame frame = new JFrame();
JPanel panel1 = new JPanel();
[code]....
View Replies
View Related
Aug 6, 2014
I have a question about a method I have. In my game, I had a move method to move my player left and right, and originally this method was huge, as it also took care checking collisions and a few other things. I broke it up a bit and put the collisions in their own methods and call them from again another method... Here is an extract which I hope illustrates my point:
private static final double MOVE_SPEED = 0.2;
private static final double MAX_MOVE_SPEED = 3.5;
private static final double STOP_SPEED = 0.18;
private double xPos;
private double yPos;
[Code] .....
Something I thought might be a good idea is to check the direction collision when im doing the calculations for that direction:
if(moveLeft) {
dx -= MOVE_SPEED;
(dx < -MAX_MOVE_SPEED) {
dx = -MAX_MOVE_SPEED;
}
checkLeft();
}
But then I would also need to check it when I'm slowing down the left movement:
if(dx < 0.0) {
dx += STOP_SPEED;
if(dx > 0.0) {
dx = 0.0;
}
checkLeft();
}
Then I thought instead i can check it after both of these steps:
if(moveLeft || dx < 0.0) {
checkLeft();
}
I guess my question is quite general: How much is acceptable to break up a method? How many chains of method calls is acceptable? Is it ok to call the same method from different nearby places?
View Replies
View Related
Dec 19, 2014
For reference I am programming Java in BlueJ. I am fairly new to the language and I am having trouble with sorting.
I am trying to call / test all of the 5 sorting methods (at the same time) in the main class. To be specific, the sorted list has to technically outputted 5 times.
I figured out how to call / test Quicksort:
Sorting.quickSort(friends, 0, friends.length-1);
But the others are not working correctly. Specifically these:
Sorting.mergeSort(friends, 0, friends.length-1);
Sorting.PbubbleSort(friends, 0, friends.length-1);
Sorting.PinsertionSort(friends, 0, friends.length-1);
Sorting.selectionSort(friends, 0, friends.length-1);
For reference, this is the output when it is not sorted:
Smith, John 610-555-7384
Barnes, Sarah215-555-3827
Riley, Mark 733-555-2969
Getz, Laura 663-555-3984
Smith, Larry464-555-3489
Phelps, Frank322-555-2284
Grant, Marsha243-555-2837
This is the output when it is sorted:
Barnes, Sarah215-555-3827
Getz, Laura 663-555-3984
Grant, Marsha243-555-2837
Phelps, Frank322-555-2284
Riley, Mark 733-555-2969
Smith, John 610-555-7384
Smith, Larry464-555-3489
This is the class Sorting, which I should note is all correct:
public class Sorting{
/**
* Swaps to elements in an array. Used by various sorting algorithms.
*
* @param data the array in which the elements are swapped
* @param index1 the index of the first element to be swapped
* @param index2 the index of the second element to be swapped
*/
private static <T extends Comparable<? super T>> void swap(T[] data,
int index1, int index2){
T temp = data[index1];
data[index1] = data[index2];
[Code]...
This is the Main class in which I am supposed to call the sorting methods, SortPhoneList:
public class SortPhoneList{
/**
* Creates an array of Contact objects, sorts them, then prints
* them.
*/
public static void main (String[] args){
Contact[] friends = new Contact[7];
friends[0] = new Contact ("John", "Smith", "610-555-7384");
friends[1] = new Contact ("Sarah", "Barnes", "215-555-3827");
[Code]...
View Replies
View Related
Dec 31, 2014
Here is my Code for the Game Of Life that I am programming to teach my self java. I am trying to create a GUI and I have done so and a window displays however i don't understand how i can get the Game of Life to display within that GUI?
import java.io.*;
import javax.swing.JFrame;
import java.awt.Color;
import java.awt.FlowLayout; //Provides default layout managing
import javax.swing.JLabel;
public class LifeMain extends JFrame
[Code] ......
View Replies
View Related
Feb 7, 2015
I am trying to pass an object of type Product p to my editProduct method, however trying to call p.getName(); doesn't work and throws a NullPointerException. The same kind of thing works for my displayRecord method (in a different class) and I can call .getName() on Product p, also passed as an argument to that method. Below is my editProduct class. The NullPointerExcepion is being thrown at line 61 (i.e., nameField.setText(p.getName());).
I don't know if I explained right, so here's a line thing of how the classes relate:
Search >>>(field.getText())>>> displayRecord(Product p) >>>editProduct(p)>>> EditProduct
And as a side note: adding the line p = new Product(); fixes it and successfully runs the class (including the Save and Quit parts) but obviously I want it to specifically refer to the Product I pass to the method.
Java Code:
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.util.ArrayList;
import javax.swing.BorderFactory;
[Code] ....
I'm asking a question because I don't understand how Product p could possibly be null, because the argument is passed through my DisplayRecord class, which also takes a Product p argument and works. In that class, I have declared Product prod = p; and prod is what I am passing to editProduct.
View Replies
View Related
Aug 6, 2014
I have a database of peoples names linked up to a from to enter a new employee.The form has a previous and next button that should cycle through the employees alphabetically.What im doing the cycle by now is ID which isnt in alphabetical order and just goes by the order they where entered in.
Is there any way to cycle through alphabetically instead? Is running a query each time the next/previous button is pressed the correct way or should it just grab all the names in the array. Theres probably 150 names.
View Replies
View Related
Jan 4, 2015
I have some problem checking if a directed graph has a cycle or not. So I have a given rooted directed graph, and find if there at least one existing cycle.
For example, I have to input the Root Node, followed by a number of nodes, the nodes in the graph, number of edges, and the adjacency list representing the edges. Each entry in the adjacency list contains a pair of nodes. The ordering of the nodes in the pair represents the direction of the edge. An entry A, B means that there is an edge from A to B. Nodes in each pair is separated by a space. One input per line.
And the output should display whether the directed graph has a cycle or not.
Sample input:
A //Root Node
6 //Number of Nodes
A //Nodes in Graph
B
C
D
E
F
6 //Number of edges
A B //Adjacency list representing the edges
B C
C D
C F
F E
E B
Output:
Cycle!
Graph Representation:
Based on the illustration above, the graph has one cycle. The cycle exists in nodes B, C, F and E.
View Replies
View Related
May 1, 2014
So basically I have an arraylist (names) filled with images.
Now I have a JButton on my GUI and when I click my 'next' button, it's supposed to cycle through to the next image in the arraylist. With this code I am only using it to actually see if it will set the new image, but I keep getting errors thrown at me when im trying to define the new image to be set
String shield = "C:\Documents and Settings\derek\Desktop\shields\" + names.get(1);
imgico = new ImageIcon(shield);
img.setIcon(imgico);
The error i'm getting is:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at newmay1.makegui$myhandle.actionPerformed(makegui.java:66)
Along with a ton more lines of red text, and i've tried many different ways of doing this.
Even when I simply just output to the console each item in my arraylist, it comes out perfectly as a string.
View Replies
View Related
Nov 17, 2014
I am having some trouble programming the Game of Life algorithm.
View Replies
View Related
Dec 16, 2014
I'm writing an ESP game code for class. The problem is i cant get it to cycle through the colors after each guess is entered. It stays fixed on the original random number generated.
import java.util.Random;
import java.util.Scanner;
public class Final1 {
String colorInput, computerColor;
int computerNum, right, wrong;
[Code] ....
This repeats 10x but the color never changes from the initial random chosen.
View Replies
View Related
Jan 15, 2014
My program has the following requirements.
Several kinds of celebration dates are displayed.
Say Marriage, a new baby is born and so on. Such special dates are not fixed to be once or twice.
Such that a person can have a marriage and a new born baby celebration or both. One of my thoughts was to used several (up to 3). JLabels and JDateChoosers, but it is quite limiting.
How should I design such a component so that it can accommodate several major events of life.
View Replies
View Related
Mar 3, 2015
The question pretty much says it all. My problem seems to be when adding the neighbours, I am always getting a Index out of Bounds problem. I know this is because the code is reaching for the edge of the table, for example if the column, i = 0 and the statement says to perform i - 1 and return it, then we are going to have a problem.
Similarly with anything like j = 20, j + 1 (as the grid only has 20 spaces). I understand the problem, but I am unsure of how to solve it. I have tried messing around with the if statements, but I continue to get the 'out of bounds' problem...
import javax.swing.*;
public class GameOfLife {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int cellChoice = 0;
int newCells = 1;
int generation = 1;
int neighbours = 0;
[Code] .....
View Replies
View Related
Aug 19, 2014
i am trying to make something, and i want to request input from user and it shoud look like this
1. xxx -> press 1 to choose this
2. xxx -> press 2 to choose this
So if they enter 3 or string or whatever i want to restart method and show again
1. xxx -> press 1 to choose this
2. xxx -> press 2 to choose this
So here is method that i am trying to restart
public static void askUser(){
System.out.println("xxx");
System.out.println("1. xxx");
System.out.println("2. xxx");
System.out.println("3. xxx");
[code]....
If i try to make it public void than it say can't call non-static methods inside static(main).if i try to put it into new class and then call it after i fail input it goes into infinite loop.
View Replies
View Related
Apr 14, 2015
I create 2 files:
CircleCalculationMethod.javaMain.java
In Main.java, How can i call method in CircleCalculationMethod.java ?
Should I put everything in same folder ??Should i do something like "import CircleCalculationMethod.java"Should i do something like create a package ...
I use Eclipse software
View Replies
View Related
Jul 6, 2014
I've been putting together an addressbook and try to work on some idea but I have hit a bit of a wal early on, and Im sure the problem is easy to resolve, I just can't get the old brain to do it.At present I have 5 classes
PersonDetailsAdressDetailsAddressBookAddressBookGUIEnterDetailsPanel
I have taken EnterDetailsPanel out of the main GUI code, as I plan, or had planned on using additional JPanels for the other options of the application until I got stuck. What I want the EnterDetails panel to do, which it does so far is to have the user enter all of their information and when the button is pressed it will then create a PersonDetails object and here is where my problem is. how to get the object from the panel back across to the GUI which initalises the AddressBook class in the constructor and add it to the List via an addDetails() method.
If I create a quick method in the AddressBookGUI class I can add the object to the List fine, I'm guessing this is because I have created a new instance of the AddressBook in here already via the constructor, however if I add an AddressBook reference in the EnterDetailsPanel I get a nullpointerexception for the opposite because it's not been created in there.These are what most of the classes do so far.
PersonDetails has a reference to the AddressDetails and holds all information for that person.AddressBook contains a List that accepts PersonDetails and has methods to add/remove the person.AddressBookGUI creates a new instance of the AddressBook class along with the general gui things. EnterDetailsPanel is added to JTabbedPane in the GUI class and allows the user to enter their details and submit those via a button which will then create a new PersonDetails object that I am trying to get added to the AddressBook class List
View Replies
View Related
Nov 12, 2014
I am trying to figure out how to get information back from a different method.
Basically I want to write a program to create a car, but I want to be able to add features based on user our put (V6 versus V8, Color choice, etc), but I want each one to be broken out into their own method but I am unsure of how to call from the main method and return the variable (engineSize = V8, color = blue, etc).
View Replies
View Related
Apr 19, 2014
I have a website which requires login. After I enter username and password and click login button, a new page is loaded. In that page I have a username in the right up corner. When the user clicks logout button, Session.Clear() method is called and also Response.Redirect(" to login page "). It works OK, but the problem appears when I then click Back button in the browser. It gets me back to previous page with the username in the right up corner. Insted, I would like to show message asking user to enter password again so he can login properly.
What should i do at client side???
View Replies
View Related
Apr 28, 2014
how to have an application restart if the user inputs an incorrect integer in a JOptionPane question? I know how to do it with the Scanner class but nothing I do seems to work. This is the beginning of my code:
import javax.swing.JOptionPane;
public class Pay {
public static void main(String[] args) {
String level = JOptionPane.showInputDialog("Please select your skill level: 1, 2, or 3");
int levelPick = Integer.parseInt(level);
[code]...
View Replies
View Related
Feb 13, 2014
I'm using the class below to encrypt and decrypt data in my program. It works rather well with the exception that I can't for the mind of me get the recreation of the key to work. When the program runs the first time, it creates a key and saves it to Data.txt. This part works fine, and there are no errors, the encryption and decryption works until I reload the program and it tries to recreate the key using the String in the .txt.
read = loadFile.readline();
byte[] data = read.getBytes("UTF-8");
key = new SecretKeySpec(data, 0, data.length, "PBEWithMD5AndDES");
I've looked at:
java - convert Byte Array to Secret Key - Stack Overflow
java - Converted secret key into bytes, how to convert it back to secrect key? - Stack Overflow
and a number of other sites which didn't work, both of these however suggested the key = new SecretKeySpec. The actual key became: "[B@79fe3f51". Whereas the recreated key became: "[B@3e1d1648".So they are close, but not the same.I create the original key like this:
key = SecretKeyFactory.getInstance("PBEWithMD5AndDES").generateSecret(keySpec);
Encryption.java:
public class Encryption {
public Cipher dcipher, ecipher;
// Responsible for setting, initializing this object's encrypter and
// decrypter Chipher instances
Encryption(String passPhrase) {
[code]....
View Replies
View Related
Feb 24, 2014
This piece of java software I am responsible for is running throughout numerous locations in my country, there is only 1 location which has trouble with the dates being displayed incorrectly, birthdates of clients are displayed as a day earlier. It seems pretty safe to say it is a problem on their end... But still, they're asking me for an explanation as to why java would treat a date differently in this rare case.
The date (a birthdate) comes from an oracle database, it is a date without a time (trunced date). It enters the application as a member of the client-class, it is NOT being set or changed after that. It goes through several layers in the application, then ends up in a GUI class which unwraps it from the "client"-object and puts a SimpleDateFormat (new SimpleDateFormat("dd-MM-yyyy")) on it. My first and only hunch was the timezone settings, but that seems to be OK!
View Replies
View Related
Mar 3, 2014
I'm stuck with the following error message when i try to convert a String to XML and back to a String.
Exception in thread "main" org.w3c.dom.DOMException: WRONG_DOCUMENT_ERR: A node is used in a different document than the one that created it.
at com.sun.org.apache.xerces.internal.dom.ParentNode.internalInsertBefore(Unknown Source)
at com.sun.org.apache.xerces.internal.dom.ParentNode.insertBefore(Unknown Source)
at com.sun.org.apache.xerces.internal.dom.NodeImpl.appendChild(Unknown Source)
at com.innovatrail.consulting.xml.XMLTEST2.main(XMLTEST2.java:66)
Below is my Java code snippet: The code syntactically correct except line 66. If you comment out line 66 in the source code, everything works just fine. The XML representation of my input string is denoted by INPUT 1 and that of my output string is denoted by OUTPUT 2.
package com.Test.xml;
import java.io.ByteArrayInputStream;
import java.io.StringWriter;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Transformer;
[Code] ....
INPUT 1:
<Collection>
<BookList>
<Book>
<Title>Wonder Man
</Title>
<Author>John Smith
</Author>
<Category>Fiction
[Code] .....
OUTPUT 2:
<Collection>
<Book>
<Title>Wonder Man</Title>
<Author>John Smith</Author>
<Category>Fiction</Category>
[Code] ....
View Replies
View Related
Jun 3, 2014
When we have a jsf form to store clients in a ddbb for example and the backing bean is in session scope.... Lets think of a user that requests 3 times the xhtml view with the form to store 3 clients.
1) If we dont reset the backing bean each time the form is processed, he would see the values he sent beforea and it doesnt have much sense, right?
2) Here there is an example of clearing form after submitting : [URL] ...... Clearing the form after submititng is a common practice for the reason of the statement 1, right?
3 ) What is the best or normal approach to reset values in a form? when the user requests it or done automatically by the application after processing a form?
4) Are there known issues about resetting or not resetting the values in a form bean?
View Replies
View Related
Oct 9, 2014
Inside a While Loop (While Loop begins if a condition is True) I have an If Statement, the else part of the statement assigns False to the condition I mentioned earlier.
But I've tried de-bugging and even when the code goes through the else part of the statement, firstly it returns False but then it returns to the beginning of the loop as True again.
View Replies
View Related