d**d 发帖数: 389 | 1 $ g++ --version
g++ (GCC) 4.4.4 20100630 (Red Hat 4.4.4-10)
code 如下:
#include
using namespace std;
class Animal
{
protected:
string m_strName;
Animal(string strName):m_strName(strName)
{
};
public:
string GetName(){return m_strName;};
virtual const char* Speak(){return "???";};
};
class Cat:public Animal
{
public:
Cat(string strName): Animal(strName)
{
}
virtual const char *Speak(){return "Meow";};
};
clas... 阅读全帖 |
|
h**********c 发帖数: 4120 | 2 来自主题: Programming版 - C++一问 应该可以
说不清,JAVA也可以这么干。
#include
#include
class A {
public:
A(const std::string& _name):Name(_name) {}
const std::string Name;
const std::string getName () {
return Name;
}
};
class B:public A {
public:
B():A("It is B") {}
const std::string getName () {
return Name;
}
};
class C:public B {
public:
const std::string Name;
C():Name("It is C") {}
const std::string getName () {
return Name;
}
};
int main () {
A a("It is A");
B b;
C c;
... 阅读全帖 |
|
z*******3 发帖数: 13709 | 3 之前说过我对abstract class的看法,倒是引来不少非议
尤其是有些人居然举出了例子,好,我们就从这个例子开始
有人说在这种情况下要使用abstract class
比如一个animal,有walk和sing方法
那么代码就是
public abstract class Animal{
public void walk(){System.out.println("walk")};
public abstract void sing();
}
然后对于具体的实现类,比如Cat,有如下实现
public class Cat extends Animal{
public void sing(){
System.out.println("cat sing");
}
}
这样一个类,好处就是“便于扩展”等等
OK,那么我们就从这个例子出发,说说为什么在j2ee环境中,我们不这么做
然后说说会怎么做
首先,在j2ee的环境中,关于animal这种实体
我们会在各个层面建立entity
比如在db层面建立一个表,叫做animal,然后有一个cat记录
然后通过orm,建立起一个dto之类的玩... 阅读全帖 |
|
z*******3 发帖数: 13709 | 4 之前说过我对abstract class的看法,倒是引来不少非议
尤其是有些人居然举出了例子,好,我们就从这个例子开始
有人说在这种情况下要使用abstract class
比如一个animal,有walk和sing方法
那么代码就是
public abstract class Animal{
public void walk(){System.out.println("walk")};
public abstract void sing();
}
然后对于具体的实现类,比如Cat,有如下实现
public class Cat extends Animal{
public void sing(){
System.out.println("cat sing");
}
}
这样一个类,好处就是“便于扩展”等等
OK,那么我们就从这个例子出发,说说为什么在j2ee环境中,我们不这么做
然后说说会怎么做
首先,在j2ee的环境中,关于animal这种实体
我们会在各个层面建立entity
比如在db层面建立一个表,叫做animal,然后有一个cat记录
然后通过orm,建立起一个dto之类的玩... 阅读全帖 |
|
|
s*r 发帖数: 2757 | 6 give me 100 if this works
DATAROW=n;
starts reading data from row number n in the external file.
Default: 1 when GETNAMES=NO
2 when GETNAMES=YES (default for GETNAMES=)
Interaction: When GETNAMES=YES, DATAROW= must be equal to or greater than 2. When GETNAMES=NO, DATAROW must be equal to or greater than 1. |
|
h**u 发帖数: 144 | 7 用了两个blocking queue, 还请大侠指教!
import java.util.concurrent.LinkedBlockingQueue;
public class H2O {
LinkedBlockingQueue hQueue = new LinkedBlockingQueue();
LinkedBlockingQueue oQueue = new LinkedBlockingQueue();
Object o = new Object();
public void h() throws InterruptedException {
hQueue.put(Thread.currentThread());
synchronized (o){
System.out.println(Thread.currentThread().getName() + ".h,
notify");
o.notify()... 阅读全帖 |
|
h**u 发帖数: 144 | 8 用了两个blocking queue, 还请大侠指教!
import java.util.concurrent.LinkedBlockingQueue;
public class H2O {
LinkedBlockingQueue hQueue = new LinkedBlockingQueue();
LinkedBlockingQueue oQueue = new LinkedBlockingQueue();
Object o = new Object();
public void h() throws InterruptedException {
hQueue.put(Thread.currentThread());
synchronized (o){
System.out.println(Thread.currentThread().getName() + ".h,
notify");
o.notify()... 阅读全帖 |
|
r*c 发帖数: 167 | 9 using System;
using System.Collections.Generic;
namespace WinningGame
{
class Program
{
static void Main(string[] args)
{
int nCount = 0;
int nTotalGames = 1000;
for (int i = 0; i < nTotalGames; i++)
{
Board bd = new Board();
//bd.PrintBoard();
bool bResult = bd.IsWinner();
if (bResult)
{
nCount++;
bd.Print... 阅读全帖 |
|
S*******0 发帖数: 198 | 10 public abstract class Piece {
private String pieceColor;
public Piece() {
}
public String getPieceColor() {
return pieceColor;
}
// boolean isOppositeColor()
abstract public String getName();
abstract public boolean isRoadOk(Board board, String from, String to);
}
King, Queen, Bishop, Knight, Rook, Pawn 都继承一下Piece
public class Board {
private Square[][] squares = new Square[8][8];
public Board() {
//set the 32 pieces
}
public Square[][]... 阅读全帖 |
|
z********i 发帖数: 568 | 11 为什么会比switch statements好?
Switch statements:
public boolean beats(GameObject object){
if(object.getClass.getName(0.equals("Rock"){
result=false;
}
else if(object.getClass.getName(0.equals("Rock"){
result=false;
}else if(object.getClass.getName(0.equals("Rock"){
result=false;
}
return result;
}
Doulbe Dispatch Pattern:
public class Rock implements GameObject{
public boolean beats(GameObject o){
return o.beatsRock();
}
public beatsRock(){
return false;
}... 阅读全帖 |
|
k****r 发帖数: 807 | 12 这个死锁的例子,为什么会发生呢?bow里面的bower.bowBack(this)为什么会被block
住呢,不是两个bow function都synchronized了吗?难道说instance的另一个bowBack
也被syn了吗?
concurrency小白,勿怪。
static class Friend {
private final String name;
public Friend(String name) {
this.name = name;
}
public String getName() {
return this.name;
}
public synchronized void bow(Friend bower) {
System.out.format("%s: %s"
+ " has bowed to me!%n",
this.... 阅读全帖 |
|
l******e 发帖数: 42 | 13 来自主题: JobHunting版 - 求解。。。 /* There exists the following interface
public interface Container {
Container getParent(); //if there is no parent, getParent() returns null
String getName();
}
Create a method printContainers(Container c) that prints out the names of
all the parent containers in the order of the top-most parent container
first.
For example, assume the following:
a.getParent() returns b
a.getName() returns "foo"
b.getParent() returns null
b.getName() returns "bar"
printContainers(a) should print to the ... 阅读全帖 |
|
p*********s 发帖数: 1952 | 14 //刚学java, 下面代码出错,请问下错在哪儿里,怎么改?
//RefDemo04.java:65: error: cannot find symbol
// System.out.println(bk.getPerson().getName());
^
// symbol: method getName()
// location: class Person
// 1 error
class Person {
private String name;
private int age;
private Book book;
public Person(String n, int a) {
this.setName(n);
this.setAge(a);
}
public void setBook(Book b) {
book = b;
}
public vo... 阅读全帖 |
|
l******e 发帖数: 12192 | 15 比如class A { public: void getName()}; class B {public: getName()};
我想把A的getName改一下,你怎么f&r? |
|
p********a 发帖数: 5352 | 16 options obs=max;
proc import datafile="C:\SAS Projects\Stock analysis\NYSE_symbols.xls" out=
NYSE dbms=excel2000 replace;
getnames=Yes;
run;
proc import datafile="C:\SAS Projects\Stock analysis\AMEX_symbols.xls" out=
AMEX dbms=excel2000 replace ;
getnames=Yes;
/*guessingrows=20;*/
run;
proc import datafile="C:\SAS Projects\Stock analysis\NASQ_symbols.xls" out=
NASQ dbms=excel2000 replace;
getnames=Yes;
run;
data TICK;
set NASQ(in=a) NYSE(in=b) AMEX(in=c);
if a then Srce="NASQ";
else if b then Sr |
|
b*******y 发帖数: 239 | 17 原题也是在这个版上有人发的C++的其中一题,已copy下来:
class Person{
public:
Person(const char* szName);
const char* GetName() const;
/*put a function here*/
private:
char *m_szName;
};
int main()
{
Person person("John");
std::cout << Person;
return 0;
}
Referring to the sample code above, which one of the following member
functions do you add at the comment to support std::cout << person
statement?
A. std::string operator() { return GetName(); }
B. std::string ToString() { retur |
|
l*******o 发帖数: 791 | 18 class Simple{
private:
static Simple * ptr;
string name;
Simple();
public:
static Simple * createSimple(){ptr = new Simple(); return ptr;}
const string getName(){return name;}
};
Simple* Simple:: ptr = NULL;
Simple::Simple(): name("mitbbs"){}
//static Simple* Simple::createSimple(){ ptr = new Simple; return ptr;}
void func()
{
Simple *s= Simple::createSimple();
cout<getName()<
}
int |
|
k****r 发帖数: 807 | 19 According to your approach, I tried to code one. Please kindly let me know,
if you see anything wrong:) (Here, I assume both produce and merge are
costly)
public class MergeOutput {
public static void main(String[] args) throws Exception {
List list = new ArrayList<>();
BlockingQueue bq1 = new ArrayBlockingQueue(1000);
BlockingQueue bq2 = new ArrayBlockingQueue(1000);
Producer producer = new Producer(bq1, list);
Consumer[] consumers = new Con... 阅读全帖 |
|
f******u 发帖数: 250 | 20 (导入数据)
proc import out=aapl
datafile="C:\Users\aapl.xlsx"
dbms=xlsx replace;
sheet="sheet1";
getnames=yes;
run;
proc import out=spy
datafile="C:\Users \spy.xlsx"
dbms=xlsx replace;
sheet="sheet1";
getnames=yes;
run;
(筛选数据)
data aapl;
set aapl(keep=date adj_close);
label adj_close="Aclose";
rename adj_close=Aclose;
run;
data spy;
set spy(keep=date adj_close);
label adj_close="Sclose";
rename adj_close=Sclose;
run;
(整理数据)
proc sort data=spy;by descending date;run;
proc sort data=aapl;by descendin... 阅读全帖 |
|
r*****s 发帖数: 985 | 21 或者tomcat的CLASSPATH应该怎么设?
An error occurred at line: 1 in the jsp file: /jsp/GetName.jsp
Generated servlet error:
/.../jsp/GetName$jsp.java:56: Class org.apache.jsp.UserData not found.
UserData user = null;
^
Here I defined a class UserData. Where should I put it to? I just installed
a new tomcat 4.0.3. I haven't changed any path yet.
请大虾们指教! 多谢了. |
|
o**2 发帖数: 168 | 22 我用FMP把楼主的程序重写了一遍,在这里分多层贴出来,供楼主参考,也欢迎大家评
论。
FMP的binary可以在这里download:http://search.maven.org/#browse|1968728870
Predictor class完全没有变化,我加的都是些print outs。
public class Predictor {
private static int sn = 0;
private synchronized static int incSN () {
return sn++;
}
private String mySN = "Predictor#" + incSN ();
public Predictor () {
System.out.println (mySN + " is starting - " + Thread.currentThread
().getName ());
// time consuming stuff.
System.out... 阅读全帖 |
|
n******1 发帖数: 3756 | 23 我在网上看到这两段代码,一个写,一个读,但是好像是有问题的.我看写是没问题的
,我把queue打出来,输入的都有,但是reader的读行为非常奇怪,如果文件有内容,
可以读出来,但是重新写入的有时候能读一部分,比如writer写入abcde,可能read到ab
出来,但大部分时间都是null,尝试自己加过在writer加入sleep,wait什么都没用
Writer.java
import java.io.BufferedWriter;
import java.io.Console;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.concurrent.BlockingDeque;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.logging... 阅读全帖 |
|
c*******e 发帖数: 290 | 24 对,因为那个 date 是个 local variable, 每次都重新创建。所以,他那个例子完全
不适合,根本就用不上 ThreadLocal, 他那个 PerThreadFormatter 完全是多余的. 贴
出他的完整例子:
/**
*
* @author
*/
public class ThreadLocalTest {
public static void main(String args[]) throws IOException {
Thread t1 = new Thread(new Task());
Thread t2 = new Thread( new Task());
t1.start();
t2.start();
}
/*
* Thread safe format method because every thread will use its own
DateFormat
*/
public static S... 阅读全帖 |
|
o**2 发帖数: 168 | 25
这里是完整的可运行的代码。需要的FMP库在: http://search.maven.org/#browse|1968728870
import com.fastmessenger.impl.GuiMessenger;
public class Main {
public static void main (String[] args) {
GuiMessenger messenger = new GuiMessenger ();
FMPTest win = new FMPTest (messenger);
FileAnalyzer analyzer = new FileAnalyzer (messenger);
messenger.registerSwingReceiver (win, "main.frame", "setStatus");
messenger.registerReceiver (analyzer, "file.analyzer", "countWord");
w... 阅读全帖 |
|
l**********s 发帖数: 255 | 26 我可以用如下的code分别打开三个excel文件 ,但是如何同时打开它们呢?实际上我有
上百个excel文件需要打开,是否可以用同一个简短的code同时打开它们呢?多谢!
PROC IMPORT OUT= WORK.a1
DATAFILE= "h:\a1.xls"
DBMS=EXCEL REPLACE;
SHEET="sheet1";
GETNAMES=YES;
MIXED=NO;
SCANTEXT=YES;
USEDATE=YES;
SCANTIME=YES;
RUN;
PROC IMPORT OUT= WORK.a2
DATAFILE= "h:\a2.xls"
DBMS=EXCEL REPLACE;
SHEET="sheet1";
GETNAMES=YES;
MIXED=NO;
SCANTEXT=YES;
USEDATE=YES;
SCANTIME=YES;
RUN; |
|
W*****r 发帖数: 193 | 27 用各个csv的id合并起来
简单的的我知道怎么做
比如
proc import datafile="D:file1.csv"
out=new1 dbms=csv replace; getnames=yes;
run;
proc print data=new1;
run;
proc import datafile="D:file2.csv"
out=new2 dbms=csv replace; getnames=yes;
run;
proc print data=new2;
run;
data dn;
merge new1 new2;
by id;
run;
文件“dn”含new1 和 new2的所有variables, 使用公用的id
问题是,如果csv files很多怎么办?比如100+?
可不可以用proc sql + Macro做出来?
怎么做?
多谢。 |
|
M**Y 发帖数: 431 | 28 1. With these variable declarations: int i, j[10], *k;
Which of the following are legal?
a. i = *(&(j[2]) + 1);
b. k = &(j[1]);
c. i = &(j[2]) + 1;
2. Assuming the function lookupName is defined, what's wrong with this code
(hint: 2 bugs)?
const char *getName(const char *c) {
std::string name = lookupName(c);
if (name == NULL)
return "Anonymous";
return name.c_str();
}
int main(int argc, char *argv[]) {
const char *name = NULL, *c = NULL;
if (argc >= 2)
c = ar |
|
I******y 发帖数: 176 | 29 design a class which provides a lock only if there are no possible deadlocks
解答并没有给出到底什么时候可以acquire lock阿.这个canAcquireResource具体怎么
实现呢
For our solution, we implement a wait / die deadlock prevention scheme.
1 class MyThread extends Thread {
2 long time;
3 ArrayList res = new ArrayList();
4 public ArrayList getRes() { return res; }
5
6 public void run() {
7 /*run infinitely*/
8 time = System.currentTimeMillis();
9 int count = 0;
10 while (true) {
11 if (count < 4) {
... 阅读全帖 |
|
r****m 发帖数: 70 | 30 package test;
public class MapTest implements Runnable{
int[] a;
int index = 0;
MapTest(int[] a) {
this.a = a;
}
int fun(int i) {
return i+1;
}
@Override
public void run() {
int i;
while((i = getIndex()) < a.length) {
System.out.println(Thread.currentThread().getName() + " " + i);
a[i] = fun(a[i]);
}
}
synchronized int getIndex() {
return (index++);
}
static... 阅读全帖 |
|
h*********d 发帖数: 336 | 31 phone interview, 实现一个in-memory filesystem. 刚开始面试,还没有摸到门路,
请大牛指点
Write an in memory filesystem! This is a simplified file system that only
supports directories. Your code needs to read from a file and parse the
commands listed below.
cd - Changes the current working directory. The working
directory begins at '/'. The special characters '.' should not modify the
current working directory and '..' should move the current working directory
to the parent.
mkdir - Creates a new dire... 阅读全帖 |
|
z******f 发帖数: 277 | 32 设计的很不合理。到现在偶还没研究明白,偶太笨了。但为啥人家amazon的API直接
composer装完就可以autoload,你F家的装完还得手动load n个文件?要这样还
composer做甚?load完还要use n个namespace,amazon家那么多API,每个产品就一个
use足矣。Facebook就一个用户接口和其延伸,却要use 无数的namespace,开发者秀逗
么?
最要命的是按照那个readme或官方文档https://developers.facebook.com/docs/php/
gettingstarted/4.0.0 根本不管用啊,一个劲的提示Parse error: syntax error,
unexpected 'use' (T_USE) 都快崩溃了。
/****************************************下面是Facebook composer readme*****
**************************************/
define('FACEBOOK_SDK_V4_SRC_DIR'... 阅读全帖 |
|
h**********c 发帖数: 4120 | 33 你乱用synchronized,
那么getID 会把getName也锁住,
以上答案也就是soso,在我lol的抛引起兴下
问题的本质是你懒不肯或你们学校没教你画 dependency graph |
|
g*****g 发帖数: 34805 | 34 This is not reflection, it's just passing a unique identifier so later on
Class.getName() can be used. |
|
l****c 发帖数: 782 | 35 就是按照时间顺序执行Task那道题,我收集了一些答案自己写了一下,
还请大牛多多多多的指点下,有没有问题。
多谢,多谢!
public class ProcessingQueueTest extends Thread {
//用个minHeap存Tasks
private Queue Tasks = new PriorityQueue<>(new Comparator(){
public int compare(Task a, Task b) {
if (a.time < b.time) return -1;
else if (a.time > b.time) return 1;
else return 0;
}
});
private boolean isRunning = true;
// 加Task进Heap
public void addTask(Task task) {
synchron... 阅读全帖 |
|
l******e 发帖数: 42 | 36 来自主题: JobHunting版 - 求解。。。 I figured something like this may work. Please point out anything you see to
correct or improve. thanks!
/////this is a recursive function question
static void printContainer ( Container c)
{
public Stack nameStack = new Stack();
parent1st(c);
while (!nameStack.empty()) {
system.out.println (NameStack.pop());
}
}
static void parent1st(Container c)
{
nameStack.push(c.getName());
if (c.getParent() == null)
return;
else
parent1st((c.getParent());
} |
|
b**********1 发帖数: 215 | 37 问题是,下面的code 在 点击“click to view” 的时候,会显示email address, 我
现在想吧这个点击 去掉,直接显示email address. 请高手指教
String divOpener = "";
Link = "
) + "','" + super.getParam(row) + "holder_id="+ Double.toString(key) +"');">
Click to View222";
String divCloser = " ";
return divOpener+link+divCloser; |
|
p*****e 发帖数: 5165 | 38
call getClass().getName() and compare to class name
This may work only for public classes |
|
z****g 发帖数: 2497 | 39 I got a very weird exception
code:
...
//isotopes is a Vector
cdk.Isotope iso = (cdk.Isotope)isotopes.elementAt(0);
....
when it runs this line, it throws a ClassCastException
But when I printout isotopes.elementAt(0).getClass().getName()
it print out "cdk.Isotope".
Can't figure out why.
Please help! |
|
|
|
m**c 发帖数: 90 | 42
Try to print out "p.get(i).getClass().getName()" to debug. You don't want to
find a solution without knowing why :-) |
|
c***c 发帖数: 6234 | 43 Friends,
I wrote a servlet and wanted to save some info in cookie.
Cookie c = new Cookie("database", myObj.getDbName());
c.setMaxAge(10000);
response.addCookie(c);
Cookie cc[] = request.getCookies();
if(cc != null){
for(int i=0; i< cc.length && !found; i++){
if(cc[i].getName().equals("database")){
int t = cc[i].getMaxAge();
}
}
}
t is always -1. But c's max age is 10000. So in next login, web can not retain
dbname for me.
Anyboday met the sim |
|
g*****g 发帖数: 34805 | 44 俺上次跟魔胖争论,不是说彻底消除xml,而是说减少xml。
比如spring2.5跟1.x的对比就可以说明这一趋势。
在一个field/method上annotate是不可能产生写错名字的
typo的。我个人的风格倾向于能annotate的annotate,
而真正configuration的部分,我喜欢放在properties文件里。
另外在web架构里,如果page是一个类,像wicket这样的实现,
那么不需要什么navigation xml。setResponsePage(home)这样无疑
可以利用static typing来自动减少错误。而return "home",然后
在xml里home指向xxx无疑就容易出错,要改home的名字也比较麻烦。
在swing开发里,我们希望event转移控制,同样是很直接的show/hide panel,
而不是搞个navigation rule xml,这个event产生发到一个控制器,然后
让控制器读这个xml,hide这个panel,show 那个panel。
在jsf里#{item.name}跟在java里item.getName |
|
t*******e 发帖数: 684 | 45 上次和goodbug等几位讨论到了如何在wicket中把的html tag attribute值变成动态的
问题, 正好看到了这一章,就先说一下,以免忘了。实际上还有很多收获,等书看完再
说了。
JSP中用EL
Hello #{user.name}
Wicket一切都在Java code里
Hello user
1. onComponentTag method of Wicket components
webpage.add(new Label("label", "Hello "+user.getName()){
protected void onComponentTag(ComponentTag tag)
{
super.onComponentTag(tag);
tag.put("style", (user.isActive())?"color:blue":"color:r |
|
g**********y 发帖数: 14569 | 46 ${object} refer to a variable you defined in page or session level, .name means call the method getName() of that object.
It's called expression language, check out
http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JSPIntro7.html
To be frank, it is horrible horrible "language". The only purpose is to make the JSP page look "neat" and easy for designer to understand. But under the hood, it is total mess. If you read the compiled JSP code, you will know what I mean.
Any processing, like regex, you'd |
|
a*****p 发帖数: 1285 | 47 问个exception的问题
我有个java.lang.NullPointerException,然后throwalbe变量是e,我想在textarea里
面打出e的所有信息。我用e.getName()能把名字显示出来,为啥e.getMessage()显示是
null?
后面具体的信息,at line**,这些怎么显示出来么?不是getMessage()又是什么呢?
网上也查了,试过e.getCause().getMessage()也不行。这个是哪里有问题了?
java.lang.NullPointerException
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.
java:201)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:1... 阅读全帖 |
|
N***m 发帖数: 4460 | 48 没太看懂,估摸着写吧
suppose class Bar implemnts Foo, and in bar, we have a method called "run()"
, then
final Foo f = new Bar();
for (final Method m : f.getClass().getDeclaredMethods()) {
if (m.getName().equals("run")) {
m.invoke(f, null);
}
}
Is this what you want? |
|
N***m 发帖数: 4460 | 49 "我原来想的理想状态是取得instanceB的class之后让他自己cast到自己的Bar去"
你的意思是如下类似的转换(假定这样的cast存在)?
String actualClassName = f.getClass().getName(); // "Bar" here
f = cast(f,actualClassName );
//
问题是f总归是Foo类型的...
所以你只能用另外一个Bar类型的变量来hold返回值.
可是正如前文所说的,这岂不是多此一举...
所以
像这 |
|
|