Tuesday 13 March 2012

Replace all occurrences of specified element of Java ArrayList Example

1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import java.util.ArrayList;
import java.util.Collections;
 
public class ReplaceAllArrayListExample {
 
  public static void main(String[] args) {
   
    //create an ArrayList object
    ArrayList arrayList = new ArrayList();
   
    //Add elements to Arraylist
    arrayList.add("A");
    arrayList.add("B");
    arrayList.add("A");
    arrayList.add("C");
    arrayList.add("D");
 
    System.out.println("ArrayList Contains : " + arrayList);
   
    
    Collections.replaceAll(arrayList, "A","Replace All");
   
    System.out.println("After Replace All, ArrayList Contains : " + arrayList);
  }
}
 
/*
Output would be
ArrayList Contains : [A, B, A, C, D]
After Replace All, ArrayList Contains : [Replace All, B, Replace All, C, D]
*/

Remove first and last elements of LinkedList Java example

1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import java.util.LinkedList;
 
public class RemoveFirstLastElementsLinkedListExample {
 
  public static void main(String[] args) {
   
    //create LinkedList object
    LinkedList lList = new LinkedList();
   
    //add elements to LinkedList
    lList.add("1");
    lList.add("2");
    lList.add("3");
    lList.add("4");
    lList.add("5");
   
    System.out.println("LinkedList contains : " + lList);
   
     Object object = lList.removeFirst();
     System.out.println(object + " has been removed from the first index
                                                           of LinkedList");
     System.out.println("LinkedList now contains : " + lList);
       
      object = lList.removeLast();
      System.out.println(object + " has been removed from the last index
                                                           of LinkedList");
      System.out.println("LinkedList now contains : " + lList);
 
  }
}
 
/*
Output would be
 
LinkedList contains : [1, 2, 3, 4, 5]
1 has been removed from the first index of LinkedList
LinkedList now contains : [2, 3, 4, 5]
5 has been removed from the last index of LinkedList
LinkedList now contains : [2, 3, 4]
*/

more Servlets and JavaServer Pages eBook Download

more Servlets and JavaServer PagesMarty Hall's Core Servlets and JavaServer Pages was last year's #1 servlet/JSP book helping over 100,000 Java developers master the power of Java server-side programming to Web-enable an extraordinary range of applications. Now, Hall takes the next step, bringing together even more powerful servlet/JSP techniques.

After a quick review of the basics, Hall presents in-depth coverage of the latest servlet and JSP capabilities incorporated in JDK Version 1.4, including filters, application events, and enhancements to JSP's XML support. Next, Hall moves on to Web application development, introducing the latest Servlet 2.3/JSP 1.1 features, and offering in-depth coverage of the Web Application Deployment Descriptor.

 More Servlets and JavaServer Pages includes a comprehensive section introducing the new tag library features incorporated in JSP 1.2, including a full chapter on Apache tag libraries. Hall concludes with an exceptionally comprehensive library of techniques for performance optimization, from caching to content compression, metering and connection pooling to changing JVM parameters. The book also includes a full chapter on Web application security, as well as a start-to-finish case study application.

Part I gives a thorough introduction to programming with servlet and JSP technology. It shows you how to configure your server, read form data and HTTP headers, handle cookies, track sessions, apply JSP scripting elements, use JavaBeans components, develop JSP tag libraries, and apply the MVC architecture.

Part II provides exhaustive details on Web application development and deployment. It explains how to register Web applications, how to organize them, how to deploy them in WAR files, how to deal with relative URLs, and how to share data among Web applications. It also gives details on every element in version 2.3 of the deployment descriptor (web.xml).

Part III describes Web application security in detail. It explains two general strategies for securing your applications: declarative security and programmatic security. Within each of these strategies, it shows you how to use form-based or BASIC authentication and how to protect your network traffic with SSL.

Part IV covers two features introduced with servlets 2.3: filters and life-cycle events. It explains how to use filters to debug, modify, and optimize the output of previously existing servlets and JSP pages. It also shows you how to use event listeners to respond to major events in the server life cycle.

Part V looks at new tag library developments. It shows you how to improve your own tag libraries by making use of new capabilities of the JSP 1.2 specification and explains how to streamline your code by using the new standard JSP tag library (JSPTL).

Data Structures with Java, Second Edition by JohnR.Hubrand

Data Structures with JavaScores of problems and examples—which will be available on the Internet after publication—simplify and demonstrate central concepts and help users develop their expertise in handling data structures in Java .
 
• Java is today’s fastest growing programming language, with broad popular appeal for its ease of use in creating websites and its functioning capability on any platform 
• Topics cover all the material in the first- or second-year course required of all Computer Science majors

From the Back Cover
Master the fundamentals of data structures with Java with Schaum’s—the high-performance study guide. It will help you cut study time, hone problem-solving skills, and achieve your personal best on exams and projects!
Students love Schaum’s Outlines because they produce results. Each year, hundreds of thousands of students improve their test scores and final grades with these indispensable study guides.

About the Author
Jean R. Hubbard, Ph.D. (Richmond, VA) is Professor of Mathematics and Computer Science at the University of Richmond. He is the author of the popular Schaum's Outline Programming with C++ and Programming with Java.

Learning Jakarta Struts 1.2 ebook Download

Product DescriptionThis book is designed as a rapid and effective Struts tutorial for Java developers. The book builds a fully-featured web bookstore application incrementally, with each stage described step-by-step. Concepts are introduced simply and clearly as the design and implementation of this sample project evolves.

The emphasis is on rapid learning through clear and well structured examples. This book is written for Java developers planning to develop web applications, who are new to Struts. It expects familiarity with Java, JSP and Servlets to a degree, although more obscure elements are explained. It covers Struts 1.2.

About the Author
Stephan Wiesner was born in October 1973 in L¿neburg, Germany. He graduated in business informatics in 2003. He got introduced to Struts during his studies. He didn't understand the official documentation for Struts and therefore started to develop his own documentation. Feedback from all over the world encouraged him and finally he published it as a book. He currently lives and works in Lucerne, Switzerland, as a QS consultant and test manager.

Manning-Struts 2 in Action ebook Download

The original Struts project revolutionized Java web development and its rapid adoption resulted in the thousands of Struts-based applications deployed worldwide. Keeping pace with new ideas and trends, Apache Struts 2 has emerged as the product of a merger between the Apache Struts and OpenSymphony WebWork projects, united in their goal to develop an easy-to-use yet feature-rich framework. Struts 2 represents a revolution in design and ease of use when compared to classic Struts. It adds exciting and powerful features such as a plugin framework, JavaServer Faces integration, and XML-free configuration.

Struts 2 In Action introduces the Apache Struts 2 web application framework and shows you how to quickly develop professional, production-ready modern web applications. Written by Don Brown, one of the leading developers of Struts 2, Chad Davis, a passionate Struts 2 developer, along with Scott Stanlick, this book gently walks you through the key features of Struts 2 in example-driven, easy-to-digest sections.

Struts 2 in Action delivers accurate, seasoned information that can immediately be put to work. This book is designed for working Java web developers-especially those with some background in Struts 1 or WebWork. The core content, covering key framework components such as Actions, Results, and Interceptors, includes new features like the annotation-based configuration options. You'll find chapters on Struts 2 plugins, FreeMarker, and migration from Struts 1 and WebWork 2. Finally, new topics such as the Ajax tags, Spring Framework integration, and configuration by convention give familiar subjects new depth.

Calculate difference in days between two dates

1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import java.util.Calendar;
 
public class DateDifferenceExample{
 
        public static void main(String[] args){
       
        //get instance of Calendar objects
        Calendar cal1 = Calendar.getInstance();
        Calendar cal2 = Calendar.getInstance();
       
        //set two dates we want to know difference of
        cal1.set(2006, 12, 30);
        cal2.set(2007, 5, 3);
       
        long milis1 = cal1.getTimeInMillis();  
        long milis2 = cal2.getTimeInMillis();
       
        //difference in milliseconds
        long diff = milis2 - milis1;
       
        //difference in seconds
        long diffSeconds = diff / 1000;
       
        //difference in minutes
        long diffMinutes = diff / (60 * 1000);
       
        //difference in hours
        long diffHours = diff / (60 * 60 * 1000);
       
        //difference in days
        long diffDays = diff / (24 * 60 * 60 * 1000);
       
        System.out.println("Date difference in milliseconds: " + diff + " milliseconds.");     
        System.out.println("Date difference in seconds: " + diffSeconds + " seconds.");
        System.out.println("Date difference in minutes: " + diffMinutes + " minutes.");
        System.out.println("Date difference in hours: " + diffHours + " hours.");      
        System.out.println("Date difference in days: " + diffDays + " days.");
       
        }
}
 
/*
Output of above date difference program would be
Date difference in milliseconds: 10713600000 milliseconds.
Date difference in seconds: 10713600 seconds.
Date difference in minutes: 178560 minutes.
Date difference in hours: 2976 hours.
Date difference in days: 124 days.
*/

Monday 12 March 2012

Java The Complete Reference 7the Edition Download


The world's leading programming author offers comprehensive coverage of the new Java release

The definitive guide to Java has been fully expanded to cover every aspect of Java SE 6, the latest version of the worldAnd#39;s most popular Web programming language. This comprehensive resource contains everything you need to develop, compile, debug, and run Java applications and applets.

The Definitive Guide for Java Programmers

In this comprehensive resource, top-selling programming author Herbert Schildt shows you everything you need to develop, compile, debug, and run Java programs. This expert guide has been updated for Java Platform Standard Edition 6 (Java SE 6) and offers complete coverage of the Java language, its syntax, keywords, andfundamental programming principles.

You'll also find information on Java's key API libraries, learn to create applets and servlets, and use JavaBeans. Herb has even included expanded coverage of Swing--the toolkit that defines the look and feel of the modern Java GUI. Essential for every Java programmer, this lasting resource features the clear, crisp, uncompromising style that has made Herb the choice of millions of programmers worldwide.
Coverage includes:

  • Data types and operators
  • Control statements
  • Classes and objects
  • Constructors and methods
  • Interfaces and packages
  • Method overloading and overriding
  • Inheritance
  • Exception handling
  • Generics
  • Autoboxing
  • Enumerations
  • Annotations
  • The enhanced for loop
  • Varargs (variable-length arguments)
  • Multithreading
  • The I/O classes
  • Networking
  • The Collections Framework
  • Applets and servlets
  • AWT and layout managers
  • JavaBeans
  • Swing
  • The Concurrent API
  • Much, much more

Download Object Oriented Programming with Java eBook

An Introduction to Object-Oriented Programming with Java takes a full-immersion approach to object-oriented programming. Proper object-oriented design practices are emphasized throughout the book. Students learn how to use the standard classes first, then learn to design their own classes.

Wu uses a gentler approach to teaching students how to design their own classes, separating the coverage into two chapters. GUI coverage is also located independently in the back of the book and can be covered if desired.

Wu also features a robust set of instructors' materials including PowerPoint slides, code samples, and quiz questions.
C. Thomas Wu, "An Introduction to Object-Oriented Programming with Java, 5th Edition"

Hibernate in Action ebook Download

Hibernate practically exploded on the Java scene. Why is this open-source tool so popular? Because it automates a tedious task: persisting your Java objects to a relational database. The inevitable mismatch between your object-oriented code and the relational database requires you to write code that maps one to the other. This code is often complex, tedious and costly to develop. Hibernate does the mapping for you.

Not only that, Hibernate makes it easy. Positioned as a layer between your application and your database, Hibernate takes care of loading and saving of objects. Hibernate applications are cheaper, more portable, and more resilient to change. And they perform better than anything you are likely to develop yourself.


Hibernate in Action carefully explains the concepts you need, then gets you going. It builds on a single example to show you how to use Hibernate in practice, how to deal with concurrency and transactions, how to efficiently retrieve objects and use caching.
The authors created Hibernate and they field questions from the Hibernate community every day - they know how to make Hibernate sing. Knowledge and insight seep out of every pore of this book.


What is lazy loading in Hibernate?

Lazy setting decides whether to load child objects while loading the Parent Object.You need to do this setting respective hibernate mapping file of the parent class.lazy = true (means not to load child)By default the lazy loading of the child objects is true. This make sure that the child objects are not loaded unless they are explicitly invoked in the application by calling getChild()method on parent.In this case hibernate issues a fresh database call to load the child whengetChild() is actully called on the Parent object.But in some cases you do need to load the child objects when parent is loaded. Just make the lazy=false and hibernate will load the child when parent is loaded from the database.
                      
                                Example: lazy=true (default)Address child of User class can be made lazy if it is not required frequently. lazy=false but you may need to load the Author object for Book parent whenever you deal with the book for online bookshop.

Lazy fetching means for example in hibernate if we use load() method then load() is lazy fetching i.e it is not going to touch the database until we write empobject.getString( eno );So when we write above statement in that instance it touch the database and get all the data from database. It is called as lazy loading.If we see another example i.e session.get(...) method is used then at that instance it is going to touch the database and get the data and place the data in session object it is called as eager loading.

Java Interview Questions Downlaod

You may be an experienced Java developer with hand on experience in core development or you may be a fresher who is looking for an entry in java job market, if you want to hit the job market , you may need to refresh some of the basic java terms or you may need to know what are the commonly asked questions to prepare yourself to for java technical interview.
You as an experienced java developer, just need to refresh your knowledge on java. But you as a fresher may need to know what can be the possible questions , what are the commonly asked questions, what are the valid answers for these questions and so on.

Here we are offering you some questions that we faced during different interviews. We have classified these questions into different sections like Core Java interview questions, Servlets JSP interview questions, EJB interview questions
, JMS interview questions, JDBC interview questions, Swing interview questions, J2EE interview questions, RMI interview questions, Design Patterns interview questions, etc. Depending on the categories, technologies and the availability of questions, the number of questions vary from 10 to 100 or even more.

We always welcome your feedback about the interview questions offered by us. In addition to the categories like core java , EJB, JSP, Servlets, ... we need more and more categories, more questions and answers. So if you have some questions, please help us with your questions. May be it is from core java, JSP, Servlets, or may be from some other java related technology that is not listed here, no problem . We need it. The java community needs it.

HeadFirst Servlets and Jsp 2nd Edition ebook Download

HeadFirst Servlets and Jsp 2nd Edition ebook DownloadWant to get to know the latest (J2EE 1.4) versions of Servlets and JSPs so well that you can pass the Sun Certified Web Component Developer (SCWCD) 1.4 exam? No problem! Head First Servlets & JSP will show you how to write servlets and JSPs, what makes the Container tick, how to use the new JSP Expression Language (EL), and much more. You won't just pass the exam, you will truly understand this stuff and be able to put it to work right away.







Sun Certified Java Programmer by Kathy Sierra ebook Download

With hundreds of practice questions and hands-on exercises, SCJP Sun Certified Programmer for Java 6 Study Guide covers what you need to know--and shows you how to prepare--for this challenging exam.
  • 100% complete coverage of all official objectives for exam 310-065
  • Exam Objective Highlights in every chapter point out certification objectives to ensure you're focused on passing the exam
  • Exam Watch sections in every chapter highlight key exam topics covered
  • Simulated exam questions match the format, tone, topics, and difficulty of the real exam
Covers all SCJP exam topics, including:


Declarations and Access Control · Object Orientation · Assignments · Operators · Flow Control, Exceptions, and Assertions · Strings, I/O, Formatting, and Parsing · Generics and Collections · Inner Classes · Threads · Development

Effective Java (2nd Edition) Programming Language


 Effective Java™, Second EditionAre you looking for a deeper understanding of the Java™ programming language so that you can write code that is clearer, more correct, more robust, and more reusable? Look no further! Effective Java™, Second Edition, brings together seventy-eight indispensable programmer’s rules of thumb: working, best-practice solutions for the programming challenges you encounter every day.


This highly anticipated new edition of the classic, Jolt Award-winning work has been thoroughly updated to cover Java SE 5 and Java SE 6 features introduced since the first edition. Bloch explores new design patterns and language idioms, showing you how to make the most of features ranging from generics to enums, annotations to autoboxing.


Each chapter in the book consists of several “items” presented in the form of a short, standalone essay that provides specific advice, insight into Java platform subtleties, and outstanding code examples. The comprehensive descriptions and explanations for each item illuminate what to do, what not to do, and why.

Highlights include:
  • New coverage of generics, enums, annotations, autoboxing, the for-each loop, varargs, concurrency utilities, and much more
  • Updated techniques and best practices on classic topics, including objects, classes, libraries, methods, and serialization
  • How to avoid the traps and pitfalls of commonly misunderstood subtleties of the language
  • Focus on the language and its most fundamental libraries: java.lang, java.util, and, to a lesser extent, java.util.concurrent and java.io

Head-First core Java-2nd Edition Download


Learning a complex new language is no easy task especially when it s an object-oriented computer programming language like Java. You might think the problem is your brain. It seems to have a mind of its own, a mind that doesn't always want to take in the dry, technical stuff you're forced to study. 
Head-First core Java-2nd Edition Download
The fact is your brain craves novelty. It's constantly searching, scanning, waiting for something unusual to happen. After all, that's the way it was built to help you stay alive. It takes all the routine, ordinary, dull stuff and filters it to the background so it won't interfere with your brain's real work--recording things that matter. How does your brain know what matters? It's like the creators of the Head First approach say, suppose you're out for a hike and a tiger jumps in front of you, what happens in your brain? Neurons fire. Emotions crank up. Chemicals surge. 
That's how your brain knows.

And that's how your brain will learn Java. Head First Java combines puzzles, strong visuals, mysteries, and soul-searching interviews with famous Java objects to engage you in many different ways. It's fast, it's fun, and it's effective. And, despite its playful appearance, Head First Java is serious stuff: a complete introduction toobject-oriented programming and Java. You'll learn everything from the fundamentals to advanced topics, including threads, network sockets, and distributed programming with RMI. And the new. second edition focuses on Java 5.0, the latest version of the Java language and development platform. Because Java 5.0 is a major update to the platform, with deep, code-level changes, even more careful study and implementation is required. So learning the Head First way is more important than ever. 

If you've read a Head First book, you know what to expect--a visually rich format designed for the way your brain works. If you haven't, you're in for a treat. You'll see why people say it's unlike any other Java book you've ever read.

By exploiting how your brain works, Head First Java compresses the time it takes to learn and retain--complex information. Its unique approach not only shows you what you need to know about Java syntax, it teaches you to think like a Java programmer. If you want to be bored, buy some other book. But if you want to understand Java, this book's for you. 


Related Posts Plugin for WordPress, Blogger...