Unchecked Or Unsafe Operations While Compiling Program?

Jun 30, 2014

String filename="C:UsersRajashekarDesktopfwfwdSoftware Failures1_Test.txt";//Input Files
String data;
public ArrayList<String> value=new ArrayList<String>();
public void read() throws IOException{
File f = new File(filename);

[Code] ....

View Replies


ADVERTISEMENT

Compiling And Running Program With No Main Class / How Is That Possible

Mar 22, 2014

I made a software using Netbeans and javaswing. Accidently i deleted my main file which contains my main class and main method. Just to test, i tried to compile and run and it worked but the style of my buttons and windows has changed. So, what happened? How can i change the style of my programs?

//File Accidently deleted
package time;
public class Time {
public static void main( String[] args ) {
Window wdow = new Window();
wdow.setVisible( true );
}
}

View Replies View Related

Illegal Start Of Expression Error When Compiling Program

Apr 11, 2013

class Test1
     {
     public static void main(String args[])
          {
          void show()
               {
               System.out.print("its working");
               }
          show();
          }
     }

When I compile this program i find the error illegal start of expression

^void show
Test1.java5 ';' is expected

View Replies View Related

Hiding Unsafe Methods Through Polymorphism

Feb 17, 2015

Recently I have been thinking of using additional interfaces in one of my libraries to hide certain "unsafe" methods of my classes from the user. I would like to get the opinion of other, more advanced java programmers on this issue.
What I do is something like the following (heavily simplified):

public interface ReadOnly {
public int getValue();
}
 public interface ReadWrite extends ReadOnly {
public void setValue(int value);

[Code] ....

The user would have access to the ExternalInterface. The ExternalInterface is controlling the values of the InternalComponent. The user can get the InternalComponent, but typecasted to a ReadOnly which does not expose the setters.

Now the thing is the user can still access the setValue method by typecasting the ReadOnly to an InternalComponent or to a ReadWrite, and that is not bad. If the user knows exactly what he/she is doing this will give him/her more flexibility and more power. But this way it *should* become obvious that this is not the intended use and perhaps the extra work of typecasting will discourage the user from doing this.

View Replies View Related

Why Narrowing Conversions Unsafe In Java

Nov 5, 2014

I had learned that narrowing conversion are called unsafe but unable to know why.

View Replies View Related

Casting To Parameterized Types And Unchecked Warnings

Jul 15, 2014

There is a sentence in JLS 7 which I can't figure it out. It says :

A cast from a type S to a parameterized type T is unchecked unless at least one of the following conditions holds:
-S <: T
-All of the type arguments (§4.5.1) of T are unbounded wildcards
-T <: S and S has no subtype X other than T where the type arguments of X are not contained in the type arguments of T.

Condition one and two I got it. But the number three is really bugging me. I write some code in order to try to understand it.

class G<X>{}
class D<T,U> extends G<T>{}
G<String> g = new G<>();
D<String, Integer> dd = (D<String, Integer>) g;

In Eclipse I got no warning but it shouldn't give one ?

Because g has others subtypes than D<String, Integer> (e.g. D<String, List> , D<String, G>)

Am I missing something about the contained type arguments ?

View Replies View Related

Basis For Making Exception As Checked Or Unchecked

Oct 10, 2014

I know checked exception need to be checked at compile time and runtime exception need not be checked at compile time.

My question is not related to the definition.

The question is on what basis have they selected that FileNotFound exception is a checked exception and NullPointerException is an unchecked exception? Is it the random wish of the creator or is there reason behind why something is selected as checked exception and something as unchecked?

View Replies View Related

Type Safety - Unchecked Cast From Object To LinkedList (EventData)

Feb 28, 2014

I am getting "Type safety: Unchecked cast from Object to LinkedList<EventData>" in eclipse for a piece of code stated below

public LinkedList<EventData> loadFromFile(File file) {
queue=new LinkedList<EventData>();
//Some piece of code
return (LinkedList<EventData>)queue.clone(); //--->getting warning here
}

I know that because clone() method is returning Object, hence compiler doesn't have type information that's why showing warning. I don't want to suppress this warning instead i want to fix it.

View Replies View Related

How To Count Primitive Operations

May 2, 2014

I have having some trouble on counting the primitive operations on the pseudocode given below:

Algorithm 4. MaximumArray(Arr)
Input: A 1-D numerical array Arr of size n
1) Let CurrentMax = a0
2) For i = 1 to n-1
3)If ai > CurrentMax Then CurrentMax = ai
4) End For
Output: CurrentMax, the largest value in Arr

As of now, I know that for Line 1 there are 2 operations (one set and one read). I don't know how to figure out the for loop and If statement (line 2 and line 3 too).

View Replies View Related

Nested Loops Or Set Operations?

Oct 10, 2013

Is there any advantage to using Java's operations defined in sets or collections over inspecting in nested for-loops?

For example, suppose I want to keep items from one array that do not appear in another, I could do:

for( PrimitiveType prim_1 : someArray ){
for( PrimitiveType prim_2 : otherArray ){
if( prim_1 != prim_2){
///put in some return list
}
}
}

Or else I could do:

ArrayList<NotPrimitive> excludedElements =
new ArrayList(Arrays.asList(primitiveArrayToExclude));
for( PrimitiveType elem : someArray){
if( ! excludedElements.contains( elem ) {
//put in some return list
}
}

I personally see no improvement in legibility nor any reduction of error potential.....

View Replies View Related

I/O / Streams :: Any Way To Parallel I/O Operations

Jul 31, 2014

I've been wondering about this for a while. Is there any way to parallel I/O operations or is this a bad idea? If you could create two lists of good and bad ways to parallelize I/O.

View Replies View Related

Using A Menu For Stack Operations

Dec 3, 2014

I am working on implementing a stack using a linked list. Programming the stack operations (push, pop, isEmpty, etc.) was easy but my directions were to provide the user with a menu to choose the operation that he/she wishes to perform. I am new to JFrames/Menus so how to make the stack operations available in a menu.

View Replies View Related

Illegal Start Of Operations For All Methods

Apr 21, 2015

Where are all these illegal start of operations and all of these other method errors coming from.I've written enough methods not to have this problem.

----jGRASP exec: javac -g Assessement.java
Assessement.java:29: error: illegal start of expression
public void addQuestionAnswer(){
^
Assessement.java:29: error: illegal start of expression

[code].....

View Replies View Related

How To Compute All Possible Arithmetic Operations Of 4 Integers

Nov 25, 2014

I'm new to Java and I want to write a program that compute all the possible arithmetic operations of 4 integers.

For example, if the user enter 1, 2, 3, and 4 respectively, then I want the computer to print out the following results:

1 + 2 + 3 + 4
1 + 2 + 3 - 4
1 + 2 + 3 * 4
1 + 2 + 3 / 4
..
1 / 2 / 3 / 4

(parenthesis can be ignored for this program)

This is what I have so far, but I don't know how to continue:

import java.util.Scanner;
public class ArithmeticComputation{
public static void main(String[] args) {
Scanner stdin = new Scanner(System.in);
int num1 = stdin.nextInt();

[Code] ....

I'm looking for a method that allows me to assign char into actual operators, so that I can loop through all the computation.

View Replies View Related

LISP Expression - Performing Operations

Jan 29, 2015

Given a LISP expression, perform operations on the expression. There will be no list elements that also contain a list such as '(A (B (C D))), which has one atom and one list but the list contains a sublist

INPUT: There will be 5 lines of input. Each line will contain a valid LISP expression. There will be a space between each atom and each list. There are no spaces immediately after or immediately before parentheses in a list. The entire expression must be inputted as a single string.

OUPUT: Perform the given operation on the like numbered expression. The 5 operations are:

1. Print the expression with the list in reverse order. The list will contain only atoms.

2. Print the expression with the list written with consecutive duplicates encoded as sublists in (count element) order. The list will contain only atoms.

3 Print the expression with the list written with consecutive duplicates encoded as sublists in (count element) order except that singletons are listed as atoms. The list will contain only atoms.

4. Print the expression with the list written with every Nth element deleted and where N is the last element of the list.

5. Print the expression written as 2 expressions where the number of lists in first expression is the last element of the expression.

SAMPLE INPUT SAMPLE OUTPUT
1. '(A B C D) 1. ′(D C B A)
2. '(A A A A B C C A A D E E E E) 2. ′((4 A) (1 B) (2 C) (2 A) (1 D) (4 E))
3. '(A A A A B C C A A D E E E E) 3. ′((4 A) B (2 C) (2 A) D (4 E))
4. '((4 A) (1 B) (2 C) (2 A) (1 D) (4 E) 2) 4. ′((4 A) (2 C) (1 D) 2)
5. '((4 A) (1 B) (2 C) (2 A) (1 D) (4 E) 3) 5. ′((4 A) (1 B) (2 C)) ′((2 A) (1 D) (4 E) 3)

View Replies View Related

What Are Interleaving Operations - Can Atomic Actions Interleave

Mar 24, 2014

I have read that when two threads have two steps (of execution) and each step involves many operations, then the operations of both the threads kind of overlap one-another. For example

I think I am not very clear about interleaving actions/operations? Especially when we say that atomic actions can not be interleaved. But

Java Code:

class Counter{
private int c=0;
void increment () {
c++;
}
void readIn () {

[Code] ....

And the following sequence of events occurs.

Thread A: Retrieve cThread A: Increment cThread A: Store the result in cThread B: Ask the user to enter a valueThread B: Read in the value, store it in c

Now the value of c obtained after increment will be lost (Thread Interference). Isn't this an example of interleaving operations?

View Replies View Related

JSP Calculator - Performing Basic Operations On Numbers

Jul 8, 2014

I want a simple jsp page that performs basic operations on numbers such as addition, subtraction, multiplication, division and modulus . How to run that file?

View Replies View Related

Queue Operations In Java - Using Reference As Pointer

May 28, 2014

I am trying to run the queue operations in java such as enqueue, dequeue using pointers ... How to use references as pointer in java.

View Replies View Related

JavaFX 2.0 :: Perform Boolean Operations On 3D Primitives?

Nov 10, 2014

How to perform boolean operations (union, intersect and subtract) on 3D primitives in javafx 3D?

View Replies View Related

Errors When Compiling

Nov 19, 2014

why my program doesn't work. Here's the code :

public test5 {
public boolean test(int grille[][]){
for (int i = 0 || i < grille.length || i++){
int max = grille[i][0];
for (int e = 1 || e < grille[i].length || j++){
if (grille[i][e]== max && max !=0){
solution = false;
System.exit(1);

[code]....

View Replies View Related

Swing/AWT/SWT :: How To Code Button That Get Selected Element From JComboBox And Perform Operations

Aug 6, 2014

i've spend an hour or two, pasting fragments from tutorials and nothing changed.

Well - i have GUI, that have JComboBox with two elements:
String[] fedoras = { "Fedora 19", "Fedora 20" };
JComboBox fedora_list = new JComboBox(fedoras);
fedora_list.setSelectedIndex(0);
fedora_list.setBounds(120,170, 170,25);
fedora_list.addActionListener(this);
this.add(fedora_list);

Below i have normal button (named Update) with "update" set as ActionCommand. This button after clicked should check which value from list is selected and perform different operations for that elements. But it's harder than i thought.

Code for update button:

public void actionPerformed(ActionEvent e){
String cmd = e.getActionCommand();
(...)
else if ("update".equals(cmd)){
String selectedFedora = (String) fedora_list.getSelectedItem();
if (selectedFedora.equals("Fedora 19")) {

[code]....

- after user clicked Update button, button should check which value is selected in JComboBox (fedora_list).
- if Fedora 19 is selected and button clicked, then action in Xterm
- if Fedora 20 is selected, this same action in Xterm is performed, but for Fedora Linux 20

The problem is - i don't know hot to code Update button to check which value from fedora_list (JComboBox) is selected and perform other actions for every element on List.

View Replies View Related

Simulate Simple Calculator That Performs Basic Arithmetic Operations Of JAVA

Sep 9, 2014

How can i write a java program that simulate a simple calculator that performs the basic arithmetic operations of JAVA. (JOption Pane and Repeat control structure)

Example : Addition, Subtraction, Multiplication, Division.

The program will prompt to input two floating point numbers and a character that represents the operations presented above. In the event that the operator input is valid, prompt the user to input the operator again.

Sample Output :

First number 7
Second number 4
Menu

<+> Addition
<-> Subtraction
<*> Multiplication
</> Division

Enter Choice: * <enter>

The answer is 28.

View Replies View Related

Compiling Java Application

Feb 27, 2015

So say I write up a program like a dice roll game, which I see on the forums here. It's all written and good to go and when I hit Run it does what I want it to do, no errors..What do I do with those .class and .java files? Do I compile it somehow into an app I can put on the google play store? What is the NEXT STEP after the program is all written?

View Replies View Related

Errors Compiling BeerSong

Feb 9, 2014

I get quite a few errors while trying to compile the BeerSong from the Head First Java book. I copied the text from another person that did the beer song on this forum and it worked as expected. What I can't figure out is why mine is not working when it looks like the text is exactly the same between the two versions. His works, but mine doesn't.

Here is the text and errors that I get:

public class BeerSong
{
public static void main (String[] args)
{
int beerNum = 99;
String word = "bottles";

[code]...

View Replies View Related

Third Overloaded Method Not Compiling

Feb 16, 2012

Create a class named Commission that includes three variables: a double sales figure, a double commission rate, and an int commission rate. Create two overloaded methods named computeCommission (). The first method takes two double parameters representing sales and rate, multiplies them, and then displays the results. The second method takes two parameters: a double sales figure and an integer commission rate. This method must divide the commission rate figure by 100.0 before multiplying by the sales figure and displaying the commission. Supply appropriate values for the variables, and write a main () method that tests each overloaded method. Save the file as Commission.java

b. Add a third overloaded method to the Commission application you created in Exercise 1a. The third overloaded method takes a single parameter representing sales. When this method is called, the commission rate is assumed to be 7.5% and the results are displayed. To test this method, add an appropriate call in the Commission program's main () method. Save the application as Commission2.java

COMMISSION.JAVA

public class Commission
{
public static void main(String[] args)
{
double Sales = 10000;
double commRate = 0.075;
int rate = 7;
computeCommission(Sales, commRate);
computeCommission(Sales, rate);
}
public static void computeCommission(double Sales, double commRate)

[code]....

View Replies View Related

Errors On Compiling But Not Showing In Eclipse?

May 6, 2015

I am watching BrandonioProductions on youtube. His videos are pretty good, but he doesn't seem to get errors where I get them. Here is an example.

public class compareUnequal {
public static void main(String[] args){
compareTwo();
}
public static void compareTwo(){
String x = "david";
String y = "Notdavid";
if (!x.equals(y)){
System.out.println("Not equal");
}
}
}

It runs ok, but asked me to proceed when there is an error, but I can`t figure out where the error is!

View Replies View Related







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