Java Rules #Java Short Notes

  • Do not synchronize an instance variable or a code block without an object – it is illegal in Java
  • a synchronized context: wait(), notifyAll() – may be required to be called
  • Do not add a checked exception to an overridden method
  • A superclass does not have to be serializable, but its constructor will run when a serializable subclass instance is deserialized.
  • Loose coupling: you can change the implementation of a class without affecting the other classes. For example, if two classes say A and B – do not use each other at all (no instantiation of the other or no method calling ), they are not coupled. If A uses B but B does not use A, then they are loosely coupled. If both A and B use each other, then they are tightly coupled.Loose coupling expects that a class should keep its members private and that the other class should access themthrough getters and setters

From: http://sitestree.com/?p=4910
Categories:Java Short Notes
Tags:
Post Data:2010-02-08 12:34:16

Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada

Generics in Java #Java Short Notes

  • Generics can prevent many run time errors.
  • A generic class:
    public class Box {    private T t; // T stands for "Type"              public void add(T t) {        this.t = t;    }    public T get() {        return t;    }}Object creation:
    Box integerBox = new Box();
  • Generic method syntax: public void inspect(U u){}
  • Type Erasure:Check this code:
    public class MyClass {    public static void myMethod(Object item) {        if (item instanceof E) {  //Compiler error            ...        }        E item2 = new E();   //Compiler error        E[] iArray = new E[10]; //Compiler error        E obj = (E)new Object(); //Unchecked cast warning    }}

From: http://sitestree.com/?p=4902
Categories:Java Short Notes
Tags:
Post Data:2007-10-28 07:08:01

Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada

Java: Common Architectures #Java Short Notes

From: http://sitestree.com/?p=4890
Categories:Java Short Notes
Tags:
Post Data:2010-06-02 07:22:23

Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada

SCEA:Security in Java: Potential threats to a system and how to address the threats:Java Enterprise Architect #Java Short Notes

  • Input Validation Failures: Input should be validated both at the client end and the server end (before any processing). Validating both from trusted and untrusted sources is important. Otherwise code injection attack may happen. Validation should include: data type (string, integer), format, length, range, null-value handling, verifying for character-set, locale, patterns, context, legal values and validity, and so on.
  • Output Sanitation: If you display the user entered values or if the generated output contains a significant use of the input values, in some cases, the user may be able to relate the output to the input. The user may provide malicious data to display say a pop up or an affiliate ad or to break the system.
  • Buffer Overflow: Some users may try to cause buffer overflow and hence, break the system. This may be part of a denial of service attack. Suppose you have set a not null table column to be of size 50 and did not validate the input, then data > 50 chars may break the system based on the operations and platforms. Or a user can just insert huge amount of data to eat up your server resources.
  • Data Injection Flaw: In this case, security intruders can try to pass sql queries as part of their data to get useful information or to break your system.
  • Cross-Site Scripting (XSS):
  • Improper Error Handling: In case of errors, such as, out of memory, null pointer exceptions, system call failure, database access failure, network timeout many applications display detailed internal error messages. Based on the error messages (weak points), hackers may be able to design an attack.
  • Insecure Data Transit or Storage: Data in storage or transit when represented as plain text are vulnerable to attack. Encryption algorithms may help in these situations.
  • Weak Session Identifiers: If you assign session identifiers before user authentication or display session identifier in plain text, hackers may spoof user identity and do harmful business transactions.
  • Weak Security Tokens:
  • Weak Password Exploits: Passwords, many times, can be guessed or watched or retrieved by using password-cracking tools to obtain data from password files. Strong authentication or multifactor authentication mechanisms using digital certificates, biometrics, or smart cards is strongly recommended.
  • Weak Encryption:
  • Session Theft:
  • Insecure Configuration Data:
  • Broken Authentication:
  • Broken Access Control:
  • Policy Failures:
  • Audit and Logging Failures:
  • Denial of Service (DoS) and Distributed DOS (DDoS):
  • Man-in-the-Middle (MITM):
  • Multiple Sign-On Issues:
  • Deployment Problems:
  • Coding Problems:

From: http://sitestree.com/?p=4886
Categories:Java Short Notes
Tags:
Post Data:2013-03-23 01:58:45

Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada

Sun certifications: Topics #Java Short Notes

From: http://sitestree.com/?p=4885
Categories:Java Short Notes
Tags:
Post Data:2008-10-21 15:25:38

Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada

Code Conventions for the Java Programming Language #Java Short Notes

Why Have Code Conventions?

  • 80% of software life cycle is spent on software maintenance.
  • Hardly the original author maintains a software
  • Code Conventions improve the readability of the software
  • If you require to ship your source code as a product, code conventions make your product well packaged

Java Code Conventions

  • Avoid assigning several variables to the same value in a single statement
  • Avoid using an object to access a class (static) variable or method. Use a class name instead
  • Don’t make any instance or class variable public without good reason. When the class is essentially a data structure, you can use public instance variables
  • Two blank lines: Between sections of a source file, between class and interface definitions
  • One blank line: Between methods, between the local variables in a method and its first statement, before a block or single-line, between logical sections inside a method
  • Blank spaces: Between a keyword and parenthesis, after commas in argument lists, after Casts
  • Each line should contain at most one statement
  • One declaration per line is recommended
  • Initialize local variables where they’re declared
  • Put declarations only at the beginning of blocks
  • No space between a method name and the parenthesis
  • Methods are separated by a blank line
  • Four styles of implementation comments: block, single-line, trailing, and end-of-line
  • Documentation comments describe Java classes, interfaces, constructors, methods, and fields. Use /**…*/ for doc comments
  • Doc comments: One comment per class, interface, or member
  • Doc comments: Should appear just before the declaration
  • Avoid lines longer than 80 characters
  • Break longer lines: after a comma, before an operator, Prefer higher-level breaks to lower-level breaks, align new lines with the previous line, or indent the new line with 8 spaces
  • You can get a detailed code conventions at Java Code Conventions

From: http://sitestree.com/?p=4865
Categories:Java Short Notes
Tags:
Post Data:2012-09-01 18:46:01

Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada

Java Collection Framework #Java Short Notes

Array
Benefits Constraints
  • Data access is fast.
  • Good for ordered data, which is not changed or searched frequently.
  • Inefficient if number of elements grow.
  • Inefficient if an element to be inserted in middle of collection.
  • Provides no special search mechanism.
Linked List
Benefits Constraints
  • Allows efficient inserts/delete at any location
  • Allows arbitrary growth of collection.
  • Applying order to the elements is easy.
  • Slower while accessing elements by index.
  • No special search mechanism is provided.

Tree
Benefits Constraints
  • Easy addition/deletion in middle.
  • Allows arbitrary growth.
  • A better and efficient search mechanism.
  • Ordering is peculiar and some comparison mechanism is required.
  • Searching is not efficient for unevenly distributed data.

Hashtable
Benefits Constraints
  • Efficient searching.
  • Good access mechanism.
  • Allows arbitrary growth of collection.
  • Not good for small data set because of overheads.
  • Overhead for storing keys for the values in collection.
  • Overhead of hashing scheme.

From: http://sitestree.com/?p=4861
Categories:Java Short Notes
Tags:
Post Data:2007-06-09 22:01:31

Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada

JDBC: Stored Procedure #Java Short Notes

Sample stored procedure call using JDBC:Call stored procedure to change/set a value in the database

//set birthday - supply professor nametry{ String professor= "dylan thomas"; CallableStatement proc = connection.prepareCall("{ call set_birth_date(?, ?) }"); proc.setString(1, professor); proc.setString(2, '1950-01-01'); cs.execute();}catch (SQLException e){ // ....}Stored procedures can also return result/data to the caller: like//return birth dayconnection.setAutoCommit(false);CallableStatement proc = connection.prepareCall("{ ? = call birthday_when(?) }");proc.registerOutParameter(1, Types.Timestamp);proc.setString(2, professorName);cs.execute();Timestamp age = proc.getString(2);Stored procedures can also return complex data like resultsets. JDBC drivers from oracle, Sql Server, PostgreSQL support this.

From: http://sitestree.com/?p=4839
Categories:Java Short Notes
Tags:
Post Data:2010-07-30 07:32:42

Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada

Comparison EJB 2 and EJB 3 #Java Short Notes

Comparison EJB 2 and EJB 3

  1. EJB 2.0 has deployment descriptors but EJB 3.0 has no deployment descriptor
  2. In EJB 2.0 you have to write Home and Remote Interfaces But in EJB3.0 you do not need to write Home interfaces
  3. In EJB 3.0, all entities are identified with ‘@’
  4. In EJB 3.0 methods like ejbPassivate, ejbActivate, ejbLoad, ejbStore, etc. are not required
  5. EJB 3.0 is totally newly designed including the entity manager
  6. EJB 3.0 entity beans are just POJO
  7. No EJB container required to run
  8. EJB 3.0 supports Java Persistence API for all of its data needs
  9. No XMLDeployment Descriptors but annotations
  10. EJB 3.0 entity beans/JPA becomes local
  11. Queries are very flexible. Multiple levels of joins are enabled
  12. EJB 3.0 pluggable, security enabled

From: http://sitestree.com/?p=4835
Categories:Java Short Notes
Tags:
Post Data:2009-04-17 12:57:04

Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada

EJB 3: Entity Bean Basic #Java Short Notes

Plain Java objects with persistence storage. They are not remotable and must be accessed through the new javax.persistence.EntityManager service. An entity bean implementation is provided in the following three files/classesBeansOrder.javaLineItem.javaEntity ManagerShoppingCartBean.java//Order.javaimport javax.persistence.CascadeType;import javax.persistence.Entity;import javax.persistence.FetchType;import javax.persistence.GeneratedValue; import javax.persistence.GenerationType;import javax.persistence.Id;import javax.persistence.OneToMany;import javax.persistence.Table;import javax.persistence.Id;import javax.persistence.CascadeType;import javax.persistence.FetchType;import java.util.ArrayList;import java.util.Collection;@Entity@Table(name = "PURCHASE_ORDER")public class Order implements java.io.Serializable{   private int id;   private double total;   private Collection lineItems;   @Id @GeneratedValue(strategy=GenerationType.AUTO)   public int getId()   {      return id;   }   public void setId(int id)   {      this.id = id;   }   public double getTotal()   {      return total;   }   public void setTotal(double total)   {      this.total = total;   }   public void addPurchase(String product, int quantity, 	double price)   {      if (lineItems == null) lineItems = new ArrayList();      LineItem item = new LineItem();      item.setOrder(this);      item.setProduct(product);      item.setQuantity(quantity);      item.setSubtotal(quantity * price);      lineItems.add(item);      total += quantity * price;   }   @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, 	mappedBy="order")   public Collection getLineItems()   {      return lineItems;   }   public void setLineItems(Collection lineItems)   {      this.lineItems = lineItems;   }}//LineItem.javaimport javax.persistence.Entity;import javax.persistence.GeneratedValue; import javax.persistence.GenerationType;import javax.persistence.Id;import javax.persistence.JoinColumn;import javax.persistence.ManyToOne;import javax.persistence.Entity;@Entitypublic class LineItem implements java.io.Serializable{   private int id;   private double subtotal;   private int quantity;   private String product;   private Order order;   @Id @GeneratedValue(strategy=GenerationType.AUTO)   public int getId()   {      return id;   }   public void setId(int id)   {      this.id = id;   }   public double getSubtotal()   {      return subtotal;   }   public void setSubtotal(double subtotal)   {      this.subtotal = subtotal;   }   public int getQuantity()   {      return quantity;   }   public void setQuantity(int quantity)   {      this.quantity = quantity;   }   public String getProduct()   {      return product;   }   public void setProduct(String product)   {      this.product = product;   }   @ManyToOne   @JoinColumn(name = "order_id")   public Order getOrder()   {      return order;   }   public void setOrder(Order order)   {      this.order = order;   }}//ShoppingCartBean.javaInteracts with Order as a plain Java object. The checkout() method stores orders with persistence storage by using the required EntityManager service.import javax.ejb.Remote;import javax.ejb.Remove;import javax.ejb.Stateful;import javax.persistence.EntityManager;import javax.persistence.PersistenceContext;import javax.persistence.PersistenceContext;@Stateful@Remote(ShoppingCart.class)public class ShoppingCartBean implements ShoppingCart, 	java.io.Serializable{   @PersistenceContext   private EntityManager manager;   private Order order;   public void buy(String product, int quantity, double price)   {      if (order == null) order = new Order();      order.addPurchase(product, quantity, price);   }   public Order getOrder()   {      return order;   }   @Remove   public void checkout()   {      manager.persist(order);   }} GNU Distribution Without Warranty License

From: http://sitestree.com/?p=4834
Categories:Java Short Notes
Tags:
Post Data:2011-12-03 23:27:24

Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada