This reverses the characters as below and not words in the sentence.
Input => 'this is the wonderfull island'
Output => 'dnalsi llufrednow eht si siht'
This reverses the characters as below and not words in the sentence.
Input => 'this is the wonderfull island'
Output => 'dnalsi llufrednow eht si siht'
Thanks normR1. Its just a logic question.No need to bother about database. Need to reverse words and keep it in buffer(i.e., some other variable). I don't knw the exact answer, atleast try with using some other java API (stack or queue..)
Thaks for the time, normR1. I agree with u BestJew, but this seems to be logical question. This was the question i came across in an interview. Since, i knew that this can be solved by using either token or split with new arrays,but it should not be approched as such. Is there any other API which would reverse or any logic or approch?
Reverse words in the sentence without using any Java API or new array
Eg.
Input => 'this is the wonderfull island'
Output => 'island wonderfull the is this'
If any logic, pls let me know
--
thanks,
ramjeev
Friends,
Can we add a panel into a editorgridpanel in ExtJS? I have a Ext.list.listview which i want to add it into a GridPanel. I can add textfield, combobox, but listview not workrd out.
Can anyone help on this.
--thanks,
ramjeev
Friends,
Since I have to design JSP using Ext-JS, I am in need of help to start Extended JS. Can anyone suggest me any good sites or pdfs to learn.
Thanks,
ramjeev
Friends,
Can u suggest me some good sites and tutorials to start Extended JS (Java Script) ?
--Thanks
ramjeev
Thanks James & Mustafa.
Sorry ramjeev, musthafa is right. "this" is the method's object.
See Java Lanmguage ref:
For Static mtd, object of that class is used.
For Instance mtd, this object is used.
This is what i can understand from your statement.Am I right?
Its seems to be that method's(run) object and not this. Following is the statement taken from
http://www.javaworld.com/javaworld/jw-04-1996/jw-04-synch.html
During the execution of a synchronized method, the thread holds the monitor for that method's object, or if the method is static, it holds the monitor for that method's class. If another thread is executing the synchronized method, your thread is blocked until that thread releases the monitor (by either exiting the method or by calling wait()).
Thanks. In the following code, which object is synchronized?
public class TestThread implements Runnable
{
TestThread()
{
new Thread(this,"Test 1").start();
new Thread(this,"Test 22").start();
}
synchronized public void run()
{
int i=0;
do
{
System.out.println((i++)+"....Sync block 1 :"+Thread.currentThread().getName());
}while(i<3);
}
public static void main(String[] args) throws InterruptedException
{
new TestThread();
}
}
Hi friends,
This is regarding synchronization in Thread. If a block or method is synchronized, which object is said to be synchronization?
Thanks for your patience explanation, Masijade.
I can understand the concept now.It takes time for me to take up and sorry for the same.Really good effort to make this clear.Thanks, once again.
Now, it seems to be clear.
void Check()
{
int i=0;
int j=0;
synchronized(t1)
{
while(true)
{
if(i<5)
System.out.println(i+"....Sync block t1 :"+Thread.currentThread().getName());
else
break;
i++;
}
}
synchronized(t2)
{
while(true)
{
if(j<5)
System.out.println(j+"....Sync block t2 :"+Thread.currentThread().getName());
else
break;
j++;
}
}
}
And the output is like this, which makes each sync block parallel.
Run : Test 1
Run : Test 22
0....Sync block t1 :Test 1
1....Sync block t1 :Test 1
2....Sync block t1 :Test 1
3....Sync block t1 :Test 1
4....Sync block t1 :Test 1
0....Sync block t2 :Test 1
0....Sync block t1 :Test 22
1....Sync block t2 :Test 1
1....Sync block t1 :Test 22
2....Sync block t2 :Test 1
2....Sync block t1 :Test 22
3....Sync block t2 :Test 1
3....Sync block t1 :Test 22
4....Sync block t2 :Test 1
4....Sync block t1 :Test 22
0....Sync block t2 :Test 22
1....Sync block t2 :Test 22
2....Sync block t2 :Test 22
3....Sync block t2 :Test 22
4....Sync block t2 :Test 22
Thanks.
Actually,my question is to know the purpose of object.
synchronized(t1)
synchronized(t2)
For anyone of the above, I get the same result.If it is so,then syn. block prototype should be 'synchronized()'. i.e,with passing any parameters.
As far as Output is concerned,
Whichever runs first, it finishes it round upto 20.Then left the other to start & complete its 20.
Is 'synchronized block' is equivalent synchronized method? Its seems to be the same when i tried with a sample.Can u help on this.
public class TestThread implements Runnable
{
static Thread t1,t2;
TestThread()
{
System.out.println("Hello World! ");
int a1=0,a2=0;
t1 = new Thread(this,"Test 1");
t2 = new Thread(this,"Test 22");
t1.start();
t2.start();
}
void Check()
{
int i=0;
//synchronized(System.in) //Behaves as syn. mtd
//synchronized(t1) //Behaves as syn. mtd
synchronized(t2) //Behaves as syn. mtd
{
while(true)
{
if(i<20)
System.out.println(i+"....Sync block :"+Thread.currentThread().getName());
else
break;
i++;
}
}
}
public void run()
{
System.out.println("Run : "+Thread.currentThread().getName());
Check();
}
public static void main(String[] args) throws InterruptedException
{
new TestThread();
}
}
that is.,
say, ob is an Object,
int i = Integer.parseInt((String)ob);
SoRelena,
Check this code.Hope this is what u want.
import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.Runnable;
public class MyApp extends JFrame implements Runnable
{
static boolean stopped = true; // Is the counting stopped? (True or False) --> shared variable
static JTextField number;
JButton startButton,stopButton;
public MyApp()
{
// set the GUI
super( "CAP 332 - Assignment 6: Learning Java Threads" );
startButton = new JButton("Start");
startButton.addActionListener(new ButtonHandler());
startButton.setToolTipText("Click here to start counting.");
stopButton = new JButton("Stop");
stopButton.addActionListener(new ButtonHandler());
stopButton.setToolTipText("Click here to stop counting.");
number = new JTextField(20);
number.setEditable(false);
number.setText("0");
JPanel row1Panel = new JPanel();
JPanel row2Panel = new JPanel();
row1Panel.add(number);
row2Panel.setLayout(new GridLayout(1,2));
row2Panel.add(startButton);
row2Panel.add(stopButton);
// create a split panel to include the 2 row panels
JSplitPane allPanel = new JSplitPane( JSplitPane.VERTICAL_SPLIT, row1Panel, row2Panel );
allPanel.setOneTouchExpandable( false );
allPanel.setDividerLocation( 50 );
getContentPane().add(allPanel);
setSize(500,150);
Thread t = new Thread(this, "MyThread");
t.start();
setVisible( true );
}
public void run()
{
try
{
System.out.println("stopped: "+stopped);
long counter = 1;
while(true)
{
//while (! stopped)
if(! stopped)
{
number.setText(""+counter);
counter ++;
System.out.println(".counter."+counter);
}
}
}
catch (Exception e){}
}
public static void main (String[] args)
{
MyApp app = new MyApp ();
app.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
}
private class ButtonHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
JButton b = (JButton)e.getSource();
if(b==startButton)
{
stopped = false;
}
else if(b==stopButton)
{
stopped = true;
}
}
}
}
Friends,
I hav an application running in system tray.As of now, when I click it,the dialog displays.I want to make this happen by pressing any shortcuts,say,ctrl+Alt+a. Can anyone help on this?
Thanks Ezzaral & masijade, your replies makes me clear now.
That is the instance that all threads must obtain a lock on in order to access the block.
Can u explain in detail,if possible?
Implement Runnable unless you have some specific reason for extending Thread.
Thanks masijade.Still,not clear about this.
Say,test is a class which doesn't hav any parents.In such a case,why should i go specifically for runnable implementation instead Thread inherit.Pls,let me explain,the advantage of using runnable.
Difference between Runnable interface & Thread class?Which one to use, though both seems to be same? As per my knowledge,runnable can be implemented in such a case that already it has some hierarchy
-Thanks in advance
For synchronized block, an object has been passed.The question is,Why & when it is passed & what is the purpose of passing an object?
-Thanks in advance
Thanks for the reply , chronless & gangsta. Actually ,I have done that.But , for better performance only ,i raise this ques. Anyway,
Thanks for the suggestion.
On firing an event at a keyReleased or actionPerformed(button click).This event fires continuosly whenever I click.Say,for 10 clicks, 10 events are in queue.I want to clear remaining 9 events while first processing.
-thanks
This can be done by splitting up send & receive as seperate methods.And by using GroupAddress,
Below link & code might be usefull.
-------------------------------
http://java.sun.com/docs/books/tutorial/networking/datagrams/broadcasting.html
-------------------------------
void BroadcastSend()
{
int iBrcstPort=1600;
String sBroadcast="";
byte b[]=new byte[1000];
try
{
sBroadcast=ta2.getText(); //GetText from JTextArea
sBroadcast=sBroadcast.trim();
mulSoc=new MulticastSocket();
InetAddress BrcstAddress = InetAddress.getByName("230.0.0.1");
mulSoc.joinGroup(BrcstAddress);
b=sBroadcast.getBytes();
DatagramPacket pack = new DatagramPacket(b,b.length,BrcstAddress,iBrcstPort);
mulSoc.send(pack);
//mulSoc.leaveGroup(BrcstAddress);
//mulSoc.close();
}
catch (Exception e)
{
System.out.println("Excep BroadcastSend: "+e);
}
}
void BroadcastReceive()
{
int iBrcstPort=1600;
String sBroadcast="",str="";
byte b[]=new byte[1000];
try
{
mulSoc=new MulticastSocket(iBrcstPort);
InetAddress BrcstAddress = InetAddress.getByName("230.0.0.1");
mulSoc.joinGroup(BrcstAddress);
while(true)
{
DatagramPacket pack = new DatagramPacket(b,b.length);
mulSoc.receive(pack);
str=new String(pack.getData(),0,pack.getLength());
System.out.println("Broadcast From Server : "+str);
}
mulSoc.leaveGroup(BrcstAddress);
mulSoc.close();
}
catch (Exception e)
{
System.out.println("Excep BroadcastReceive: "+e);
}
}
Thanks for the link..I ll check it out.
Can u suggest any better link for datastructure that explains with diagrams?It would be good,if any basic level explanation with algorithms.
Thanks for the info.
Thanks for ur support masijade....I had done it..Its the same way jus like MS-Sql.
Only driver initialisation,
"com.mysql.jdbc.Driver"
And connectionUrl string
"jdbc:mysql://localhost:3306/test"; (here,test is the database to be used)
has been changed.
Thanks a lot.. nice explanation.. which clears my doubt very comfortably.
How can I use Mysql for JDBC connection.How to make data source?
I can able to done with MS-SQL.
Why String comparison with '==' is illegal,eventhough it works fine.Kindly explain?
What is Bottom up & Top-down approach And How it can be implemented in JAVA?
Thanks Ezzaral,
I have gone thru, tried with some basic samples which throws Filenot found exception.
following are the code,
Find the bold line for file path,I dont know how to mention the file path from URL class.
I have tried with some ways like
"file://d:/explica.vlc"
"d:\\explica.vlc"
Can u tell me ,how to mention path from URL class?
import java.awt.Component;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import javax.media.ControllerEvent;
import javax.media.ControllerListener;
import javax.media.Manager;
import javax.media.NoPlayerException;
import javax.media.Player;
import javax.media.RealizeCompleteEvent;
import javax.swing.JPanel;
public class examplePanel extends JPanel implements ActionListener, ControllerListener
{
private static final long serialVersionUID = 1L;
private Component visualComponent;
private Player player;
public examplePanel()
{
try
{
[B]player = Manager.createPlayer(new URL("file://explica.vlc"));[/B] player.addControllerListener(this);
player.start();
}
catch(NoPlayerException e)
{
e.printStackTrace();
}
catch(MalformedURLException e)
{
e.printStackTrace();
}
catch(IOException e)
{
e.printStackTrace();
}
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
}
public void actionPerformed(ActionEvent e)
{
}
public void controllerUpdate(ControllerEvent c)
{
if(player == null)
return;
if(c instanceof RealizeCompleteEvent)
{
if((visualComponent = player.getVisualComponent()) != null)
add(visualComponent);
}
}
}
Hi friends,
I want to make a movie player.I heard about JMF but not had any idea.If anyone knows, kindly help me.
thanks,
ram
Thanks ezzaral.
If anyone has the calendar and willing to share,pls let me know.
Hi friends,
I have to fetch date, month & year from Calendar.For that I need a Calendar with User Interaction from which i can fetch.
Is there any Calendar (builtin) in swing or i have to make it my own?.Pls let me know if u have any idea.
with Thanks,
ramjeev
Hi,
How to create install shield (setup) rpm file in LINUX?
Thanks in advance,
ramjeev
Thanks,
As I know, Windows can allow the MFC exe's to rename while running,but jar file ,i think JVM wont allow.
Hi,
I m trying to get the current path using the following.Its works fine (gets the current working directory) in Windows both in debug & release mode.Whereas, in LINUX ,works only in debug mode but not in release mode.
i.e.,It gets home path(/root) instead current path(/root/ABC/..) while running in release(by clicking jar file)
String Dest = System.getProperty("user.dir");
I dont know why its so.Ur help would be appreciated.
Thanks,
ramjeev
Hi everyone,
I want to disable windows key in keyboard.Please let me know if u hav any idea.
Thanks buddy,
Its cleared in some way now.I m using JscrollBar seperately and JPanel seperately fix both closely so that its seems that its own scroll.I m loaded n number of labels in that panel.When I scroll, i m refreshing the labels with new text,so that its seems to be scroll.
Hi,
I m trying to scroll the JLabel by adding JLabel to Jscrollpane,I can see the scrollbar,but I can't scroll as well as I found JLabel's are misplaced.Can anyone please help me to solve this.
The following is the code,
class outerWindow extends JFrame implements KeyListener,ActionListener
{
Container c = null;
JPanel pane;
public outerWindow()
{
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
c = getContentPane();
pane = new JPanel(null);
pane.setLayout(null);
pane.setBounds(0,0,750,550);
pane.setBackground(Color.gray);
JLabel lab_test = new JLabel("Test");
lab_test.setBounds(0,10,210,1000);
lab_test.setBackground(Color.yellow);
lab_test.setForeground(Color.black);
lab_test.setOpaque(true);
lab_test.setFont(new java.awt.Font("Arial",1,30));
lab_test.setHorizontalAlignment(JTextField.CENTER);
lab_test.setFocusable(false);
lab_test.setVisible(true);
JLabel[] lab = new JLabel[50];
for(int i=0;i<50;i++)
{
lab[i] = new JLabel("new");
lab[i].setBounds(70*(i%3),70*(i/3),70,70);
lab[i].setOpaque(true);
lab[i].setBackground(Color.green);
lab[i].setFont(new java.awt.Font("Arial",1,30));
lab[i].setVerticalAlignment(JTextField.BOTTOM);
JLabel labIn = new JLabel("Boost");
labIn.setBounds(0,0,65,20);
lab[i].add(labIn);
lab_test.add(lab[i]);
}
JScrollPane scrPane = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
scrPane.setBounds(50,10,230,300);
//scrPane .getViewport().add( lab_test);
scrPane.add( lab_test);
pane.add( scrPane , BorderLayout.CENTER );
c.add(pane);
c.setBackground(Color.white);
c.addKeyListener(this);
setSize(800,600);
this.setVisible(true);
c.requestFocus();
}
--Thanks--
Its quite hard to know abt IPC and Processbuilder.Since ,I can't find any ProcessBuilder with the java version 1.4.2_13, I m using.I think its necessary to know abt IPC, pls refer me any tutorial for this to get better idea.
Hi vidaj,
Thanks a lot,
Finally, I make it with ur help.I did with socket communication.
Thanks for the effort, vidaj.
I will try this & let u know.
I too want to know whether B.jar is running or not? because, there is an option in B.jar to exit from itself.
Hi buddies,
I m in need of IPC sample to communicate between two applications.I hav to start one app from another and I want to know whether the second is running or not.If any samples on Interprocess communication,please let me know.
Thanks in advance.