How Does Java Know Where To Import Classes From The Standard Libraries

Aug 19, 2014

I was wondering how Java knows where to Import classes from when we don't specify the whole directory path.

For example: import java.util.* Does It automatically search In both your current directory and the directory created during Installation that contains the standard library (wherever It may have been Installed) ?

View Replies


ADVERTISEMENT

File Import Which Is Not Standard Import

Apr 5, 2014

Usually, most of the time, I import the standard java stuff.But what happens when I find a code with a list of those com. imports:

import java.io.File;
import java.io.IOException;
import com.itseasy.rtf.RTFDocument;
import com.itseasy.rtf.text.Border;
import com.itseasy.rtf.text.Field;

Where are these imports and how do I "get" them?

View Replies View Related

Scanner Closed - Import Via Keyboard Numbers And Calculate Mean And Standard Deviation To Results

Oct 24, 2014

The purpose of this program is to import via keyboard Numbers.txt and calculate the mean and standard deviation to Results.txt.I am able to get the mean calculate but when I open the Results.txt the standard deviation is 0. I don't know what is wrong with my code, but I believe it has something to do with the scanner being close. Here is the error message i receive after inputting Numbers.txt.

java.lang.IllegalStateException: Scanner closed
at java.util.Scanner.ensureOpen(Unknown Source)
at java.util.Scanner.hasNext(Unknown Source)
at StatsDemo.main(StatsDemo.java:48)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at edu.rice.cs.drjava.model.compiler.JavacCompiler.runCommand(JavacCompiler.java:272)

Java Code:

import java.text.DecimalFormat; //for number formatting
import java.util.Scanner; //for keyboard input
import java.io.*; //for using files
public class StatsDemo
{
public static void main(String [] args) throws IOException

[Code] .....

View Replies View Related

Swing/AWT/SWT :: Extending Classes And Importing Libraries Basics?

Mar 12, 2015

1. Tried to use setLayout() but it wouldn't let me. Have imported libs

import javax.swing.*;
import java.awt.*;

but it doesn't work. It only worked when I extended a class with JFrame. Why do I have to do it? I already have a JFrame instance:

public test(){
JFrame frame = new JFrame();
frame.setTitle("Workshop");
frame.setBounds(500,300,400,300);
frame.setVisible(true);
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
....
}

This code runs smooth, so it's confusing for me that it lets me create a JFrame object, and put buttons onto it, but it wants me to extend the class onto JFrame class in order to use a method.

2. I've read somewhere that AWT is old and should not be used anymore. Is there a diagram or a list with objects and properties that are manipulated only by Swing so that I could concentrate only on those? For example (made up list):

JPaper -

- width, setWidth(x)
- height, setHeight(x)
- position, setPosition(x,y)
- color, setBackground(RGBa)
- acquire, add(subordinate component)
- deprive, remove( subordinate comopnent)
- etc...

JSticker -

- width ...
- height ...
- write, setText(String)
- etc...

View Replies View Related

How To Import / Access Classes Created In One Package In Another Package

Apr 30, 2014

My working directory is e:ajava. in package p1 i create two classes c1 and c2. net beans creates three files e:ajavap1srcp1, e:ajavap1srcc1, e:ajavap1srcc2. package runs without a hitch. i create another package p2 under e:ajava. i want to use class c1 in p2. pray what on earth should be my import statement in the p2 source code after the first statement 'package p2'. another related querry what should i include in my class path so as to gain access to c1 and c2 in source code of p2.

View Replies View Related

NoClassDefFoundError With Java Standard Platform Class?

Feb 18, 2015

I am facing NoClassDefFoundError with one of the java standard platform class (java.text.DigitList$1)

java.text.DigitList class is part of rt.jar so it should not create any issue as such.

I am using Java 1.6.0_06

StackTrace:
Unhandled exception java.lang.NoClassDefFoundError: java/text/DigitList$1
at java.text.DigitList.shouldRoundUp(DigitList.java:4 11)
at java.text.DigitList.round(DigitList.java:363)
at java.text.DigitList.set(DigitList.java:351)
at java.text.DigitList.set(DigitList.java:272)
at java.text.DecimalFormat.format(DecimalFormat.java: 584)
at java.text.DecimalFormat.format(DecimalFormat.java: 507)
at java.text.NumberFormat.format(NumberFormat.java:26 9)

View Replies View Related

Handling Button Events In Eclipse Standard 4.4 / Java?

Jul 20, 2014

Code:
package button;
import javax.swing.*;
import java.awt.event.*;
public class Actions extends JFrame implements ActionListener
{
JPanel pnl = new JPanel();

[Code] ....

Errors:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The type Actions must implement the inherited abstract method ActionListener.actionPerformed(ActionEvent)
event cannot be resolved
event cannot be resolved
at button.Actions.<init>(Actions.java:4)
at button.Actions.main(Actions.java:9)

View Replies View Related

Incorporating Java Libraries?

Mar 11, 2014

I am responsible for an application which the developer did not build with ANT and also, he had the libraries sitting on his local machine.

Do you have any recommendations on what I should do with these libraries, knowing they were parcelled out and sitting on his local machine instead of in the project itself (Eclipse IDE workspace)?

I am building a script in ANT but don't really know what to do with his libraries. I did get a bunch of compilation errors earlier when I did not have the libraries, but now that I have them, I don't really know where to put them.

View Replies View Related

JAVA Calculator - Equals Method To Return Appropriate Value Using Standard Arithmetic

Apr 18, 2014

I am having trouble using the equals method to return the appropriate value using standard arithmetic.

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

[Code] ....

I know that "inText.setText(Integer.toString(secondOperand));" in the code is wrong, I just don't know the right code...

View Replies View Related

Java B-Tree Insert (no Libraries)

Apr 11, 2014

My task is to implement a B-Tree data structure in Java using no libraries.

My current problem is inserting when the root is full, thus the middle key goes to root.keys[0] and then it get the left and right side which are new Nodes separating and inserting their keys. My problem is that for some reason there is a random second number when in the root and secondly my boolean leaf is always false meaning it never detects that the Tree is deeper than root.

The coding makes sense to me and I have tried printing everywhere but still can't seem to find the problem.

public class BTree {
/*
1. You may not modify the public interface of this class. You may however add any additional methods and/or field which you may require to aid you in the completion of this assignment.
 
2. You will have to design and implement a Node class. The BTree should house Integer objects.
 
3. You will notice that there are some overloaded methods, some of which work for Integer objects and some with primitive type int. You have to find a way to implement the methods to work with both types.
*/
 
class BTreeNode { 
boolean leaf = true;
int numKeys = 1;
int mOrder;
Integer keys[];

[Code] ....

View Replies View Related

Java B-Tree Insert (no Libraries)

Apr 11, 2014

My task is to implement a B-Tree data structure in Java using no libraries.

My current problem is inserting when the root is full, thus the middle key goes to root.keys[0] and then it get the left and right side which are new Nodes separating and inserting their keys. My problem is that for some reason there is a random second number when in the root and secondly my boolean leaf is always false meaning it never detects that the Tree is deeper than root.

The coding makes sense to me and I have tried printing everywhere but still can't seem to find the problem.

public class BTree {
/*
1. You may not modify the public interface of this class. You may however add any additional methods and/or field which you may require to aid you in the completion of this assignment.
2. You will have to design and implement a Node class. The BTree should house Integer objects.
3. You will notice that there are some overloaded methods, some of which work for Integer objects and some with primitive type int. You have to find a way to implement the methods to work with both types.
*/

class BTreeNode {
boolean leaf = true;
int numKeys = 1;
int mOrder;
Integer keys[];

[Code] ....

View Replies View Related

Java Import Not Working In Package?

May 20, 2015

I am trying to understand the package and import functions.

The path to access the file " library.book" is

C:UsersKameshDesktopJava SessionJAVAOCA7ooklibrary

and i can see 3 txt files

Book.class
Book.ctxt
Book.java

while compiling i am getting <identifier>expected error.

Here is the code :

package library;
public class Book {
public String isbn;
public void printBook() {}
}
package building;

[Code] .....

The error i get is <identifier>expected.

View Replies View Related

Objects And Links - Import Database To Java Pane

Nov 23, 2014

I would like to import database to the Java pane and connect objects to each other and want to display their information as visually. How can i do.

View Replies View Related

Reading From Standard Input?

Jun 20, 2014

I have to write sorting algorithm for numbers given on standard input(console) with following requirements:

The application must remember the distinction between double and integer numbers. This must be evident in the sorted output. Double type numbers are written using a period (.) to separate the fraction from the whole part.

The problem is I don't know how to efficiently distinct whether something is an int or double on standard input, to save them into 2 different arrays.

Only idea I've come to so far is to read each number as String and check if it has '.' character, to figure out if it's double and than convert it into right type and add it to correct array.

Also thought that maybe this would be achieveable using Pattern but how to do that?

View Replies View Related

Java Application With Several Classes All In Same Java File

Apr 9, 2015

I've written a java application with several classes all in the same .java file. It works just fine. Now, I've broken it up so that each class has its own .java file. Still works fine. My next step is to put those classes into a package, but I'm not about to get the program to run.The .java source files are all in /home/user/src

I've set the CLASSPATH to /home/user/src..All of the source files have "package com.myfirm.program" on the first line.I compiled the application with:

javac -d . File1.java File2.java File3.java (etc...)

the compiler created the directory: /home/user/src/com/myfirm/program and put all of the .class files in there.So how do I get the program to run? if I run from /home/usr/src

java File1

I get: Exception in thread "main" java.lang.NoClassDefFoundError: File1 (wrong name: com/myfirm/program/Program)

View Replies View Related

Standard Deviation - Round To 10s Place

Dec 2, 2014

for standard deviation my output is not rounded to the 10's place, how can I make it round to the 10's place. Here is my code.

import java.util.*;
public class chapter7 {
public static final int Max_Number_Scores = 100;
public static int fillArray(double[] scores) {
System.out.print("You entered ");
for (int i = 0; i < scores.length; i++) {
System.out.print(scores[i] + " ");

[code]....

View Replies View Related

When To Use Inner Classes In Java

Jan 19, 2015

Wondering, what is exactly reason for existence of inner classes? Are there problems that without them you can not resolve?

Anything beside emulate multiple inheritance - when your class need to extends the real classes, and not implement multiple interfaces ?

View Replies View Related

Many Errors Calculating Mean / Variance And Standard Deviation

Apr 28, 2014

It may be (it is highly likely) possible that I have royally stuffed this up. I am attempting to write a program that asks a user for a file name, gets the number of entries and if there is more than one entry calculate the mean, variance and standard deviation. This is my code so far:

/* Calculate contains methods that determines the number of data entries in a file, and calculates the mean, variance and standard deviation of this set
*
************************************************************************/
import java.util.Scanner;
import java.io.*;
public class Calculate {
public static void main(String[] args) throws IOException {
// Create a Scanner object for keyboard input.
Scanner keyboard = new Scanner(System.in);

[Code] ....

The errors I am getting are:

Calculate.java:67: error: ';' expected
mean += mean/String filename;
^
Calculate.java:67: error: not a statement
mean += mean/String filename;

[Code] ....

11 errors

Although I am sure there are many more to come.

View Replies View Related

Purpose Of Java Inner Classes

Jan 19, 2015

What is exactly reason for existence of inner classes? Are there problems that without them you can not (or be very hard to) resolve? Anything beside emulate multiple inheritance, when you need to extends the real classes ( not implements multiple interfaces) ?

View Replies View Related

Netbeans - Application To Send And Receive Data Via RS 232 Standard

Mar 2, 2014

I'm using netbeans to develop an application to send and receive data via RS 232 standard. I can send data but I can't read it.what can I do? I have this message in the console: Underlying input stream returned zero bytes. (I must use also threads to have application in real time but I don't understand very well....

View Replies View Related

Compute Standard Deviation For A Set Of Numbers - ClassCastException Being Thrown?

Apr 20, 2015

Basically I'm trying to compute the standard deviation for a set of numbers and I'm using previously know data to compute this. The data I'm working with is here (note all of this is fake as its for an assignment):

Id,First Name,Last Name,Quiz1,Quiz2,Quiz3,Lab1,Lab2,Assignment1,Exam1,Exam2
58136,Wade,Andrews,5,8,2,2,20,47,20,40
59759,Jacqueline,Simmons,9,4,1,16,13,2,82,41
28056,Frederick,Castro,8,0,6,3,6,29,53,63
15532,Annette,Myers,2,6,0,14,13,4,77,43

Next this is the code that I know is producing the error:

/**
* Pass in original data from files, and pass in computed grades as arraylist. this returns all of the standard deviations to be printed
*/
public static ArrayList calcStandDev(String data1[], ArrayList<Double> grades, ArrayList<Integer> averages)
{
double standDev = 0;
int j = 0;
//gets rid of first element in string array, makes processing MUCH easier
String[] data = Arrays.copyOfRange(data1, 1, data1.length);
 
[Code] ....

Look for the line with all the ***'s, it is producing the "java.lang.ClassCastException: java.lang.Double cannot be cast to java.lang.Integer".

The reason I dont undersand why its producing this error is because temp.get(i) should be a integer - averages.get(i) (is type double), I do believe automatic up casting is present here making them both a double then I multiply it by itself producing a double? I dont understand where the casing is occurring. And just incase you want the formula I'm using for standard deviation here it is:

((x1 - ave)^2 + (x2 - ave) ^2 + (xn - ave) ^ 2) / (n-1)

then squareroot above

Why I'm getting this error! I tried changing a few dataTypes but I just cant avoid exceptions being thrown everywhere .

View Replies View Related

How To Use External Libraries

Dec 23, 2014

I need to build an application that can preform measurements. So I have a measuring device that can be connected through USB (with a rs232 converter aka VCP).The manufacturer provided me with two libraries:

C++ : a library (.lib) file and a header (.h) file
VB6 : a DLL (.dll) file and a list (.txt) with all the available functions

And also some demo code. Can't get the C++ code running with my Borland C++ 5.5 compiler but the VB6 code is working.What can I use to integrate into my java code.

View Replies View Related

How To Add Libraries To JCreator

Nov 18, 2014

I've been trying this for hours but it's not working. I'm trying to add the sea glass look and feel library to my project but I still get the error:

Exception in thread "main" java.lang.NoClassDefFoundError: List (wrong name: list)

What should I do? I've added the library to "project settings >Required Libraries" and did not forget to check the box. I've also imported the L&F so it can't be that.

View Replies View Related

OMR Class Libraries

Nov 22, 2011

I'm researching the viability of a project. One of the requirements is that a "play slip" will be used to read input. I've searched for open source Java libraries that utilize OMR's (optical mark reader) but to no avail. I have located a C library that fulfills the task- is there a way in Java to access/use non-native language libraries?

View Replies View Related

Interface And Abstract Classes In Java?

Jun 4, 2014

why don't I define my methods in a class, rather than going a level up and declaring it first in an abstract class/interface? If the point is to have different implementations for different needs, then we have the option to override the methods.

View Replies View Related

Does Java Extend 2 Classes At One Time

Feb 7, 2014

1) when you create a class and compile it and open and see the class using javap command .. that class file contains that it extends java.lang.object and a default constructor is created automatically..... But when you extends another class the java.lang.Object class is not appeared as extended why?

Code example:

1St Case ----- Java code:

public class temp(){
}

Javap Code:
public class temp() extends java.lang.Object {
public temp(){
}
}

2nd case --- Java Code:
public class temp() extends dummy{
}

javap Code:

public class temp() extends dummy{
public temp(){
}
}

why for the above scenario it doesn't extends object class .. if it does implicitly then why it did not do in the first case instead why did the compiler extends Object class ?

View Replies View Related







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