How to/What is a good library, to create a fading indicator message in Java like that of Outlook when you get a message, or Ubuntu/Gnome when you've connected to a network?
Is it possible to get a reference to this from within a Java inner class?
i.e.
Class outer {
void aMethod() {
NewClass newClass = new NewClass() {
void bMethod() {
// How to I get access to "this" (pointing to outer) from here?
}
};
}
}
Given the following code:
public class Test {
public void method(Object o){
System.out.println("object");
}
public void method(String s) {
System.out.println("String");
}
public void method() {
System.out.println("blank");
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Test test=new Test();
test.method(null);
}
}
Java prints "String". Why is this the case?
This question showed up on my mid-term exams and I've been searching for correct answer for some time. I know that Java interfaces can't be directly instantiated so they don't need constructors and that they can have only public static final attributes so they don't need constructors to set them up but that's not the expected answer.
What's the easiest way to create a simple HTTP server with Java? Are there any libraries in commons to facilitate this? I only need to respond to GET/POST, and I can't use an application server.
What's the easiest way to accomplish this?
Please advise me the difference between two ways of declaration of java constructor
public class A{
private static A instance = new A();
public static A getInstance() { return instance;
}
public static void main(String[] args) {
A a= A.getInstance();
}
}
AND
public class B{
public B(){};
public static void main(String[] args) {
B b= new B();
}
}
Thanks
I need a java program to get the current date without timestamp
Date d = new Date();
gives me date and timestamp
But i need only date, without timestamp. I use this date to compare with another date object that does not have timestamp.
on printing
System.out.println("Current Date : " + d)
of d it should print May 11 2010 - 00:00:00 .
I have created a Java Swing application. It works fine.
I have created application file (.app) for that application using jar bundler.
But the main problem is that my application does not open if I click it on the Dock. I am using Mac OS. How I can launch my application by clicking on Dock
Thanks
Sunil Kumar Sahoo
During navigation of Method class I came across the function isBridge(), javadoc of which says, that its true only if java spec declares the method as true.
Please help me understand what this is used for ? Can a custom class declare its method as a bridge if required ?
I'm in the process of weeding out all hardcoded values in a java library and was wondering what framework would be the best (in terms of zero- or close-to-zero configuration) to handle run-time configuration? I would prefer xml-based config-files, but it's not essential.
Please do only reply if you have practical experience with a framework. I'm not looking for examples, but experience... Thanks for taking the time.
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]
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();
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!
Hi,
I would like to know if its possible to deploy java class files without restarting JBoss server. I am using jboss v4.2.2.
Also, when I try to deploy jsp files, it works fine and server picks up the changes almost instantly.
Thanks a lot in advance :)
Hi i'm working in task queue concept.... First i struggled to program using task queue and i asked many doubts in stack overflow and Google app engine java. After a search i got a sample program for task queue. http://gaejexperiments.wordpress.com/2009/11/24/episode-10-using-the-task-queue-service/ It will very useful for beginners Like me.
Regards,
Sharun.
Hey guys;
I have a url which leads to in image. How do i grab this image from this url into my servlet? NOTE: the web-app is deployed on google app engine.
java.net.URL myURL = "http://a3.twimg.com/profile_images/150131301/slogo4_normal.jpg";
//code to grab the image
Thank you
I am about to start developing an Android application and had a question if in Java there self naming. For instance say I had a variable named dog that held the value of scruffy.
Could I then create a variable named scruffy from that variable. In PHP it would be $$dog. That would make a variable with the name scruffy.
If this is possible please provide example
Hi,
I am developing an application in Netbeans, and it is using JavaDB. I can connect to it and execute queries without issues, but for some reason, the "Output - JavaDB Database Process" pane within Netbeans keeps displaying
Security manager installed using the Basic server security policy.
Could not listen on port 1527 on host localhost:
java.net.BindException: Address already in use
How do I find out what process is already using, or bound to, that port number?
if you wanna code a desktop application in java for windows, mac and linux, will the code be the same for all of them?
and you just change the GUI so that the Windows application will be more Windows-like and so on?
how does it work without digging into details?
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);
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