What's the simplest way of printing an array of primitives or of objects in Java? Here are some example inputs and outputs:
int[] intArray = new int[] {1, 2, 3, 4, 5};
//output: [1, 2, 3, 4, 5]
String[] strArray = new String[] {"John", "Mary", "Bob"};
//output: [John, Mary, Bob]
Generally, how does a java applet manipulate user data? Take for instance "shopping carts" on shopping websites - after a user enters the data, is the data then preloaded each time a user accesses a website? Or is the data retrieved as the user is on the page?
Hello,
I am a computer science Student Second year ,and i know good deal about c++,Data Structure, File Structure,OOP etc.
I decided to learn java i have read couple of books but i know u need practice to master any Programming language so i wonder if anyone could give me the assignments"only the questions not the solution" so that i could solve them as i am getting bored of "hello world"s and "3+2=5"s kinda stuff
thanks,
~HW
Hi,
I would like to open a webpage and run a javascript function from within a java app.
For example I would like to open the page www.mytestpage.com and run the following javascript code:document.getElementById("txtEmail").value="[email protected]";submit();void(0);
This works in a browser...how can I do it programatically?
Thanks!
From what I have gathered, I want to force a class to use particular private fields (and methods) I need an abstract class because an interface only declares public/static/final fields and methods. Correct??
I just started my first big java project and want to make sure I'm not going to hurt myself later :)
Hello,
In which case should you use primitive types(int) or complex types(Integer)?
Ex:
http://stackoverflow.com/questions/2508918/why-java-compiler-does-not-like-integer-as-type-for-values-in-hashmap this example works with Integer type. Should we always use Integer as a complex type?
I have a problem with java instanceof. I have a class called Employee and several others that extend this one, for example - Manager. I also created another class,EmployeeStockPlan, where I wanted to test if instanceof is finding which object I am using. But when I am calling a method from the new class, I have this error: The method grantStock(Manager) is undefined for the type Loader. Sorry, I am somehow new to some thing in java, I hope I am not asking dumb questions.
The Employee class:
package com.example.domain;
public class Employee {
private int empId;
private String name;
private String ssn;
private double salary;
public Employee(int empId, String name, String ssn, double salary) { // constructor
// method;
this.empId = empId;
this.name = name;
this.ssn = ssn;
this.salary = salary;
}
public void setName(String newName) {
if (newName != null) {
this.name = newName;
}
}
public void raiseSalary(double increase) {
this.salary += increase;
}
public String getName() {
return name;
}
public double getSalary() {
return salary;
}
public String getDetails() {
return "Employee id: " + empId + "\n" + "Employee name: " + name;
}
}
The Manager class:
package com.example.domain;
public class Manager extends Employee {
private String deptName;
public Manager(int empId, String name, String ssn, double salary,
String dept) {
super(empId, name, ssn, salary);
this.deptName = dept;
}
public String getDeptName() {
return deptName;
}
public String getDetails() {
return super.getDetails() + "\n" +
"Department: " + deptName;
}
}
The EmployeeStockPlan class:
package com.example.domain;
public class EmployeeStockPlan {
public void grantStock(Employee e) {
// nothing calculated, just simulating;
System.out.println("This is an employee!");
if (e instanceof Manager) {
// process Manager stock grant
System.out.println("This is a manager!");
} else {
// error - instance of Engineer?
System.out.println("Not an engineer!");
}
return;
}
}
The main class:
EmployeeStockPlan esp = new EmployeeStockPlan();
Manager m = new Manager (12421, "Manager1", "111-4254-521", 2430, "Marketing1");
grantStock(m);
I have an android app that I am trying to get a file path for a SAX parser. I have the following structure:
assets:(Where my xml file is)
src(same level as assets)
com
msi
androidrss(The calling java file is in here)
I tried several variations of this:
InputSource is = new InputSource("file://../../../../assets/Rss.xml");
But I always get a FNF Exception
Any suggestions?
Thanks
I am building an Android hello world application in Netbeans. It's building properly and I am to run in the emulator also.
But when creating and running the Junit test and running the test I get a java.lang.NoClassDefFoundError.
How can I fix this problem?
If I wanted a single word that meant "conforming to Java language conventions", what would that be? Python has the term "pythonic". Would it be "javaish"?
Hi all! I'm making an android program that retrieves content of a webpage using HttpURLConnection. I'm new to both Java and Android.
Problem is: Reader reads whole page source, but in the last while iteration it doesn't append to stringBuffer that last part.
Using debbuger I have determined that, in the last loop iteration, string buff is created, but stringBuffer just doesnt append it.
I need to parse retrieved content. Is there any better way to handle the content for parsing than using strings. I've read on numerous other sites that string size in Java is limited only by available heap size. I've tried with StringBuilder too.
Anyone know what could be the problem. Btw feel free to suggest any improvements to the code.
Thanks!
URL u;
try {
u = new URL("http://feeds.timesonline.co.uk/c/32313/f/440134/index.rss");
HttpURLConnection c = (HttpURLConnection) u.openConnection();
c.setRequestProperty("User-agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; InfoPath.1; .NET CLR 2.0.50727)");
c.setRequestMethod("GET");
c.setDoOutput(true);
c.setReadTimeout(3000);
c.connect();
StringBuffer stringBuffer = new StringBuffer("");
InputStream in = c.getInputStream();
InputStreamReader inp = new InputStreamReader(in);
BufferedReader reader = new BufferedReader(inp);
char[] buffer = new char[3072];
int len1 = 0;
while ( (len1 = reader.read(buffer)) != -1 )
{
String buff = new String(buffer,0,len1);
stringBuffer.append(buff);
}
String stranica = new String(stringBuffer);
c.disconnect();
reader.close();
inp.close();
in.close();
I have a relatively easy question. I have to create a java GUI to do math based calculations. I have to have a menu item that will double the variable that I am doing calculations with. For example
variable = 1
if radio button = selected{
variable = variable * 2
}
So, how would I achieve the if statement there?
thankyou
Hi there,
is it possible to access a shadowed field of an enclosing class from the enclosed one in Java?
public class Inherit {
public int a = 3;
private int b = 5;
public class Inheriting {
public int a = 23;
private int d = 8;
public void f() {
System.out.println("Here I want to get a = 3");
...
}
}
}
Cheers!
Hello everyone!
I have to make an on-screen keyboard using JAVA on linux.
the problem is it has to work on the most languages.
for start, i need to et the current locale, that's clear, but after that, is there any way of getting the keyboard layout and maping of that locale?
i searched for hours, but couldn't find a thing, so i really hope you can help me.
Thanks in advance, Adam!
Hi all, I need to calculate for grouping objects according to their size. I got k-means algorithms in java which calculate mostly for classifying according to their two or more features and the results are not satisfy for me.I only want to calculate for grouping objects based on one feature.Pseudocode or code would be helpful, too. Thanks u all for helping.
Hi
I have a java web application running on windows currently. I may host it in future in a Linux Server.
My application allows people to upload data. I want to display the data they have uploaded in an excel file and render it in a portion of my webpage.
How do I go about this ?
I want to create a TreeMap in Java with a custom sort order. The sorted keys which are string need to be sorted according to the second character. The values are also string.
Sample map:
Za,FOO
Ab,Bar
Hi
I need to visualize conceptual graph by using java
and I'm wondering if there any library that i can use to make my work easier?
Any advice?
Thank you so much
I have next to no programming experience, and absolutely none with Java, so I'm looking for some good online tutorials/primers. Please point me to good ones for beginners like me.
Thanks.
Can anyone recommend a web site that includes up to date performance tips for Java? Most of the sites I have found seem to be old and I guess the newer versions (1.5 - 1.7) may have obsoleted some recommendations.
What function does the "^" operator serve in Java?
When I try this:
int a = 5^n;
...it gives me:
for n = 5, returns 0
for n = 4, returns 1
for n = 6, returns 3
...so I guess it doesn't indicate exponentiation. But what is it then?