Why do I get multiple class files from 1 java file?
I wrote a dialog box using gridBagConstraints and another program RunPanel to run it as a java application. For the first time since playing with java, I get multiple class files from a single java file.
This seems very strange to me and wonder if anyone else has come across this and what could possibly be the reason for it. I did a clean (in Eclipse) just to make sure it wasn't garbage and sure enough they come back again.
I have ReconPanel.java from which I get ReconPanel.class with the addition of ReconPanel$N.class where N goes from 1 to 5.
The same thing in RunPanel but here there is only 1 extra file, RunPanel$1.class.
I'll include the code for RunPanel since it is relatively small:
package ilan;
import javax.swing.JFrame;
public class RunPanel extends JFrame {
private static final long serialVersionUID = 1L;
private ReconPanel m_reconPanel = null;
public RunPanel() {
super();
initialize();
* This method initializes this
private void initialize() {
this.setTitle("tester");
this.setSize(new java.awt.Dimension(138,396));
this.addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent e) {
m_reconPanel.exitPanel();
System.exit(0);
m_reconPanel = new ReconPanel();
this.getContentPane().add(m_reconPanel);
* @param args
public static void main(String[] args) {
JFrame frame1 = new RunPanel();
frame1.setVisible(true);
} // @jve:decl-index=0:visual-constraint="10,10"The only thing "unusual" I do is to put a listener on the WindowClosing so that I can go back to ReconPanel and write results to the registry.
Can anyone tell me what is going on?
Thanks,
Ilan
He IIan,
Yes, you get number of extra class files based on your number of anomyous class es used. Like in your RunPanel, you get only 1 ..$1.class file, b'coz u have used only 1 annomyous class & i.e WindowAdapter. Take a look at this code :-
this.addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent e) {
m_reconPanel.exitPanel();
System.exit(0);
});Similarly, in your ReconPanel, you must have used such kind of classes 5 times, & hence u get such 5 extra classes. To avoiod such extra classes, if you can directly implement that interface or extend the class, if possible will be best. For example, for each button, u write
button1.addActionListener(new ActionListener() {
// Code
});Instead, of this, its better to implement ActionListener & write
button1.addActionListener(this);
public void actionPerformed(ActionEvent ae) {
if (ae.getSource() == button1) {
// CODE
}Likethis, you can get rid of such numerous extra class files. In IDE, if you ask to add actionEvent, it will do the first method. To get rid of it, don't add event in the properties, instead, apply the second method. The same thing applies for anyother event. The first option is worthful, if by implementing, u got to write 5 functions from which u r gonna use just 1 method.
Hope this clears your question.
Trupti
Similar Messages
-
When i compile my program I get multiple class files
When I compile my program why when I have only written 1 Main.class do I get other ones with dooler signs in them.
For example
Main.class (This is the only on I have actually coded)
Main$1.class
Main$2.classIt must be that you have some inner classes as well, like:
class TheRealClass
private NonAnonymousInnerClass // this would create TheRealClass$NonAnonymousInnerClass.class
void foo()
Thread someThread = new Thread(
public void run() // this is an anonymous inner class - would create TheRealClass$1.class
someThread.start();
} -
How to compile and register a Java CFX tag with multiple class files?
All-
If this is the wrong forum for CFX questions, please let me
know.
I need to determine how to compile and register a Java CFX
tag that contains multiple class files. One class file implements
the CustomTag interface and the other class files implement various
supporting classes. All of the documentation that I have found
talks about using a single class file. I am assuming that a JAR
file will be involved, but I am not sure of the specifics.
Thanks in advance for your help.
-JoshYes, it will involve a jar. Use your java IDE (eclipse,
etcetera ..) to create a jar containing all of the classes. Check
your ide's documentation for how to create jar files. After you
have created the jar, place the jar in the CF class path so CF will
recognize it. For example the {cf_root}/WEB-INF/lib directory. CF
must be restarted before it will detect the new jar. After
restarting CF, register the CFX tag in the ColdFusion Administrator
using the name of the class that implements the CustomTag
interface.
Though it is worth noting you can also instantiate java
classes directly from ColdFusion (ie without using a CFX
tag). -
How to get the .class file for the extended Controller .java file
Hi,
I did the below steps.
1. Created New OAWorkspace
2. Created New project
3. Imported the page .xml file
4. Added new .java file by extending the controller class
5. Added code in the .java file.
6. Ran the .xml file
As I copied all the folders from Unix box, the page was opened.
But My question was where can I see the .class file the extended controller. It's a .java file. How to compile and get the .class file for this .java file. If I get this .class file, I can go to the page and click the personlize page. and change the Controller name to the new path by ftp ing the new class to the cust.oracle.apps.pos.changeorder.webiui.
Please let me know how to create the .class file.
Thanks,
HPAll are Java files are stored in JDEV_INSTALL_DIR:\jdevhome\jdev\myprojects\
In your case the path java would be
JDEV_INSTALL_DIR:\jdevhome\jdev\ myprojects \cust\oracle\apps\pos\changeorder\webui\
AND
Once you compile the java file in Jdeveloper, Class files get generated @ below path
In your case the path of class would be
JDEV_INSTALL_DIR:\jdevhome\jdev\ myclasses \cust\oracle\apps\pos\changeorder\webui\
Duplicate Thread-
Thanks
--Anil
http://oracleanil.blogspot.com/ -
Why do I get other iphones contacts from my itunes account on my phone?
Why do I get other iphone contacts from my itunes account on my phone? I get my wife and son's contacts in my iphone. I do not want. I have tried cloud and no cloud that only provides all the contacts or empty file of contacts.
What laptop are you refering to? Did the drive crash or is the laptop dead? Is the computer you want to transfer to a mac with Itune? If the other computer has Itunes,there are third part software that can transfer music and some file off an ipad to Itunes. Not sure about the Iphone. If you sync to another Itunes in another computer it will erase the ipad and install whatever is on the other Itunes. One of the third part apps. that comes to mind is Irip. Phone to Mac is another.
-
How to get the class file of jar file
hello all,
is there any way to get the class file of jar file,as we have when we compile a java file we get class file
same do we have any option to get the class file of jar fileA jar file is a zip archive, so you can uznip it or extract the contents with the command "jar" - if it is what you need.
-
Why is U51 blocking individual class files not in jars but U45 accepted them?
Let me answer the "why do you need individual class files?" question first. We have a rather large applet based application with a current client-side minimum jar download size of 1.8 MB. If we put ALL of our class files into jars, that size will probably double. Most users only use a small portion of the class files for their particular tasks. Which of the class files they use depends upon the tasks they perform. Having ALL users download ALL the classes, albeit compressed in jars, is extremely time consuming and a major problem after application updates due to the large number of users and the network load it would cause.
Jar file manifest:
Permissions: all-permissions
Codebase: *
Application-Name: MyApplication
Application-Library-Allowable-Codebase: *
Caller-Allowable-Codebase: *
Trusted-Library: true
We have 11 directories with one containing the applet and main client application code. The other 10 directories contain class files relating to the various sub-applications in the system. The system has a third-party runtime jar file, too.
We have a private network and servers for our business so the exposure is small. This is a screen-scraping, reformattring application that does no real data processing so doesn't need the same security as a true data processing application. Since we are not open to the Internet and of limited security risk, we chose to keep a more simplified structure.
This all worked under 1.7.0_45. I read the security guide and it was my understanding that these attributes in the manifest would also work for U51. Apparently not. Looking at the guides, now, it appears they have been changed sometime last year regarding mixed-code to mean jars with certificates and jars without certificates. The support for individual class files appears to have been removed. If this is true, then there should have been a beta of the U51 code because the rules seem to have been changed since the last release or there is a new bug.This is exactly my same problem. My app (and applet) is about 5 MB if I consider all the classes and libraries used by the app. (I mean 5MB is the size of the jar file). I can't ask customers to download 5 MB every time they want to access the program.
We need java ask code signing for the principal applet but then we must have the possibility to run single class files as needed.
Help us all please.
Thanks Paolo -
I have a Free Agent external backup hard drive connected to my iMac Intel desktop via USB, I never unplug it. Why do I get an error message, from time to time, upon startup stating, "Disk was disconnected improperly. Always eject disk before disconnecting."?
I never unplug the external harddrive, and the error message comes up only occassionaly upon startup. Maybe the USB connection gets disrupted enough to cause the computer to see it as disconnected and then reconnected while the iMac is powered.
-
Why do I get multiple windows of the same page?
Why do I get multiple pages under each other of the same website?
Ah I'm not alone its seems to be a recent 'issue'
-
Why do I get a humming noise from my stereo speakers when I plug in airport?
Why do I get a humming noise from my stereo speakers when I plug in my airport?
Temporarily, please turn off your amplifier and/or powered speakers and disconnect the plug that goes into the AirPort Express audio jack.
Plug a pair of headphones directly into the AirPort Express and listen for a few minutes.
Do you hear the "hum" that way? -
How do I get multiple return results from a function
IDBASKET IDSTAGE DTSTAGE
3 1 24-JAN-03
3 5 25-JAN-03
4 1 13-FEB-03
4 5 13-FEB-03
5 3 21-FEB-03
I input is a single IDBASKET number from this table and this function works fine only if it has one IDSTAGE per idbasket. (idbasket#5)
But how do I get it to return a result for an IDBASKET when it has multiple IDSTAGE? (idbasket#3 & 4)
THANKS MUCH,
MAT
SQL> CREATE OR REPLACE FUNCTION status_desc_sf
2 (p_code NUMBER)
3 RETURN VARCHAR2
4 IS
5 lv_output_txt VARCHAR2(30);
6 BEGIN
7 IF p_code = 1 THEN lv_output_txt := 'Order submitted';
8 ELSIF p_code = 2 THEN lv_output_txt := 'Accepted, sent to shipping';
9 ELSIF p_code = 3 THEN lv_output_txt := 'Backordered';
10 ELSIF p_code = 4 THEN lv_output_txt := 'Cancelled';
11 ELSIF p_code = 5 THEN lv_output_txt := 'Shipped';
12 ELSE lv_output_txt := 'No information';
13 END IF;
14 RETURN lv_output_txt;
15 END;
16 /Duplicate thread:
How do I get multiple return results from a function -
How is the java.lang.StringBuffer class different from the java.lang.String class?....
Read the API.
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html
"Strings are constant; their values cannot be changed after they are created. String buffers support mutable strings."
Although when possible you should use StringBuilder instead of StringBuffer.
Always read the API at the very least before asking questions in the forums. Ideally you should do some google searching and poke around for an answer too. Otherwise you will get people barking at you.
Drake -
Getting the class name from within the compiled class file
hey!
I was wondering (i know its possible) how to read a .class and get the name of the class. ok that made not much sense^^ so, You have a file: c:\f.class but it wont run because the file name has to be the same as the classes name, right? so how can you read the class file i guess in binary mode to receive the correct class name.
I saw inside my f.class i have "realname.java" so i know now that the name of the class file should be realname.class, i tried ways to extract it from the class file but never had any success.
i think i need to study english^^
ps: i need this because i have some class files sent to me and the file names have been changed so they wont work, they only work when i open the class file in notepad and find out what its real name should be and then rename the file.
Edited by: forgotmydamnpass on May 7, 2009 11:23 AMah looks interesting, problem is i cant use it.. im prone to errors!
import java.net.URLClassLoader;
public class NewMain {
* @param args the command line arguments
public static void main(String[] args) {
FileClassLoader loader = new FileClassLoader();
Class clazz = loader.createclass("c:\\f.class");
Method method = clazz.getName();
}apparently "createclass" doesnt exist :/
FileClassLoader = cannot find symbol
Method = cannot find symbol -
How to get an XML string from a Java Bean without wrting to a file first ?
I know we can save a Java Bean to an XML file with XMLEncoder and then read it back with XMLDecoder.
But how can I get an XML string of a Java Bean without writing to a file first ?
For instance :
My_Class A_Class = new My_Class("a",1,2,"Z", ...);
String XML_String_Of_The_Class = an XML representation of A_Class ?
Of course I can save it to a file with XMLEncoder, and read it in using XMLDecoder, then delete the file, I wonder if it is possible to skip all that and get the XML string directly ?
FrankI think so too, but I am trying to send the object to a servlet as shown below, since I don't know how to send an object to a servlet, I can only turn it into a string and reconstruct it back to an object on the server side after receiving it :
import java.io.*;
import java.net.*;
import java.util.*;
class Servlet_Message // Send a message to an HTTP servlet. The protocol is a GET or POST request with a URLEncoded string holding the arguments sent as name=value pairs.
public static int GET=0;
public static int POST=1;
private URL servlet;
// the URL of the servlet to send messages to
public Servlet_Message(URL servlet) { this.servlet=servlet; }
public String sendMessage(Properties args) throws IOException { return sendMessage(args,POST); }
// Send the request. Return the input stream with the response if the request succeeds.
// @param args the arguments to send to the servlet
// @param method GET or POST
// @exception IOException if error sending request
// @return the response from the servlet to this message
public String sendMessage(Properties args,int method) throws IOException
String Input_Line;
StringBuffer Result_Buf=new StringBuffer();
// Set this up any way you want -- POST can be used for all calls, but request headers
// cannot be set in JDK 1.0.2 so the query string still must be used to pass arguments.
if (method==GET)
URL url=new URL(servlet.toExternalForm()+"?"+toEncodedString(args));
BufferedReader in=new BufferedReader(new InputStreamReader(url.openStream()));
while ((Input_Line=in.readLine()) != null) Result_Buf.append(Input_Line+"\n");
else
URLConnection conn=servlet.openConnection();
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setUseCaches(false);
// Work around a Netscape bug
conn.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
// POST the request data (html form encoded)
DataOutputStream out=new DataOutputStream(conn.getOutputStream());
if (args!=null && args.size()>0)
out.writeBytes(toEncodedString(args));
// System.out.println("ServletMessage args: "+args);
// System.out.println("ServletMessage toEncString args: "+toEncodedString(args));
BufferedReader in=new BufferedReader(new InputStreamReader(conn.getInputStream()));
while ((Input_Line=in.readLine()) != null) Result_Buf.append(Input_Line+"\n");
out.flush();
out.close(); // ESSENTIAL for this to work!
return Result_Buf.toString(); // Read the POST response data
// Encode the arguments in the property set as a URL-encoded string. Multiple name=value pairs are separated by ampersands.
// @return the URLEncoded string with name=value pairs
public String toEncodedString(Properties args)
StringBuffer sb=new StringBuffer();
if (args!=null)
String sep="";
Enumeration names=args.propertyNames();
while (names.hasMoreElements())
String name=(String)names.nextElement();
try { sb.append(sep+URLEncoder.encode(name,"UTF-8")+"="+URLEncoder.encode(args.getProperty(name),"UTF-8")); }
// try { sb.append(sep+URLEncoder.encode(name,"UTF-16")+"="+URLEncoder.encode(args.getProperty(name),"UTF-16")); }
catch (UnsupportedEncodingException e) { System.out.println(e); }
sep="&";
return sb.toString();
}As shown above the servlet need to encode a string.
Now my question becomes :
<1> Is it possible to send an object to a servlet, if so how ? And at the receiving end how to get it back to an object ?
<2> If it can't be done, how can I be sure to encode the string in the right format to send it over to the servlet ?
Frank -
Question about multiple class files
I just started learning JAVA a couple of days ago and the first program I wrote had two classes in one file. here is the program :
class fib_num {
public int value;
public boolean is_even;
class Fibonacci {
/** Print the Fibonacci sequence for values < MAX and mark even numbers with an asterick */
private static final int MAX = 50;
private static final String Title = "The Fibonacci sequence for values less than " + MAX + ":";
private static fib_num[] fib = new fib_num[MAX];//This is actually an array of object
//references to objects of the fib_num class
public static void main(String[] args) {
System.out.println(Title);
//We must initialize each element of the array also !!!!
for (int i = 0; i < fib.length; i += 1) {
fib = new fib_num();
int lo = 1, hi = 1;
fib[0].value = lo;
fib[0].is_even = false;
fib[1].value = hi;
fib[1].is_even = false;
for (int i = 2; i < fib.length; i += 1) {
//create the next Fibonacci number and then save the previous Fibonacci number
hi = lo + hi;
lo = hi - lo;
fib.value = hi;
//now indicate if the Fibonacci number is even/odd
if (fib.value % 2 == 0) {
fib.is_even = true;
}else {
fib.is_even = false;
print (fib);
//This method prints an array of Fibonacci numbers
public static void print(fib_num[] array) {
if (array == null || array.length == 0)
throw new IllegalArgumentException();
String mark;
for (int i = 0; array.value < MAX; i += 1) {
if (array.is_even) {
mark = "*";
}else {
mark = "";
System.out.println((i + 1) + ": " + array.value + mark);
I ran the program and everything went fine. But today I started to write another program with two classes. However the file will not compile and I get an error about interfacing or something. here is the program:
Note: it's not nearly complete.
class enumerate {
//print out all permutations of a list of integers
public static final int MAX = 4;
public static int[] initialize(int[] nums) {
for (int i = 0; i < nums.length; i++) {
nums = i + 1;
return nums;
public static void print(int[] nums) {
for (int i = 0; i < nums.length; i++) {
System.out.print(nums);
System.out.println("");
public static void swap (int[] nums, int i, int j) {
int temp = nums;
nums = nums[j];
nums[j] = temp;
public static void main (String[] args) {
int[] list = new int[MAX];
list = initialize(list);
PermutationGenerator x = new PermutationGenerator(5);
// Systematically generate permutations.
import java.math.BigInteger;
public class PermutationGenerator {
private int[] a;
private BigInteger numLeft;
private BigInteger total;
// Constructor. WARNING: Don't make n too large.
// Recall that the number of permutations is n!
// which can be very large, even when n is as small as 20 --
// 20! = 2,432,902,008,176,640,000 and
// 21! is too big to fit into a Java long, which is
// why we use BigInteger instead.
public PermutationGenerator (int n) {
if (n < 1) {
throw new IllegalArgumentException ("Min 1");
a = new int[n];
total = getFactorial (n);
reset ();
// Reset
public void reset () {
for (int i = 0; i < a.length; i++) {
a = i;
numLeft = new BigInteger (total.toString ());
// Return number of permutations not yet generated
public BigInteger getNumLeft () {
return numLeft;
// Return total number of permutations
public BigInteger getTotal () {
return total;
// Are there more permutations?
public boolean hasMore () {
return numLeft.compareTo (BigInteger.ZERO) == 1;
// Compute factorial
private static BigInteger getFactorial (int n) {
BigInteger fact = BigInteger.ONE;
for (int i = n; i > 1; i--) {
fact = fact.multiply (new BigInteger (Integer.toString (i)));
return fact;
// Generate next permutation (algorithm from Rosen p. 284)
public int[] getNext () {
if (numLeft.equals (total)) {
numLeft = numLeft.subtract (BigInteger.ONE);
return a;
int temp;
// Find largest index j with a[j] < a[j+1]
int j = a.length - 2;
while (a[j] > a[j+1]) {
j--;
// Find index k such that a[k] is smallest integer
// greater than a[j] to the right of a[j]
int k = a.length - 1;
while (a[j] > a[k]) {
k--;
// Interchange a[j] and a[k]
temp = a[k];
a[k] = a[j];
a[j] = temp;
// Put tail end of permutation after jth position in increasing order
int r = a.length - 1;
int s = j + 1;
while (r > s) {
temp = a[s];
a[s] = a[r];
a[r] = temp;
r--;
s++;
numLeft = numLeft.subtract (BigInteger.ONE);
return a;
I thought the error had somethin to do with only having one class per .java file since the compiler creates a .class file. But how come my first program had two classes and it was OK. Is it b/c the second class was merely a collection of fields, almost like a simple struct in C?
Any help would be appreciated. ThanksMove the import java.math.BigInteger line to the start of the file.
Use the "[ code ] [ /code ]" tags around your code when you post, it makes reading it a lot easier.
Maybe you are looking for
-
New user - Some issues I want to resolve
I purchased my mac 2nd hand about 6 weeks ago (24" Mid 2007, 2.4GHz Core 2 Duo, 4GB RAM) and got it home and set it up and everything has been working flawlessly. Also purchased a magic mouse & trackpad which have also been working fine. I received a
-
[Solved] Found a Tripod Adapter for iPad
I've seen these tripod mounts for ipads used by apple themselves at demo setups. We purchased a few and they work great. The thing we like about them is that you can use it with your case so you dont have to take them off every time you want to use t
-
I tried to download the free IE version 9 available with yahoo as my home page(because it's easier for me to use.) It said my computer won't except that version but will take the Micro soft version 8, so I downloaded it that way. Now the home page wo
-
HT3060 right shift key not working
hello. Recently, my right hand shift key has quit working on my bluetooth wireless keyboard. Any suggestions? Software is up to date.
-
Remove navigation panel and the section says " you can fill out the following form"
Hi all, I need to remove navigation panel on the left side and also the section which is below toolbar and above actual pdf starts which says " you can fill out the following form and save the data. Can I hide or remove them using JavaScript? How? Re