Archive for July 22nd, 2010

Question by Jaydee: How can I write a java program to check a palindrome of a string?
My Lecturer asked me to write a java program to check a palindrome of a string? Could you kindly show me how to maybe be give an example.

Best answer:

Answer by ducky
boolean isPalindrome(String s){
for (itn i=0; i < string.length()/2; i++)
if (s.charAt(i) != s.charAt(string.length()-i))
return false;
return true;
}

... you might want to check the end points .. but its the general idea

this is a palindrome

asdffdsa

Add your own answer in the comments!

Java Pocket Guide (Pocket Guides) Reviews

Java Pocket Guide (Pocket Guides)

  • ISBN13: 9780596514198
  • Condition: New
  • Notes: BUY WITH CONFIDENCE, Over one million books sold! 98% Positive feedback. Compare our books, prices and service to the competition. 100% Satisfaction Guaranteed

How many times have you reached an impasse while writing code because you couldn’t remember how something in Java worked? This new pocket guide is designed to keep you moving. Concise, convenient and easy to use, the Java Pocket Guide gives you Java stripped down to its bare essentials — in fact, it’s the only book on Java that you can actually fit in your pocket.

Written by Robert and Patricia Liguori, senior software and lead information engineers for Java-based air traffic management

Rating: (out of 7 reviews)

List Price: $ 14.99

Price: $ 7.99

Java Sockets – You Just Got to Plug Them in

Java Sockets – You Just Got to Plug Them in

I realised that programming in Java is quite a fun only after doing it myself. You will be amazed to know that it’s like putting different pieces of puzzle together. You put them relatively in an integrated and coherent manner. The Beauty of it is, that most of the times you dont have to create these pieces yourself. You just customize them according to your need after you get them from an already defined java class or package. It was about programming, now lets talk sumthing about sockets.

Socket is used to establish a point-to-point, bidirectional connection between two entities in a network. Just like a real world socket, it is used to plugin a connection from another source. The connection can be incoming or outgoing or both. Similar is the case at the other end. To understand these socketsĀ  properly, you need to learn a bit about Operating System and its Networking Protocols. Sockets are basically of three types: 1)UNIX Domain Sockets; 2) Internet Domain Sockets; 3) NS domain Sockets.

Java being platform independent Programming language, supports only Internet Domain Sockets as only they are platform independent out of three. These internet domain sockets are distinguished on the basis of Internet protocol they work on…

1) TCP/IP(Transfer Control Protocol): The data transfer is reliable, in-order,connection oriented, so takes connection establishment time before the actual data transfer takes place. Sockets based on TCP/IP are known as Stream Sockets.

2) UDP(User Datagram Protocol): It is connectionless,unrealiable and unordered data transfer protocol. Each packet in it has a destination address associated with it and is realeased into the network to make its own way. The sockets based on UDP are called Datagram Sockets.

3) Raw IP: It is a non-formatted protocol. Unlike TCP/IP, UDP protocols, Raw IP is not a core protocol of IP Suite. It’s different from them as its used to receive header information of the packet along with data, which is not the case in TCP/IP, UDP, they just receive data.

In Java Sockets are mainly implemented from already defined classes and pakages. These are:

1) Java.net.package: It contains all the classes that a user require to create a network based application. The below mentioned classes namely ServerSocket and Socket are also its part. This package also contain classes to create Secure Sockets and to connect a Web Server.

2) ServerSocket Class: It Provides sockets for the Server side.These sockets monitor network for requests or simply waits for them. When such request arrives, a server socket performs assigned task based on the request.

3) Socket Class: This class provides the Client side sockets. These sockets connect to the server, send and receive data for the client.

Remember, no socket can work without a port which is identified by a port no. Port is a gateway to a socket connectivity which is on the both sides of network. A socket is mainly identified as per its ports.

Find More Java Articles