somjit{} 60 Junior Poster in Training Featured Poster

:P nah iv been in daniweb long enough to "internalize" a few good practices , will create a new thread when some new question comes up in my mind. :)

thanks for the help. :)

somjit{} 60 Junior Poster in Training Featured Poster

thanks for the link deceptikon :) problem solved :)

just for reading , can you give some links to read about portability in c ? its been a long time since iv been with c , and forgotten a lot of stuff i learned back then.

somjit{} 60 Junior Poster in Training Featured Poster

good to know.

so in the program above, can you suggest some way (since getchar() wont do it) that i get output to ascii when i press any character ?

somjit{} 60 Junior Poster in Training Featured Poster

when you say about things being line buffered , the S.O. page had this

Standard output is line buffered if it can be detected to refer to an interactive device, otherwise it's fully buffered.

what does that mean ?

somjit{} 60 Junior Poster in Training Featured Poster

for a basic ascii checker code of less than 10 lines , i want to print out stuff immediately , instead of after a newline.
i understand that stdout is a bufferedstream , and so it will by default wait for a '\n'. i was looking at this page for some solutions , but so far aint working like me wants...

this is the code :

#include<stdio.h>
int main(){
    char c;
    while((c=getchar())!=EOF){
        if(c == '\n') continue;
        fprintf(stderr , " : %d \n" , c);
    }
}

i want it to printout like :
A : 65

any help would be highly appreciated.

regards
somjit.

somjit{} 60 Junior Poster in Training Featured Poster

modify is for changing the type only right ? im trying to change the name and the type together...

this place shows that the keyword column is not needed as iv done above , but that also is giving errors.

edit:

alter table project_info change number proj_id int not null auto_increment,
add primary key (proj_id);

this seems to get the job done .
thanks for helping :)

somjit{} 60 Junior Poster in Training Featured Poster

im trying to do this :

alter table project_info change column number proj_id int not null auto_increment,
add primary key (proj_id);

but mysql tells iv got an error. any help with whats wrong here ? i followed this from head first sql book (page 210 if anyone's interested ) .

somjit{} 60 Junior Poster in Training Featured Poster

glad it helped. if you have got your solution, consider marking this solved ?

somjit{} 60 Junior Poster in Training Featured Poster

XXX@YYYY

i think what your looking for is regexes.
and i get the feeling that you are yet to use them. in that case , this and this should give you a good start.

somjit{} 60 Junior Poster in Training Featured Poster

have three states (variables) : str1 ,str2 , op;
create a textfeild tf;
set an accelerator to it for the "ENTER" key event, see this and [this](http://docs.oracle.com/javase/7/docs/api/javax/swing/KeyStroke.html#getKeyStroke(java.lang.Character, int))
now , when you type something in tf , and press enter , text of tf gets stored as str1;
when you press a math button ( + - / etc) that operand gets stored as op;
then when you type in the 2nd number in tf , that gets stored into str2;
the block which stored str2 will also have a test : if both str1 and str2 are valid , and an operand has been entered : doCalc();
doCalc() : something that takes in two strings str1 and 2 , casts them as integers , operates them with the entered operand , and store the result as str1.

and the cycle continues.

this was a quickie , might(and probably will) need further refinements.

somjit{} 60 Junior Poster in Training Featured Poster

perhaps this should be posted on the javascript forums.
youd find the right people there.

somjit{} 60 Junior Poster in Training Featured Poster

installed the server part to get the command line. i had a server installation (downloaded from file-hippo) which didnt work(as mentioned above). hence was skeptical. this however ran fine. and i have a command line working now.

somjit{} 60 Junior Poster in Training Featured Poster

im on win 8. neither can i find the bin folder as i could on my xp machine , nor do i get any command line. googleing didnt help much either. either i got some really hard to understand mysql doc page , with no specific answer to my problem nor any help on non-server installation.

note: by client mode , i installed through custom, and de-selected the server box , and .net and exel connections , and the docs , and installed everything else. ver : 5.6 community server. windows installer.

its really frustrating to not be able to do something on win8 that i could so easily on xp. in xp i had a 32Mb 5.5 installer download from file-hippo and even that gave me a nice command line to work with. i installed the 5.6 version of the same , and whatever command line it gave , flashed once and then went off. im learning sql and i plan to write my code on notepad++ and run it on the command line. but no luck so far. Will be thankful for any help regarding this matter.

somjit{} 60 Junior Poster in Training Featured Poster

finer debugs needed. but essentially solved i hope. thanks again.

somjit{} 60 Junior Poster in Training Featured Poster

i marked it solved , but something's wrong with the code... for the record , im marking it unsolved again
(dont want a faulty code in a solved thread)

i changed the code to read from a file , being :

enq a
enq b
enq c
enq d
enq e
enq f
enq g
enq h
enq i
enq j
enq k
deq
deq
deq
deq
deq
deq
deq

and it gave this as output :
adding : a
adding : b
adding : c
adding : d
adding : e
adding : f
resizing array to size: 10
adding : g
adding : h
adding : i
adding : j
adding : k
removing : f
removing : g
removing : h
removing : i
removing : j
removing : k
removing : null

somethings not right... ill see if i can figure it out. any suggestions would be great as well.
edit : i think my resize condition at enqueue is causing the problem.

edit 2 : overthought the whole modulo thing. not needed . simplified (and working) change :

public void enqueue(E item) {
        // when size = arr.length , and tail has made one loop and now pointing
        // to head.
        arr[size++] = item;
        if (size …
somjit{} 60 Junior Poster in Training Featured Poster

thanks a lot mr Baen Mido !! kudos to your evil eyes... i hope you can use that for more than thrice a day :)

i never noticed that eclipse auto code added something else from my jar package... thanks!

~s.o.s~ commented: You bet I can ;) +14
somjit{} 60 Junior Poster in Training Featured Poster

my display() method is public and looks to be defined , however eclipse says that its not defined.
this is a code for an amortized time resizing circular array. can someone help me out here ? also , please do point out if you see something else wrong with the code.

thanks in advance.

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
class ResizingCircularArray<E>{

    private int head = 0; // head , tail are modulo capacity , ie modulo arr.length
    private int tail = 0;
    private int size = 0; // a measure of non-null elements in the array
    private E[] arr;
    private void resize(){

        @SuppressWarnings("unchecked")
        E[] tempArr = (E[]) new Object[2*size];
        System.arraycopy(arr, head , tempArr , 0 , size );
        arr = tempArr;
    }

    public void enqueue(E item){
        // when size = arr.length , and tail has made one loop and now pointing to head.
        if( tail == head && size!=0 ){ resize(); }
        arr[tail] = item;
        tail = ( tail + 1 ) % arr.length;
        size++;     
    }
    public E dequeue(){
        E item = arr[head];
        head = ( head + 1 ) % arr.length; // dequeing leads to size reduction , making the head move more towards tail , hence + 1.
        size--;
        if(size == arr.length/4){ resize(); }
        return item;
    }
    public int size(){ return size; }   

    public void display(){
        for(E item : arr)
            System.out.print(" " + item);
        System.out.println("\n\n");
    }

    @SuppressWarnings("unchecked")
    public ResizingCircularArray(){
        arr = (E[]) new Object[5];
    }

    public static void main(String[] args){

        ResizingArrayQueue<String> r = new ResizingArrayQueue<String>(); …
somjit{} 60 Junior Poster in Training Featured Poster

so reading as well as printing out both are working ok ? like the example in the S.O forum , doing a System.out.println("<korean chars here>") prints out the chars all right ?

somjit{} 60 Junior Poster in Training Featured Poster

thats good.
while your doing that , would you mind giving some feed back on whether

public Scanner(InputStream source, String charsetName)

does a good job too ? you can set the charsetName to UTF-8 . i havent done anything of this sort before, maybe we can both learn something new.

somjit{} 60 Junior Poster in Training Featured Poster

if your sorting numbers , instead of the complicated looking stuff you did there , why not just use the nextInt() method of Scanner instead of nextLine() ? but if you want to stick to reading line and parsing it , better just use readLine() from BufferedReader and .split() the read line.

somjit{} 60 Junior Poster in Training Featured Poster

this might help... the part about converting the encoding standard to UTF-8. unless of course you have already tried that.

somjit{} 60 Junior Poster in Training Featured Poster

may i ask where does such capturing of instances/classes find its use ?

somjit{} 60 Junior Poster in Training Featured Poster

i saw php being discussed here , as is other languages.. so i thought maybe it wont hurt if i ask about one more language.

somjit{} 60 Junior Poster in Training Featured Poster

that would be a good way to solve it. however , as OP says , in his 2ndweek only... maybe he should practise up some of the basic gui before going there.

somjit{} 60 Junior Poster in Training Featured Poster

the OP asks something i have pondered over myself a number of times , but didnt ask anywhere feeling i might be tagged as vague and asking something without any objective. but regarding php , i would like to know how node.js stands against it. also, when it is said python speeds up development , development of what of things exactly ? pardon my ignorance as im just a few months old java programming student.

somjit{} 60 Junior Poster in Training Featured Poster

make your class extend JFrame , then create a jpanel , that will be your own custom Contentpane , which you can add to the JFrame ,
then inside the contenpane , have two textfeilds , and a button in between them , 1st one takes in input , and on pressing the button , the output is shown on the 2nd text feild. and regarding the decimal point part , use a double instead of a an int.

this is a good place to get started with swing components.
if you have the head first java , book , i learned basic gui from there , found it quite helpful... maybe you can try that out too.

note : youll find the reason i suggested using your own jpanel contentpane within the first few pages of the link above. :) see if you can dig it out.

somjit{} 60 Junior Poster in Training Featured Poster

, all other threads that invoke synchronized methods for the same object block (suspend execution) until the first thread is done with the object.

so if an object MyThread has 100 methods with the synchronized keyword, and one thread accesses just one out of the 100 synchronized methods , all the rest of the 99 methods and the current invoked method are blocked to all other threads in the program ?

i thought only the synchronized method being invoked gets locked/blocked and other threadscan access other methods of the object....

and, thanks a lot for the detailed answer , just what i needed :)

somjit{} 60 Junior Poster in Training Featured Poster

This is the example i was looking at. The docs say that trying to access the bowBack() method is creating the deadlock , but im new to threads , and i really dont understand why this is happening. In need of some guidance here...

somjit{} 60 Junior Poster in Training Featured Poster

yeah i think i read about CPUID and coreTemp both getting their info from the diodes/sensors underneath the chip.

Are the softwares giving strange readings suited to your mb and CPU?

I didnt know about the suited part . Do monitors have this compatibility issue ? i wasnt aware of this .
However , on my desktop - coreTemp , CPUID , speccy all three agree , maybe because the hardware is old and was easily compatible with the versions i tried. But in my laptop , CPUID ( OpenHardwareMonitor ) seems to be giving the correct readings , whereas Speccy makes the cpu go upto 85+. and i think it really MAKES the cpu go to 85+ instead of just showing wrong data , because the exhaust air feels very hot once Speccy starts running. Maybe speccy isnt compatible with the HP+win8 combination.

iv ran kaspersky scans (without ever starting speccy after turning on the laptop) yesterday , and even with full load , the apu temp stayed under control and the exhaust air was much cooler than even in idle+speccy mode.

i think i remember that coreTemp also showed believable (35-45 temp range) readings , but i didnt notice at that point that turning on speccy was causing the temperature rise.

somjit{} 60 Junior Poster in Training Featured Poster

1st of all , let me mention my hardware :

HP G6 laptop with win8 :
amd a4 4300M, radeon graphics : 512 MB 7420G + 1GB 7670M , 4 gb 1600 Mhz ram.

4 yr old Desktop running xp sp2 :
amd athlon x2 250 , inbuilt graphics : 256MB NVIDIA GeForce 7025 / NVIDIA nForce 630a, ram : 2gb DDR2 800Mhz ,

Long Story short : i think speccy doesnt give accurate results on win8 + HP hardware , or , is bugged somehow , and causes CPU temp to shoot to astronomical levels.
if you care about how i come to say this , read below :

I wanted to note the CPU temerature of my laptop , and i have always been a speccy user , so installed the latest speccy in the lappy , and ran it. i was surprised to see an idle temperature over 86 degrees Centigrade. i ran a kasperky scan , and it went upto 120 degrees !! i thought it must be a mistake , so i installed coreTemp , and a bunch of other monitors. All showed the same readings !

whereas , in my desktop , they all show an idle temp of around 33 deg (recently changed the thermal paste) and under load ( Photoshop rendering ) it went upto a max of around 44 deg.

it has been around a week since this event , iv contacted hp , and an engineer had …

somjit{} 60 Junior Poster in Training Featured Poster

thanks for the detail mKorbel :) i have a feeling ill be coming back to this post when i do more with layouts. :)

somjit{} 60 Junior Poster in Training Featured Poster

in the second case you are adding to a FlowLayout (using a BorderLayout parameter for an unspecified result)

that explains the null pointer exceptions i was getting , i thought the contentPane had already fitted in the panel when i called the methods on it , but they hadnt fit in , and gave me nulls.

thanks for the answer :)

somjit{} 60 Junior Poster in Training Featured Poster

doing this works :

        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        contentPane.setLayout(new BorderLayout(0, 0));          
        textArea = new JTextArea();
        scrollPane = new JScrollPane(textArea);
        contentPane.add(scrollPane,BorderLayout.CENTER);
        setContentPane(contentPane);

however this doesnt :

        contentPane = new JPanel();
        textArea = new JTextArea();
        scrollPane = new JScrollPane(textArea);
        contentPane.add(scrollPane,BorderLayout.CENTER);
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        contentPane.setLayout(new BorderLayout(0, 0));
        setContentPane(contentPane);

i guess thats got something to do with setBorder() and setLayout() creating something like a new instance of JTextArea perhaps , something that nullifies the effect of contentPane.add(scrollPane,BorderLayout.CENTER); line , but i was hoping for a concrete answer as to why one code works and the other doesnt.

thanks in advance for your time :)

somjit{} 60 Junior Poster in Training Featured Poster

^ means to start searching from the beginning,

how is ^a different from \b ? that should also let me start from the begining right ?

somjit{} 60 Junior Poster in Training Featured Poster

regarding the null error of exp2 , i suppose that the whole pattern resulting from the regex , the (compiler ? ) wants to find it at the start , which not being there , gives a null. i read that regexps are evaluated left to right , so i thought ^a+ would be evaluated first , and that would give "aaaa"...

edit : didnt see you already posted above..

a+(a+(?=b|c))

ahh ! so thats what i was doing wrong ! thanks for pointing that out :)

somjit{} 60 Junior Poster in Training Featured Poster

can you give an example of this putting things in between ? i just learned this today...

somjit{} 60 Junior Poster in Training Featured Poster

checks for any number of a's followed by a c.

but i have the lookahead part under parens , why doesnt the one on the outside return 4-a's ?

somjit{} 60 Junior Poster in Training Featured Poster

my string (str2) = "aaaabbaacc"

i wanted to parse out the two a groups. some trials had worked according to plan , while a few , are giving me outcomes i dont understand. im hoping the members could help me out :)

problematic regexp 1 : console.log(str2.match(/a+(a+(?=c))/).toString());
this gives "aa , a"

problematic regexp 2 : console.log(str2.match(/^a+(a+(?=c))/).toString());
this gives : Uncaught TypeError: Cannot call method 'toString' of null

no idea why the two works like the way they do. i was expecting both to give "aaaa , aa" as the result !

somjit{} 60 Junior Poster in Training Featured Poster

they might be a top class plasterer

nah :D i would'nt be searching for a plasterer's job.

thanks for the inputs. i guess i have an idea now :)

somjit{} 60 Junior Poster in Training Featured Poster

how about a site that mentions
no clients ,
no area of work ,
no tools they work with (iv seen a few site that mention this , and i like it)
and no past records.

somjit{} 60 Junior Poster in Training Featured Poster

i was looking up some websites for small scale companies around my area, during which i found a few websites that didnt really look much. i saw the html code , and also , seemed fairly easy and simple to me , a newbie html learner.
i was wondering if there is some significant relation between the quality of the webpage and the company itself... ? most of my friends whom i gave the links (of these few companies) to , told me the same stuff ,
** bad webpage > bad company **

would like to hear the opinions of the members on this matter.

regards.

somjit{} 60 Junior Poster in Training Featured Poster

well , i wanted to see the courses offered there for a long time , got a pass today , so i was a bit elated you can say.

i agree maybe this wasnt the best place to post it. but then again , i felt somebody might find it useful. hence i posted to daniweb. why the java forum , well i got a bit carried away perhaps... and didnt know in which forum to post to...
if the morderators do feel that it might help somebody , may be they could shift it to some other forum.

i hope this wasnt too much of a nuisance...

somjit{} 60 Junior Poster in Training Featured Poster

i just learnt that code school is giving away free hall passes.
i got in through a coursemate's distributed pass on coursera's forum.

this is my pass , i thought id share it here if anyone is interested in getting an all access pass to code school.

http://go.codeschool.com/lCxAPA

ps: each pass gets you 2 days of free access , and if someone activates from my pass , i get 2 more days. extendable upto 30 days max. a little help here would be nice :)
thanks :)

somjit{} 60 Junior Poster in Training Featured Poster

thanks a lot :)

somjit{} 60 Junior Poster in Training Featured Poster

chrome , firefox.. these are great browsers , and even if i write utter crappy html code, it still makes sense out of it , and tries to display it the way a proper code would have made it display.

thats great stuff unless i want to know/see the errors when i make them.

any such place i can do that ?

somjit{} 60 Junior Poster in Training Featured Poster

thanks again :)

somjit{} 60 Junior Poster in Training Featured Poster

the cast will be OK, but in general, you cannot be sure that a class that implements StyledDocument will extend AbstractDocument

so i guess the instanceOf check was a best-practices example for code in general. thanks for the nice and simple explanation :)

another question i would like to ask is that the code also shows the use of the DefaultEditorKit for functions like undo etc.
taking undo as a reference , is there any performance benefits of say using the DefaultEditorKit over methods implemented using UndoManager with key-binding ?

somjit{} 60 Junior Poster in Training Featured Poster

this is the code i was looking at.Its about how to use JTextPane and related swing text Components along with actions and keymaps.

my question is that in this part

        textPane = new JTextPane();
        textPane.setCaretPosition(0);
        textPane.setMargin(new Insets(5, 5, 5, 5));
        StyledDocument styledDoc = textPane.getStyledDocument();
        if (styledDoc instanceof AbstractDocument) {
            doc = (AbstractDocument) styledDoc;
            // doc.setDocumentFilter(new DocumentSizeFilter(MAX_CHARACTERS));// DocumentSizeFilter doesnt work , eclipse giving errors
        } else {
            System.err
                    .println("Text pane's document isn't an AbstractDocument!");
            System.exit(-1);
        }

in the lines doc = (AbstractDocument) styledDoc; , does doc and styledDoc point to the same location in the heap ? or does the casting create a new memory-space / object-instance pointed to by doc.

a related question that was going on in my head was that :
if styledDoc is an instanceof AbstractDocument , why do we need the cast ?

somjit{} 60 Junior Poster in Training Featured Poster

ok. thanks for clearing up the main doubt :)

somjit{} 60 Junior Poster in Training Featured Poster

No, one's an interface, the other is a class.

i did get that part... , i guess the way i asked the question was pretty vauge. my bad.

For most applications, where there's no need to do anything special, they provide a "default" implementation of the interface in the form of the HashPrintRequestAttributeSet class

thanks! that makes things a lot clearer.

however , regarding the attributes , using just printDialog() without any attributes let me edit the print settings by clicking the properties button of the dialog that comes up... however , when i used the HashPrintRequestAttributeSet attribute with the printDialog, the properties button was left dysfunctional. why is that ?

this is what im doing

public void filePrint() {
        PrinterJob printer = PrinterJob.getPrinterJob();
        //HashPrintRequestAttributeSet pAttrib = new HashPrintRequestAttributeSet();// pAttrib inside printDialog() does not give functional properties button  
        if (printer.printDialog()) // without it , however , i do get a functional button for properties.
        { 
            try {
                printer.print(); 
            } catch (PrinterException e) {
                e.printStackTrace();
            }
        }
    }