Java is a high-level, platform-independent, object-oriented programming language originally developed by Sun Microsystems. Java is currently owned by Oracle, which purchased Sun in 2010.

learn more… | top users | synonyms

-1
votes
0answers
102 views

How do i wait for all threads in java code here? [migrated]

I would like to compare thread performance on solaris/linux/windows 64 bit JVM's, with the below code. I personally, prefer this style of coding for threading, because you have a method performing ...
0
votes
3answers
168 views

Building a calculator using MVC

I've been programming in Java for about 6 months, and I thought a good and challenging test of my skills would be to build a GUI calculator. I have very recently heard about this MVC idea, and I ...
0
votes
2answers
81 views

Managing multiple JDBC connection

I have an application that connects to databases based on a json string that contains connection information. The json is sent just when the application starts. How do you manage such connection ...
0
votes
1answer
135 views

Is Default Package included in the Package Level Access?

I would like to know how the default package is defined in Java.I know how public and private access is defined but I don't know whether there is any default package access that is defined in package ...
-1
votes
1answer
180 views

Whether Methods could be defined in Constructors in Java? [closed]

I am learning to program in Java and have run into a situation I don't understand. I have this code import java.io.*; class temp { temp() { Finish f=new Finish(); f.end(); } ...
-2
votes
0answers
146 views

Trying to create the simple 24 game in java, I have some code but I need to reverse it [duplicate]

I am trying to create the 24 game in java and I found some code that does what the game is supposed to do. This code give the user 4 numbers and the user then has to put them into an equation to equal ...
-3
votes
1answer
61 views

Why are there just a few implementations of a Java EE container? [closed]

I see at the JCP that work on Java EE 8 is allready in progress, as Java EE 7 was released almost 1,5 year ago. However, as far as I know there are only three implementations of the Java EE 7 ...
0
votes
0answers
7 views

What is first argument in 'JOptionPane.showConfirmDialog() here? [migrated]

Here is the below code snippet, where i would like to display the dialog using JOptionPane.showConfirmDialog() by setting its parent as resultsTablePanel: public class SearchResultsTablePanel extends ...
-4
votes
1answer
114 views

What is immutable by default in Java? [closed]

While trying to grasp copying/copy constructors, and noticed that some things seem to be immutable by default (Strings, and Integers), while everything else is mutable by default. That leaves me ...
3
votes
2answers
118 views

What preconditions should be checked while adding/removing a listener?

Imagine the following interface: interface Service { addListener(Listener l) removeListener(Listener l) } Should I check for null values while add/remove? Is it a good idea on remove to ...
3
votes
0answers
106 views

What is the advantage of 'SwingUtilities.invokeLater()' method?

For the below sample GUI program using javax.swing, public class UnResponsiveUI extends JFrame{ private boolean stop = false; private JTextField tfCount; private int count = 1; /* ...
0
votes
2answers
185 views

Using Constructors in Java

I would like to know why do we need to use constructors in examples like this:http://math.hws.edu/eck/cs124/javanotes5/c5/s2.html. I think even if there are no constructors the programs mentioned in ...
0
votes
0answers
22 views

What does 'name' attribute signify in any java.awt component?

With the below program, am trying to find the names assigned to all the components part of the GUI. public class AWTCounter extends Frame implements ActionListener{ private Label lblCount; ...
-2
votes
0answers
28 views

Why 'JRootPane' is-a 'JComponent' in javax.swing? [duplicate]

As per below code, I see that, setLayout() is being called on a JRootPane object instead of JFrame top level container in javx.swing world unlike java.awt, because it is told that swing's JFrame is ...
1
vote
1answer
94 views

Java App as Tomcat Service?

I currently have a basic j2ee website. Currently, a jsp frontend gets data from the backend (the java program, lets call it object "Score"). The backend gets this data from a web site. <% Main m ...
3
votes
1answer
89 views

Why 'JButton' is-a 'Container' in javax.swing?

As per the class hierarchy in java.awt.*, class Button & class Label is-a class Component, and Component is not a Container, which make sense to me. As per the redesign of class hierarchy in ...
0
votes
1answer
20 views

Query on usage of 'Window()' default constructor from java.awt

I had been through this query before asking this question. In class Window we have constructor with default direct access level package private but not private as shown below: Window() throws ...
1
vote
4answers
127 views

Is there an alternative to instanceof when filtering a Java stream by class?

I have an unexpected situation in a project in which all types extending one class are packed into a Java collection; but only a specific extension of that class contains an additional method. Let's ...
3
votes
1answer
163 views

Type Casting in Java

Could anyone explain why short(100000) is -31072 as said in p.48 of java-notes.The article says that "the value -31072 is obtained by taking the the 4 byte int 100000 and throwing away two of these ...
1
vote
2answers
164 views

Most Efficient way to Compute the sum of divisors of N (1 ≤ N ≤ 1 000 000 000)

I want to write a code which computes the sum of divisors of a number N(1 ≤ N ≤ 1 000 000 000), excluding the number itself. However, I need an efficient way to do it. It suppose to print the answer ...
1
vote
2answers
52 views

Query on Recursive composition

For the below relation between Container and Componentin java.awt class hierarchy, I see that, in addition to is-a relation, class Container has composite relation with class Component with below ...
0
votes
1answer
76 views

Does class Availability makes programming as Object Oriented Language? [duplicate]

Does class Availability makes programming as Object Oriented Language ? Most of the people think that if there is Availability Class in a language, then that language becomes Object Oriented. Is it ...
2
votes
2answers
188 views

architecture of database heavy application

A program I'm currently designing is extremely database heavy, almost anything the user does will alter the database, or read from it. Now I have one interface which defines all these operations, and ...
0
votes
1answer
99 views

Starting Execution of Java Program [duplicate]

While reading about Java Programming I couldn't get why it states Java static main necessity reason is because "before you're program starts,there aren't any objects to send messages to" as said in ...
0
votes
6answers
226 views

Why 'String' objects are immutable with an explicit constructor in java? [duplicate]

It make sense to make class String objects immutable with following declarations, because they share the same storage in common pool. String str1 = "abc"; String str2 = "abc"; But, am not sure, if ...
0
votes
0answers
9 views

What is meant by end of stream reached in inputstream.read()? [migrated]

my android smartphone is tcpclient and chipkit wf32 wifi module is my tcp server. int bytesRead; InputStream inputStream = socket.getInputStream(); while ((bytesRead = inputStream.read(buffer)) != ...
0
votes
2answers
265 views

Where is it specified that Java is call by value?

I know that Java is by default call-by-value but I am not sure where in the Java Language Specification this is addressed. Google searching only seems to find me unofficial sources but never points to ...
0
votes
0answers
32 views

Transaction Management in Hibernate with DAO Design Pattern

I have many Tables, For every Table,we have DAO Interface and DAOImplementation class. Example DAO Interface public interface CancelPolicyDAO { public CancelPolicy insertCancelPolicy(CancelPolicy ...
1
vote
2answers
168 views

Are there other ways to limit recursion depth for a function?

I am trying to prevent a function/method (in Java) from performing recursion more than a depth of 3 self calls. I've learnt about the accumulator trick from odersky's scala coursera course. public ...
11
votes
4answers
561 views

Why shouldn't a method throw multiple types of checked exceptions?

We use SonarQube to analyse our Java code and it has this rule (set to critical): Public methods should throw at most one checked exception Using checked exceptions forces method callers to ...
2
votes
1answer
88 views

Simple and Composite transactional services: Question about separation of concerns and transactions

I believe I know the answer to this but I'm looking for any holes or anything I may be missing. This is focused on Spring and Java but could really apply to any programming stack. Anyway, we have a ...
0
votes
0answers
22 views

Design architecture and software for webapp integrating with few other endpoints (Email Server, Jira, CRM system)

In my upcoming project, I need to integrate a webapp with few other endpoints. Main duty of the webapp will be some kind of thin-client for inner JIRA system for company. Moreover, I'll need to ...
0
votes
2answers
89 views

Java Web Application in Cluster with Shared Database. How to Negotiate an Instance to do Updates? How to Notify Instances of Updates? [duplicate]

I have a Java web application, running in a cluster of Tomcat application servers and a shared SQL/JDBC database. Data from the database is cached in memory in each instance of the web app. My web ...
0
votes
4answers
221 views

How to ensure objects unique by equality?

I frequently have this problem but didn't find it as an established programming pattern. I have some Class C whose equality is determined by some key k and I want to prevent time-consuming ...
1
vote
2answers
128 views

Can I use US-ASCII and UTF-8 encoding interchangeably for an XML file without a XML root declaration?

My source XML does NOT contain the root declaration i.e. <?xml version="1.0" encoding="utf-8" ?> And when I run the file command on it, I get: ASCII text, with very long lines, with CRLF ...
0
votes
1answer
121 views

calculating the average of a value over a month [closed]

I am working on a project right now that is having me calculate monthly interest on a bank account. The way the interest is supposed to be calculated is as follows: Use the daily average to calculate ...
0
votes
1answer
186 views

Did Java avoid multiple inheritance here?

I learnt that Java did not allow multiple inheritance using abstract classes for simplicity. In java, after a good design of class hierarchy, SubType would not get into trouble of same method ...
0
votes
1answer
183 views

Why does this evaluation function work in a connect four game in java

I am exploring how a Minimax algorithm can be used in a connect four game. I was looking through a program and found this evaluation function. private static int[][] evaluationTable = {{3, 4, 5, 7, ...
1
vote
4answers
162 views

Java exception handling design

I am trying to design a simple exception handling strategy for web services middleware using some ideas from here: http://northconcepts.com/blog/2013/01/18/6-tips-to-improve-your-exception-handling/. ...
2
votes
2answers
141 views

Passing by value multiple times vs. Creating a public class variable

Suppose I have a series of methods across different classes that all use the same five core variables defined in my main method. I could chain these five variables as method arguments from one method ...
0
votes
3answers
209 views

I want to understand clearly why can't we instantiate an object of an abstract class [duplicate]

Can I get a clear explanation why why can't we instantiate an object of an abstract class. I know abstract is not real. But I want to know more why can't we instantiate an object of an abstract class. ...
0
votes
0answers
69 views

What is the best way to implement a workaround for Log4J's DailyRollingFileAppender issue on Windows? [migrated]

I understand that there is an open bug with Log4J 1.2.x because (apparently) the java.io.File.renameTo() function fails due to a OS lock on the log file, which causes the file not to be renamed. I ...
4
votes
3answers
229 views

Batching immutable object changes?

With immutable models, what would be the best way to batch several changes? For example, let's have a Book that is immutable. I need to change both title and year. I could change one by one, but that ...
0
votes
3answers
248 views

Java 1.7 library with a Java 1.5 program - what are the options

I have a class library which is compiled with JDK 1.7 It uses several 1.7 features and classes and would be very difficult to get it recompiled in JDK 1.5. This needs to integrate with an old legacy ...
-5
votes
1answer
95 views

Help Understanding This? [closed]

I'm using the book Heads First Java and I just don't understand it at some parts and the book doesn't explain it well enough. Could someone please tell me what each line does? public class whileloop ...
3
votes
1answer
66 views

Skeletal/Abstract class just to store shared state?

Given an interface for the Strategy pattern like so: public interface Strategy { public Output execute(Input input); public Output getLastExecutionOutput(); } if I want to store the last ...
-5
votes
1answer
103 views

What is the purpose of Deprecation? [closed]

Is it just giving different names to previously named method? Does it change with the language you use? Is it essential? I have noticed different APIs having deprecated methods, which actually seem ...
1
vote
0answers
73 views

How to pass control between sub-controller to parent controller in Java MVC Design Pattern?

I'm pretty new in Java, but I've done plenty of research and I know what MVC is. However, to implement MVC in Java was a difficult task. I followed this tutorial, which helped me to realise that the ...
0
votes
1answer
111 views

How do different technologies connect to form a web stack? [closed]

I am a little confused, is it possible to implement a front end using common languages like html, css and javascript and then do server side processing using a language of your choice, say python or ...
5
votes
2answers
303 views

Why can't I understand Java? [closed]

I'm a 9th grader and I joined my school's robotics team in order to learn how to code Java and enter the programming team. However, I am so confused! Even after the first lesson, I had no idea what ...