Skip to main content

Java Basic Knowledge - Part 1

public class Card{
// instance variables:
private String number;
//Accessor methods:
public STring getNumber(){return number;}
//Action methods:
public boolean isNumberCorrect(..){}

{  curly brace for the opening of the method body
} curly brace for the closing of the method body
In Java, any set of statements between braces "{" and "}" define a program block;

; semicolon indicating the end of the statement

Data of Java Objects are stored in instance variables(also called fields);

The operations that can act on data, expressing the "messages" objects respond to are called methods;
A method's name combined with the number and types of its parameters is called a method's signature, for it takes all these parts to determine the actual method to perform for a certain method call. The signature of a method does not include the type that the method returns;

the syntax for defining a method is as follows:
modifiers type name(type0 parameter0, .., typen-1 parametern-1){
//method body

The name of a class, method, or variable in Java is called identifier, which can be any string of characters as long as it begins with a letter and consists of letters, numbers, and underscore characters.

Class modifiers are optional keywords that precede the class keyword.

base type numbers are not themselves objects, to get around this obstacle, Java defines a wrapper class for each numeric base Type. We call these classes number classes.

A literal is any "constant" value that can be used in an assignment or other expression. e.g. null, true , false,  1.12 or String Literal like " you are good"

Java expressions involve composing literals and variables with operators. e.g. + , - , and etc
Logic Operator: <= , == , !== , > , < , ! and etc.
String Concatenation Operator(+)

Casting  is an operation that allows us to change the type of a variable. In essence, we can take a variable of one type and cast it into an equivalent variable of another type.
Ordinary Casting: when casting from a double to an int, we may lose precision. But we cast an int to a double without this worry.
There are cases where Java will perform an implicit cast to the type of the assignment variable, provided there is no loss of precision. int i =3 ; double result, d = 3.2; result = i/d; // i was cast to a double

Autoboxing(since java 5.0), will convert the base type to its corresonsidng Number object.

Integer i = new Integer(9);
Integer j = new Integer(13);
int k = 9 + 13;    // always OK
Integer l = i + j; // error in versions prior to 5.0!

Likewise, any time a base type is expected in an expression involving Number reference,  that Number object is changed to the corresponding base type, in an operation called unboxing.
int i = 4;
int j = 5;
Integer k = new Integer(i + j); // always OK
Integer l = i + j; // would have been an error, but okay now 


Popular posts from this blog

Stretch a row if data overflows in jasper reports

It is very common that some columns of the report need to stretch to show all the content in that column. But  if you just specify the property " stretch with overflow' to that column(we called text field in jasper report world) , it will just stretch that column and won't change other columns, so the row could be ridiculous. Haven't find the solution from internet yet. So I just review the properties in iReport one by one and find two useful properties(the bold highlighted in example below) which resolve the problems.   example:
<band height="20" splitType="Stretch"> <textField isStretchWithOverflow="true" pattern="" isBlankWhenNull="true"> <reportElement stretchType="RelativeToTallestObject" mode="Opaque" x="192" y="0" width="183" height="20"/> <box leftPadding="2"> <pen lineWidth="0.25"/> …

JasperReports - Configuration Reference

Live - solving the jasper report out of memory and high cpu usage problems

I still can not find the solution. So I summary all the things and tell my boss about it. If any one knows the solution, please let me know.

Symptom: 1.The JVM became Out of memory when creating big consumption report 2.Those JRTemplateElement-instances is still there occupied even if I logged out the system
Reason:         1. There is a large number of JRTemplateElement-instances cached in the memory 2.The clearobjects() method in ReportThread class has not been triggered when logging out
Action I tried:      About the Virtualizer: 1.Replacing the JRSwapFileVirtualizer with JRFileVirtualizer 2.Not use any FileVirtualizer for cache the report in the hard disk Result: The japserreport still creating the a large number of JRTemplateElement-instances in the memory     About the work around below,      I tried: item 3(in below work around list) – result: it helps to reduce  the size of the JRTemplateElement Object                Item 4,5 – result : it helps a lot to reduce the number of  JRTemplateE…