|
foo() in Base class is declared as Static. Therefore it is not belonged to specific object but common for all objects.
bObj is an object of Base class, therefore it will call foo() in Base class, because foo() is Static.
|
|
|
|
|
To explain that, take a look at what is executed and why.
First of all, you create a new Derived-Instance as an instance of Base.
Take a look at how you call the static method foo():
You dont access it in a static way (to use exact the phrase the compiler will warn you with) - which would be Base.foo() or Derived.foo() - but you call it on an instance.
As mentioned, bObj is an instance of Base (because you declared it as that) and thus the static Method Base.foo() is called, which prints the "In Base.foo()"-Part of your output.
If you declared it as an instance of Derived, the static method Derived.foo() would have been called there.
To explain the part "In Derived.bar()" take a look at what is called next:
In Base.bar() you call bObj.bar();
bObj was instantiated with new Derived(), so the method bar() on that object is overriden with the implementation in Derived, which prints then "In Derived.bar()".
I hope that explains inheritance a bit better.
ab
|
|
|
|
|
|
i'm still new to java, but i want to create a java application for mobile phones, which will perform the following functions for sending sms online
get Username and password of the user
Message Sender ID,
Recipient numbers or select from contact list
the message
then the send button which will make use of sms API
|
|
|
|
|
Please use Google to do some research first. It is not possible to provide all this information in a technical forum.
Veni, vidi, abiit domum
|
|
|
|
|
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
public class server extends Frame implements ActionListener, Runnable
{
Image Icon = Toolkit.getDefaultToolkit().getImage("hi.gif");
ServerSocket ss;
Socket s;
BufferedReader br;
BufferedWriter bw;
TextField text;
Button sendBut, exitBut;
List list;
public server(String m) // class constructor
{
super(m);
setSize(300, 130);
setLocation(0,0);
setIconImage(Icon);
setResizable(false);
setBackground(new Color(192, 192, 192));
this.setLayout(new GridLayout(2, 1));
Panel panels[] = new Panel[2];
panels[0] = new Panel();
panels[1] = new Panel();
panels[0].setLayout(new BorderLayout());
panels[1].setLayout(new FlowLayout(FlowLayout.LEFT));
sendBut = new Button("Send");
exitBut = new Button("Exit");
sendBut.addActionListener(this);
exitBut.addActionListener(this);
list = new List();
list.addItem("Server up & Listening on port plz wait...");
text = new TextField(25);
panels[0].add(list);
panels[1].add(text);
panels[1].add(sendBut);
panels[1].add(exitBut);
add(panels[0]);
add(panels[1]);
setVisible(true);
try
{
ss = new ServerSocket(1053);//some port number, better be above 1000
s = ss.accept();
br = new BufferedReader(new InputStreamReader(s.getInputStream()));
bw = new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
bw.write("Hi! ASL plz??");
bw.newLine();
bw.flush();
Thread th;
th = new Thread(this);
th.start();
}catch(Exception e){}
}
public void run()
{
while (true)
{
try
{
list.addItem(br.readLine());
}catch (Exception e){}
}
}
public static void main(String arg[])
{
// create an object instance
// by sending the title as a parameter
new server("Server Applicaton");
}
public void actionPerformed(ActionEvent ae)
{
if (ae.getSource().equals(exitBut))
System.exit(0);
else
{
try
{
bw.write(text.getText());
bw.newLine();bw.flush();
text.setText("");
}catch(Exception x){}
}
}
}
|
|
|
|
|
How would I get the JSpinner value into database?,
the value is in alphanumeric
Like
1month
2month
String[] monthStrings = {"1Month","3Month","6Month","1Year"};
SpinnerListModel monthModel = new SpinnerListModel(monthStrings);
JSpinner spinner = new JSpinner(monthModel);
|
|
|
|
|
chdboy wrote: How would I get the JSpinner value into database? The same way you would put any value into the database; what exactly is the difficulty? Given also that it is just a short list, maybe storing the index value rather than the string would be the best idea.
Veni, vidi, abiit domum
|
|
|
|
|
Here is the code ,how I'm saving the JSpinner value
statement.setString(27,JSpinner.getValue());
Under setString red line and the error is
The method setString(int, String) in the type PreparedStatement is not applicable for the arguments (int, Object)
and Under
JSpinner.getValue() red line and error says
Cannot make a static reference to the non-static method getValue() from the type JSpinner
|
|
|
|
|
You cannot use JSpinner.getValue() , you need to call getValue() on an instance of the JSpinner class.
Veni, vidi, abiit domum
|
|
|
|
|
I tried
statement.setString(27,(String)spinner.getValue());
and I get
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
EDIT:
It worked with
statement.setString(27,(String)spinner.getValue().toString());
modified 17-Sep-13 9:54am.
|
|
|
|
|
You should go back to your Java documentation or tutorials and learn why and when it is possible to use casts. Simply stated, you cannot use a cast to convert one object type to another. You also need to decide in advance what object type you want to store in the database, and write the code to handle that specific situation.
Veni, vidi, abiit domum
|
|
|
|
|
can i join your grope ?
longkimnoy
|
|
|
|
|
grope=feel about or search blindly or uncertainly with the hands.
group=a number of people or things that are located close together or are considered or classed together.
You have already done the second.
|
|
|
|
|
|
Hi all,
I am new to java; earlier i was working in .net (c#). My company assigned me an existing web project which is developed in java (jsp). i have installed jdj7 and Apache Tomcat 7 as service on my machine. Whenever i placed my project in webapps folder it generate an error in logs (Catalina)
Sep 12, 2013 3:11:45 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\Tomcat 7\webapps\myproject
Sep 12, 2013 3:11:57 AM org.apache.catalina.core.StandardContext startInternal
SEVERE: Error listenerStart
Sep 12, 2013 3:11:57 AM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/myproject] startup failed due to previous errors
Thanks
rmshah
Developer
|
|
|
|
|
That's not a Java issue, try one of the Apache forums.
Veni, vidi, abiit domum
|
|
|
|
|
Anybody knows how to call the XEN hypercalls by the c program. Anybody know means guide me.
|
|
|
|
|
|
I have this text file on the web called, accounts and what it should look like it when people add their account is
name;password
name2;password
the ";" is so it can be split into an array later
im trying to do this with-out a server, an example, not a gaming server, more like a web host server example, im not sure how I am to allow a person to make account with-out whiping all the data and adding it agian, this is how i got it going when adding an account
copy text file data
add text file data to program
clear text file data
add data from program program and new account info
I want it to go
add account data to text file
I was wondering if this is possible to do? and if so how?
|
|
|
|
|
This is exactly what databases are designed for, and text files are not. Why not use a database?
|
|
|
|
|
because its too complicated
|
|
|
|
|
A worse excuse could not be made for learning something new.
Expand your knowledge, if you stop because "its too complicated", how are you ever going to get better?
[Edit]
Modifying text files (despite the HUGE security hole where I can get your usernames and passwords) is, in my opinion, complicated. Might be OK while you have a small user base, but try getting concurrent operations and losing users/passwords when you write the file twice.
|
|
|
|
|
As Ron suggests, you should use a database for this; and it really is not that complicated. Trying to modify a text file in the way you describe is prone to errors and losing all your data. You could read the file at startup and keep it all in memory. Then every time you get a new account add it to your in memory list and write the complete file back to disk. However, this method is still not totally secure.
Veni, vidi, abiit domum
|
|
|
|
|
C.CoderCreator wrote: I was wondering if this is possible to do?
If there is no server then EVERYONE must have access to the file system. So that means NO internet.
If that is ok with you then the way this is typically handled is with a "file lock". Depending on what the clients look like and the OS then there might be native support for this. However there are non-OS supported ways that are almost workable for simple cases. Failures usually result in locked applications. Failures are very likely to occur. So likely that if they don't occur that would be an abnormal situation.
You can google for "file lock" to find more information if the limitations are ok.
|
|
|
|