Live Bytes For Object Instance In JVisualVM Increase On Every Operation

May 5, 2014

Whenever i perform any operation in my application Live Bytes of a particular Instance of a class increases by 1000.Although i perform the same operation everytime it always increases by 100 or 1000.Is this a memory leak or does these instances increase everytime we perform an operation.

View Replies


ADVERTISEMENT

Mathematical Operation On Bytes

Jan 28, 2015

byte a1 = 0;
byte a2 = 4
byte a3 = 4;

//below statement gives a compilation error
a1 = a2 + a3;

//below line compiles fine.
a1 = 4 + 4;

View Replies View Related

Changing Value Of Object Instance

Jul 13, 2014

I have been working on a program that is meant to use a class' instructions in a program to add a value to a variable, save it, and present it. This is my class

public class Car
{
//FIELDS
private int yearModel;
private String make;
private int speed;
//METHODS
public Car(int carYearModel, String carMake)

[Code] .....

Whenever I call the accelerate method, a value of 5 is to be added to the speed variable. But whenever I call accelerate, it doesn't increase! I just don't understand why not. I've tried different renditions of adding 5 to speed and it doesn't quite work. I don't get any errors when I compile, just runtime, when it doesn't add 5 to speed.

View Replies View Related

New Object With Instance Variables

Apr 7, 2014

So far in my assignment I have successfully opened a text file. However I am required to do more:

1) As each line of text (containing names and ages) is read a new Runner object is created with its instance variables set thus: ! (Runner class already created )!

- name : set directly set from the value in the file
- agaGroup : can be worked out from the given ages:
< 18 should be 'junior'
> 55 should be 'senior'
the rest should be 'standard'

2) the instance of Runner should be added to the list referenced by the instance variable runners.

I have used if statements to create the junior list, however I do not see the full list of names and ages in the variable runners as I am requested to.

I am sure there is a for loop involved somewhere but I do not know how to:

a) use the for loop in my method
add a new Runner object with the variable mentioned.

I include the code I have done so far as a file - p.s I use Bluej.

public class MarathonAdmin
{
// instance variables
private String runners;
private String age;

[Code] ....

View Replies View Related

One Object / One Instance Variable - Different Values?

Feb 5, 2015

Let's pretend I'm working on an RPG. Like in all RPGs, there are items found all throughout the imaginary world. Each player and NPC can obtain an item. My question will concern those items.

In other words, I'd like to use instances of a class in multiple places of the code. Each instance will have its own, individual values of instance variables, with one obvious exception: itemQuantity should have a different value in playerInventory, npcInventory, etc. Also, I'd like a list of all items that can be found in the game. This list doesn't need itemQuantity at all.

class Items {
String itemName;
float itemWeight;
int itemQuantity;

[Code] ....

The question is: should I really make itemQuantity an instance variable of the Item class? It seems as though for each copy of the Item class I should create a separate copy with different value of itemQuantity, but that's not very efficient. Where is the error in my logic?

What's important is that there may be plenty items in a game and a player may be given power to create new items during the course of the game.

View Replies View Related

StringHandler - Create Instance Of Object In A Loop

Oct 26, 2014

I can't figure out where to create the StringHandler object. My code should take a string as input, then create StringHandler object ord with the string input. This should repeat until cancel is pressed, then ord should be sent to the Utskrift-method (a print method).

If I do like this, null is also sent to Utskrift. I dont want that to happen.
If I put StringHandler last in the loop ord can not be resolved.

String text = "";
while (text != null){
text = showInputDialog(null, "Enter text:");
StringHandler ord = new StringHandler(text);
if (text == null){
[Utskrift(ord.getNumber(), ord.getString(), ord.getWords());
break;
}
}

View Replies View Related

Object / Methods - Private Instance Variables

Jun 30, 2014

so, i was reading my java book and learning about objects and methods and it starts talking about Encapsulation and mentions that it's good practice to set instance variables as private and instead of accessing the instance variables directly, we should create a set method and get method to get and set the stuff we want to pass to the class containing the object...

for example, in this class, we're passing the integer 70 for object dog one and integer 8 for object dog two for the dog class... and these these 2 integers are sent to the setsize method so we're not accessing instance variable size directly.

i dont quite get it though....if we the programmer are the one deciding what size the integer is for the dog, and the setsize method takes the one.setSize(70) or (8) and puts them in setsize(int s) as s... but only to copy that integer stored in s back to private int size.... why do we even need to bother with making these two extra methods such as setSize, getSize?

in the book it says that... well what if the code gets into the wrong hand and someone writes something like one.setSize(0) then you would get a dog with size 0 which is essentially illogical. but then again, i'm the programmer, and i am the person who writes the code and passing the right integer.The reason for public and private... that part i understand... i can see why if a variable's data can get changed amidst the code during calculations and you dont want it to directly change the original variable and have it mess up the code, but this code from the book just a bad example of demonstrating the reason? since we manually pass the information ourselves and passing it to method setSize... and all setSize does is stores it in another integer, only to copy it right away to size (which is the original private variable we were tryign to protect?

Any simple code to demonstrate how the code might end up changing an instance variable and why we would want to protect it by using private?

class GoodDog {
private int size;
public int getSize() {
return size;
}
public void setSize(int s) {
size = s;

[code]...

View Replies View Related

Test To See If Object Is Instance Of Interface Class

Mar 7, 2015

I am currently trying to use Junit to test a whole bunch of stuff. I almost have full line coverage but I am getting hung up on testing an if statement that consists of whether or not an object is an instance of another class. This class happens to be an interface, and even the object is an interface. Weird I know but I just want to know how to get into that if statement. I realize testing interfaces might be a waste of time but I still really want to know how. Here is an example of what I am trying to test:

Java Code:

if(x instance of y){ //where x and y are both interface objects
doSomething();
} mh_sh_highlight_all('java');

View Replies View Related

How To Pass Object Type To A Method / Then Create Instance

Aug 9, 2014

Essentially, the code I want is:

public void randomCreate(ParentObject obj){
int x = random(0-4); //pseudo
int y = random(0-4); //pseudo
create new ParentObj(x,y);
}

ParentObject is actually abstract, so you would only ever pass one of its children objects to it, and a child object of that type would be created. It seems like there should be a way to pass a type, rather than an object, and then create an instance later down, but I don't know if that is actually possible, or if it is poor programming style.

View Replies View Related

Create A New Instance Carte Of Object Carti Using Constructor

Mar 30, 2014

what have I done wrong n the following code? I'm trying to create a new instance carte of object Carti using the constructor and then to insert a row into a table created with SQL.The error I'm getting is:

Exception in thread "main" java.lang.NullPointerException
at Carti.Carti.InsertCarti(Carti.java:103)
at Main.main(Main.java:37)
Java Result: 1
BUILD SUCCESSFUL (total time: 28 seconds)

The line Main.main(Main.java:37) is when I try to insert the row.
The line Carti.Carti.InsertCarti(Carti.java:103) is when I do the
PreparedStatement st = conn.prepareStatement("insert into Carti (Id,titlu"
+ ", descriere, autor, editie, anPublicare) values (?,?,?,?,?,?)");

Here is the code (Main and Carti Classes)

import Carti.Carti;
import Imprumut_Carti.Imprumut_Carti;
import Membrii.Membrii;
import static com.sun.org.apache.xalan.internal.lib.ExsltDatetime.date;
import static com.sun.org.apache.xalan.internal.lib.ExsltDatetime.date;
import java.sql.SQLException;
import java.text.DateFormat;
 
[code]....

View Replies View Related

Converting Parent Instance To Child Instance?

Mar 7, 2014

I've Parent and child(extends Parent) class To initialize the constructors, I'm injecting from google.juice#injector. Let me show the code,

Parent.class

public class Parent{
private Animal animal;
@inject
Parent(Animal animal){
this.animal = animal;

[code].....

When I do this, ClassCastException is happening. Why is it so? Is there any way to convert instance of parent to child instance.

View Replies View Related

JSP :: Develop Live Score Webpage?

Apr 1, 2014

I am trying to develop a live score webpage using ONLY JSP.

View Replies View Related

JSF :: Primefaces Sorting Not Working Properly With Live Scrolling

Dec 15, 2013

I have datatable with live scrolling enabled.The columns are not getting sorted fully.When one of the columns is sorted,for example "insured" in the image shown below, all the records seem to have sorted but when i reach the end of scroll and next set of records get loaded i see other records in unsorted order as indicated in the image ,when i try to see the column in descending order.So because of this i am not getting the sorting feature accurately done(All records are not getting sorted at a single stretch)

My JSF code snippet

<p:dataTable id="workSpaceList" var="data"
value="#{workSpaceBean.lazylpId}" widgetVar="multiSelection"
selection="#{workSpaceBean.selectedRows}" resizableColumns="true"
liveScroll="true" scrollRows="15" scrollWidth="100%"
scrollHeight="75%" styleClass=".ui-datatable-hor-scroll"

[Code] ....

View Replies View Related

Live Video Streaming From CCTV Camera In Application?

Dec 26, 2013

I am developing some application in Java. The need is to continuously do a video streaming in the software. I am new to this and want to know how to do it.

View Replies View Related

JavaFX 2.0 :: HTTP Live Streaming M3u8 Example Not Playing

Jul 15, 2014

I was testing my JavaFX2.2.7 based media player code in a current Java 6 application when I discovered that HTTP Live Streaming does not seem to work.  I can play a local file of the supported format (Sintel trailor mp4 h264) but when I try and use an HTTP Live Stream instead, nothing plays. (for example [URL] ).  I end up with a blank player, and no exceptions or errors.
 
private static final String MEDIA_URL = "http://download.oracle.com/otndocs/products/javafx/JavaRap/prog_index.m3u8";
Media media = new Media(MEDIA_URL);
MediaException ex = media.getError();
if (ex != null){
System.out.println("Media Error" + ex.getMessage());
} else{
System.out.println("No Media Error");
}
 
Program console output: "No Media Error"
 
I thought it was something wrong with my player code, so as a last resort, I went to JavaFX 2 - Ensemble and copied the source and put it directly into my application and ran it... Unfortunately the same result occurs. The player runs, but simply shows a blank video window.  The controls are available, but no video plays.
 
Based on the Release notes for Java 2.2.7 I was under the impression that HLS was supported.  Am I incorrect?
I cannot upgrade to Java 7 as I am firmly stuck with Java 1.6.0.32 due to project constraints.

View Replies View Related

Adding Two Bytes In Binary

Oct 2, 2014

I am trying to add two bytes together in binary. The problem is that I need to print the carryover also. The printed result should be 8-bits long if the byte or the integer converted in binary is less than 8-bits the empty space should be filled with 0-s. I figured out how to print and add them, the part with the filling the blank with 0-s too. how to print the carryover. For example:

byte x =15;
byte y =9;
the output will be :

00011110 - carryover
x 00001111
y + 00001001
__________________

00011000 - result

import java.util.Scanner;
public class Addbytes
{
public static void main(String args [])

[code]....

View Replies View Related

Convert String To Array Or Bytes

Feb 9, 2015

First project here and it has been a steep learning curve. I have some code in the TwoWaySerialComm class that will write to a Com port. In my other class EBIAlarm i have my GUI. The aim of my app is the send strings out of the Com port by pressing Jbutton1-3 I can open the Com port but I don't know how to send the string.

Convert String to Array of Bytes.

import gnu.io.CommPort;
import gnu.io.CommPortIdentifier;
import gnu.io.SerialPort;

[Code].....

View Replies View Related

Decryption - Data Must Not Be Longer Than 128 Bytes

Oct 21, 2014

Button Code:

private void DecryptBActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
final String plainText;
if (!areKeysPresent()) {
// Method generates a pair of keys using the RSA algorithm and stores it
// in their respective files
generateKey();

[Code] ....

Everytime throwing exception "javax.crypto.IllegalBlockSizeException: Data must not be longer than 128 bytes" in decrypt method.

View Replies View Related

JSF :: Primefaces Live Scrolling Taking Long Time With Large Dataset

Feb 21, 2014

I have a primefaces datatable with about 52000 records to be fetched.Since it is a large dataset,i tried using live scrolling feature of primefaces with scroll rows equal to 20.THe number of columns is 53.The table also has filtering and sorting feature on its each column.Still i am not satisfied with the performance of the table.It takes about 15 secs for the page to load,worst thing is that it takes about 65 secs for the next set of 20 records to be loaded on reaching the end of scrolling.

Just for testing i reduced the total number of records to 25000 and the preformance improves with scroll time of 29 secs.I am really not able to understand why it is taking this much time when i am displaying only 20 records at a time.The total number of records should not have affected the performance.

My JSF code snippet

<p:dataTable id="arcRecList" var="data"
value="#{archivedRecordBean.archiveItems}"
tableStyle="table-layout:auto; width:80%;" styleClass="datatable"
scrollable="true" scrollWidth="84%" scrollHeight="69%"
columnClasses="columnwidth" liveScroll="true" scrollRows="20"
filteredValue="#{archivedRecordBean.filteredArchiveItems}">

[Code] ....

View Replies View Related

File Handling - It Store Character Not Bytes

Apr 13, 2015

Now I have a problem for file handling it is not store bytes in to rahul.txt. it stores character not bytes.

package com.fileh;
import java .io.*;
//import java.io.File;
public class Writedata {
public static void main(String args[])
{
try{
FileOutputStream fout= new FileOutputStream("rahul.txt");
String s="my name is rahul";
byte[] b =s.getBytes();
fout.write(b);
fout.close();
}
catch(IOException ioe)
{
}
}
}

View Replies View Related

Converting Strings To Bits / Bytes And Vice Versa

Feb 23, 2014

I have:

Java Code: String s = "111100100111011011000010110011101"; mh_sh_highlight_all('java');

I am trying to convert that to bits/bytes.

I need to make that into a series of bits with the same exact values..."1" = a 1 bit, and "0" = a 0 bit.

Remarkably, I haven't been able to find much on this sort of conversion - possibly I am just not searching with the right keywords? As typically, stackexchange or other parts of the web have the same question that I have, asked (and answered) by many others.

How do I go about doing this?

Furthermore, how would I go about saving this to a file - and are there already good "kinds" of files to save this into. If not, how do I go about making my "own" type of "file."

CONTEXT:

I've written a compression system. To keep things simple, I've been using a string to hold the 1s and 0s, so that debugging is simpler, and overall, everything is easier to write. Now, however, my algorithm is finished - and I'm moving on to create a GUI and a working system. This is the last step that I need for the non-GUI stuff (which I'm writing through javafx by the way - is this the right thing to use? I've been told that that is where people are moving towards. Away from swing).

View Replies View Related

Sales Tax Increase At 6% Not Working

Feb 8, 2015

import java.util.Scanner;
public class SalesTax {
public static void main(String [] args) {
Scanner input = new Scanner(System.in);
 
double total = 0;
double currentTax = 0;

[Code] .....

View Replies View Related

MouseListener - How To Increase A Value By Clicking It

Dec 25, 2014

I want to make a simple game and learn java by experimenting with it.I don't know how to increase a value by clicking it.I know how to make my objects move in my small game with mouse or keys, but I also got a score var that I want to increase per click. I can increase it over time, but after 2 hours of trying I couldn't progress any further.This is the piece of code I used, I imported the class, got getters n setters and all of that...

if(e.getButton() == MouseEvent.BUTTON3) hud.setScore(hud.getScore() + 555);
Whenever I click I get an error, if I remember right "NullPointerException" is when something is missing I'm probably not targeting the value correctly...
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at com.tutorial.main.MouseListens.mouseClicked(MouseListens.java:22)
at java.awt.Component.processMouseEvent(Unknown Source)

[code]...

View Replies View Related

Increase Counter When A Post Is Made?

May 15, 2015

I was wondering what the easiest way would be to keep track of everytime someone makes a new post on reddit (social media site, for those who don't know). I want the program to keep track of the number of posts made with a counter, but that's the easy part. How do I set up a program to actually communicate with and monitor reddit's servers in this manner?

View Replies View Related

How To Increase Hours Of Employee At Given Index

Oct 7, 2014

Basically I need to increase the hours of an employee at the given index. Index is the position of the employee in the array, and amount is how many hours you will be increasing by.

This is what I have so far,

public void increaseHours(int index, double amount){
for(Employee e: employees){
if(e instanceof HourlyEmployee){
HourlyEmployee he = (HourlyEmployee)e
he.increaseHours(amount);
}
}
}
}

I'm not sure how to use the index to do this correctly, all it's doing right now is adding hours to every hourly employee

View Replies View Related

How To Increase Hours Of Employee At Given Index

Oct 7, 2014

Basically I need to increase the hours of an employee at the given index.Index is the position of the employee in the array, and amount is how many hours you will be increasing by.

This is what I have so far,

public void increaseHours(int index, double amount){
for(Employee e: employees){
if(e instanceof HourlyEmployee){
HourlyEmployee he = (HourlyEmployee)e
he.increaseHours(amount);
}
}
}
}

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved