Posts Tagged ‘enterprise-it’

The J2EE platform uses a multitiered distributed application model. Application logic is divided into components according to function, and the various application components that make up a J2EE application are installed on different machines depending on the tier in the multitiered J2EE environment to which the application component belongs. Figure 1-1 shows two multitiered J2EE applications divided into the tiers described in the following list. The J2EE application parts shown in Figure 1-1 are presented in J2EE Components.Client-tier components run on the client machine.

Web-tier components run on the J2EE server.

  • Client-tier components run on the client machine.


  • Web-tier components run on the J2EE server.


  • Business-tier components run on the J2EE server.


  • Enterprise information system (EIS)-tier software runs on the EIS server.

Although a J2EE application can consist of the three or four tiers shown in Figure 1-1, J2EE multitiered applications are generally considered to be three-tiered applications because they are distributed over three different locations: client machines, the J2EE server machine, and the database or legacy machines at the back end. Three-tiered applications that run in this way extend the standard two-tiered client and server model by placing a multithreaded application server between the client application and back-end storage.

Figure 1-1 Multitiered Applications

Today, more and more developers want to write distributed transactional applications for the enterprise and leverage the speed, security, and reliability of server-side technology. If you are already working in this area, you know that in today’s fast-moving and demanding world of e-commerce and information technologyenterprise applications have to be designed, built, and produced for less money, with greater speed, and with fewer resources than ever before.

To reduce costs and fast-track enterprise application design and development, the Java 2 Platform, Enterprise Edition (J2EE) technology provides a component-based approach to the design, development, assembly, and deployment of enterprise applications. The J2EE platform offers a multitiered distributed application model, the ability to reuse components, integratedExtensible Markup Language (XML)-based data interchange, a unified security model, and flexible transaction control. Not only can you deliver innovative customer solutions to market faster than ever, but your platform-independent J2EE component-based solutions are not tied to the products and application programming interfaces (APIs) of any one vendor. Vendors and customers enjoy the freedom to choose the products and components that best meet their business and technological requirements.

This tutorial takes an examples-based approach to describing the features and functionalities available in J2EE Software Development Kit (SDK) version 1.3. Whether you are a new or an experienced enterprise developer, you should find the examples and accompanying text a valuable and accessible knowledge base for creating your own enterprise solutions.

If you are new to J2EE applications development, this chapter is a good place to start. Here you will learn the J2EE architecture, become acquainted with important terms and concepts, and find out how to approach J2EE application programming, assembly, and deployment.

When it comes to downloading videos from Youtube, the first tool that most Linux users think of would be youtube-dl. Youtube-dl is actually a very powerful tool but many people prefer using tools with a graphic user interface, and the best video downloading application for Linux with a GUI in my opinion is ClibGrab. ClibGrab has many useful and interactive features with a very easy-to-use interface. Besides Youtube, ClipGrab also supports other popular video hosting sites, namely,, and More than that, the new version of ClibGrab comes with the YouTube search function integrated so you can search for your favorite videos directly on ClibGrab, without going to youtube to copy-paste the url links as with the older versions. ClipGrab also has the converting options for you to choose the format and quality of the video.

Since it has a very intuitive interface, it’s very easy to use ClibGrab. You can either search for youtube video directly on ClipGrab or just copy-paste the video url into the link box, choose the desired video format and quality then just hit ” Grab this clip” and the downloading process will begin. ClipGrab will auto assign the name of the video to the video file name so it will be easier for you to manage your video library ( if you use youtube-dl, you will need to include the output option to change the name of the downloaded video file). ClipGrab also supports parallel download, means that you can download many videos at the same time. After the downloading finishes, there will be a notification appearing on the system tray.

If you use Arch Linuxhere is the AUR package for ClipGrab. If you use Ubuntu or other Debian-based distros, you can use the following commands to install ClipGrab:

sudo add-apt-repository ppa:clipgrab-team/ppa 
sudo apt-get update 
sudo apt-get install clipgrab 



After importing a package, you can refer to the names it exports.

In Go, a name is exported if it begins with a capital letter.

Foo is an exported name, as is FOO. The name foo is not exported.

Run the code. Then rename math.pi to math.Pi and try it again.

Example :

package main

import (

func main() {


prog.go:9: cannot refer to unexported name math.pi
prog.go:9: undefined: math.pi

after renaming math.pi to math.Pi

package main

import (

func main() {





This code groups the imports into a parenthesized, “factored” import statement. You can also write multiple import statements, like:

	import "fmt"
	import "math"

but it’s common to use the factored form to eliminate clutter.

Example :

package main

import (

func main() {
fmt.Printf(“Now you have %g problems.”,
math.Nextafter(2, 3))


Now you have 2.0000000000000004 problems.



Every Go program is made up of packages.

Programs start running in package main.

This program is using the packages with import paths "fmt" and"math".

By convention, the package name is the same as the last element of the import path.


package main

import (

func main() {
fmt.Println(“Happy”, math.Pi, “Day”)

output :

Happy 3.141592653589793 Day

This tour is also available as a stand-alone program that you can use without access to the internet.

The stand-alone tour is faster, as it builds and runs the code samples on your own machine. It also includes additional exercises not available in this sandboxed version.

To run the tour locally first install Go, then use go get to install gotour:

    go get

and run the resultant gotour executable.

Welcome to a tour of the Go programming language.

The tour is divided into three sections. At the end of each section is a series of exercises for you to complete.

The tour is interactive. Click the Run button now (or type Shift-Enter) to compile and run the program on a remote server. The result is displayed below the code.

These example programs demonstrate different aspects of Go. The programs in the tour are meant to be starting points for your own experimentation.

Edit the program and run it again.

Whenever you’re ready to move on, click the Next button or type the PageDown key.


package main

import “fmt”

func main() {
fmt.Println(“Hello, 世界”)

output :

Hello, 世界
* Q1. How could Java classes direct program messages to the system console, but error messages, say to a file?


A. The class System has a variable out that represents the standard output, and the variable errthat represents the standard error device. By default, they both point at the system console. This how the standard output could be re-directed:


Stream st = new Stream(new FileOutputStream(“output.txt”)); System.setErr(st); System.setOut(st);


* Q2. What’s the difference between an interface and an abstract class?


A. An abstract class may contain code in method bodies, which is not allowed in an interface. With abstract classes, you have to inherit your class from it and Java does not allow multiple inheritance. On the other hand, you can implement multiple interfaces in your class.


* Q3. Why would you use a synchronized block vs. synchronized method?


A. Synchronized blocks place locks for shorter periods than synchronized methods.


* Q4. Explain the usage of the keyword transient?
A. This keyword indicates that the value of this member variable does not have to be serialized with the object. When the class will be de-serialized, this variable will be initialized with a default value of its data type (i.e. zero for integers).

* Q5. How can you force garbage collection?



A. You can’t force GC, but could request it by calling System.gc(). JVM does not guarantee that GC will be started immediately.


* Q6. How do you know if an explicit object casting is needed?


A. If you assign a superclass object to a variable of a subclass’s data type, you need to do explicit casting. For example:


Object a; Customer b; b = (Customer) a;

When you assign a subclass to a variable having a supeclass type, the casting is performed automatically.



* Q7. What’s the difference between the methods sleep() and wait()


A. The code sleep(1000); puts thread aside for exactly one second. The codewait(1000), causes a wait of up to one second. A thread could stop waiting earlier if it receives the notify() or notifyAll() call. The method wait() is defined in the class Object and the method sleep() is defined in the class Thread.


* Q8. Can you write a Java class that could be used both as an applet as well as an application?


A. Yes. Add a main() method to the applet.


* Q9. What’s the difference between constructors and other methods?


A. Constructors must have the same name as the class and can not return a value. They are only called once while regular methods could be called many times.


* Q10. Can you call one constructor from another if a class has multiple constructors


A. Yes. Use this() syntax.


* Q11. Explain the usage of Java packages.


A. This is a way to organize files when a project consists of multiple modules. It also helps resolve naming conflicts when different packages have classes with the same names. Packages access level also allows you to protect data from being used by the non-authorized classes.


* Q12. If a class is located in a package, what do you need to change in the OS environment to be able to use it?


A. You need to add a directory or a jar file that contains the package directories to the CLASSPATH environment variable. Let’s say a class Employee belongs to a package; and is located in the file c:\dev\com\xyz\hr\ In this case, you’d need to add c:\dev to the variable CLASSPATH. If this class contains the method main(), you could test it from a command prompt window as follows:




* Q13. What’s the difference between J2SDK 1.5 and J2SDK 5.0?


A.There’s no difference, Sun Microsystems just re-branded this version.

* Q14. What would you use to compare two String variables – the operator == or the method equals()?

A. I’d use the method equals() to compare the values of the Strings and the == to check if two variables point at the same instance of a String object.

* Q15. Does it matter in what order catch statements for FileNotFoundException and IOExceptipon are written?

A. Yes, it does. The FileNoFoundException is inherited from the IOException. Exception’s subclasses have to be caught first.

* Q16. Can an inner class declared inside of a method access local variables of this method?
A. It’s possible if these variables are final.
* Q17. What can go wrong if you replace && with & in the following code:

String a=null; if (a!=null && a.length()>10) {…}

A. A single ampersand here would lead to a NullPointerException.

* Q18. What’s the main difference between a Vector and an ArrayList

A. Java Vector class is internally synchronized and ArrayList is not.

* Q19. When should the method invokeLater()be used?

A. This method is used to ensure that Swing components are updated through the event-dispatching thread.

* Q20. How can a subclass call a method or a constructor defined in a superclass?
A. Use the following syntax: super.myMethod(); To call a constructor of the superclass, just write super(); in the first line of the subclass’s constructor.

For senior-level developers:

** Q21. What’s the difference between a queue and a stack?
A. Stacks works by last-in-first-out rule (LIFO), while queues use the FIFO rule
** Q22. You can create an abstract class that contains only abstract methods. On the other hand, you can create an interface that declares the same methods. So can you use abstract classes instead of interfaces?

A. Sometimes. But your class may be a descendent of another class and in this case the interface is your only option.
** Q23. What comes to mind when you hear about a young generation in Java?
** Q24. What comes to mind when someone mentions a shallow copy in Java?
A. Object cloning.
** Q25. If you’re overriding the method equals() of an object, which other method you might also consider?
A. hashCode()
** Q26. You are planning to do an indexed search in a list of objects. Which of the two Java collections should you use:
ArrayList or LinkedList?
A. ArrayList
** Q27. How would you make a copy of an entire Java object with its state?
A. Have this class implement Cloneable interface and call its method clone().
** Q28. How can you minimize the need of garbage collection and make the memory use more effective?
A. Use object pooling and weak object references.
** Q29. There are two classes: A and B. The class B need to inform a class A when some important event has happened. What Java technique would you use to implement it?
A. If these classes are threads I’d consider notify() or notifyAll(). For regular classes you can use the Observer interface.
** Q30. What access level do you need to specify in the class declaration to ensure that only classes from the same directory can access it?
A. You do not need to specify any access level, and Java will use a default package access level.

import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;

class ReadAttachment{
public static void main(String [] args)throws Exception{

String host=””;
final String user=””;
final String password=”xxxxx”;//change accordingly

Properties properties = System.getProperties();
properties.setProperty(“”,host );
properties.put(“mail.smtp.auth”, “true”);

Session session = Session.getDefaultInstance(properties,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(user,password);

Store store = session.getStore(“pop3”);

Folder folder = store.getFolder(“inbox”);;

Message[] message = folder.getMessages();
for (int a = 0; a < message.length; a++) {
System.out.println(“————-” + (a + 1) + “———–“);

Multipart multipart = (Multipart) message[a].getContent();

for (int i = 0; i < multipart.getCount(); i++) {
BodyPart bodyPart = multipart.getBodyPart(i);
InputStream stream = bodyPart.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(stream));

while (br.ready()) {


LOAD THE JAR FILE :  C:\> set classpath=mail.jar;activation.jar;


RUN BY :C:\> java ReadAttachment