-->

Wednesday, January 22, 2014

Literals and its Types used in NetBeans part-2: Java

According to earlier article we have read about literals and some of its types used in Java Programming. We have discussed about the integer literals and floating literals, remaining are in this article.

Boolean Literals

The Boolean type has two values, represented by literals true and false formed from ASCII letters.
A Boolean literals is always of type Boolean. It is either Boolean value true or Boolean value false.

Character Literals

A character literal is one character enclosed in single quotes, e.g., ‘z’. The rule for writing character constant is given below:
A character literal in Java must contain one character and must be enclosed in single quotation marks.
Java allows you to have certain nongraphic characters in character constants. Nongraphic character are those character that cannot be typed directly from keyboard e.g. backspace, tabs, carriage return etc. these nongraphic character can be represented by using escape sequences. An escape sequence is represented by a backslash (\) followed by one or more characters.
Following table gives a listing of escape sequences:

Literals and its Types used in NetBeans: Java

In above table, you see sequences representing \, ‘ , “ and ? also. Though these character can be typed from the keyboard but when used without escape sequence, these carry a special meaning and have a special purpose, however, if these are to be typed as it is, then escape sequence should be used.

The following are the example of char literals:
Literals and its Types used in NetBeans: Java
Unicode escape are processed very early and thus must not be represented through \uHn for sequence that have their unique represented escape sequence e.g. \n or \r etc.

String literals

‘Multiple character’ constants are treated as string literals. The rule for writing string-literals is given below:
A string literals is a sequence of zero or more characters surrounded by double quotes. Each character may be represented by an escape sequence.
A string literals is of class type String. Following are legal string literals:

“abc”                              size 6bytes (each character takes 2 bytes)
“\ab”                               size 4 bytes (\a is one character)
“seema\’s pen”                size 22 bytes
(note: \a and  \’ are escape sequences)

Null Literal

The null type has one value, the null reference, represented by the literals null, which is formed from ASCII characters. A null literal is always of the null type.

Computer Programming: Control class properties, methods and events

The System.web.UI.Control class is the base class for all Web server controls. This class is derived directly from the object class, which resides in the System namespace. Here is the hierarchy of the control class:
System.Object
      System
             web.UI.Control

Public Properties of control class

AppRelativeTemplateSourceDirectory : Obtains the application-relative virtual directory of the Page or UserControl that contains this control
BindingContainer : Obtains the control that contains this control's data binding
ClientID : Obtains the server control identifier generated by ASP.NET
Controls : Obtains a ControlCollection object that represents the child controls for a specified server control in the UI hierarchy
EnableTheming : Obtains a value indicating whether themes apply to his control.
EnableViewState : Obtains a value indicating whether the server control persists its view-state, and the view-state of any child controls it contains.
ID : Obtains the programmatic identifier assigned to the server control
NamingContainer : Obtains a reference to the server control's naming container, which creates a unique namespace for differentiating between server controls with the same System.Web.UI.Control.ID property Value.
Page : Obtains a reference to the Page instance that contains the server control.
Parent : Obtains a reference to the server control's parent control in the page control hierarchy
Site : Obtains information about the container that hosts the current control when rendered on a design surface.
SkidID : Obtains the skin to apply to the control.
TemplateControl : Obtains a reference to the template that contains this control
TemplateSourceDirectory: Obtains the virtual directory of the Page or UserControl that contains the current server control.
UniqueID : Obtains the unique , hierarchically-qualified identifier for the server control.
Visible : Obtains a value that indicates whether a server control is rendered as UI on the page.

Public Method of control class

ApplyStyleSheetSkin : Helps in applying the style properties defined in the page style sheet to the control
DataBind : Helps in binding a data source to the invoked server control and all its child controls.
Dispose : Helps in enabling a server control to perform final clean up before it is released from memory.
FindControl : Helps in searching the current naming container for the specified server control.
Focus : Helps in setting input focus to a control.
HasControls : Helps in determining if the server control contains any child controls
RenderControl : Helps in output server control content and stores tracing information about the control if tracing is enabled.
ResolveClientUrl : Helps in getting a URL that can be used by the browser.
ResolveUrl : Helps in converting a URL into the desired format
SetRenderMethodDelegate : Helps in assigning an event handler delegate to render the server control and its content into its parent control.

Public Events of Control Class

DataBinding : Occurs when the server control binds to a data source
Dispose : Occurs when a server control is released from memory, which is the last stage of the server control life cycle when an ASP.NET page is requested.
Init : Occurs when the server control is initialized, which is the first step in the life cycle.
Load : Occurs when the server control is loaded into the page object.
PreRender : Occurs when the server control is about to render to its containing Page object.
Unload : Occurs when the server control is unloaded from memory.

Monday, January 20, 2014

Literals and with its Types used in NetBeans part-1: Java

In Java Programming, Literals (often referred to as constants) are data items that are fixed data values. Java allows several kinds of literals:
  • Integer-literal
  • Floating-literals
  • Boolean-literals
  • Character-literals
  • Strings-literal
  • Null literals

Integer Literals

Integer literals are whole numbers without any fractional part. The method of writing integer constants has been specified in the following rule.
An integer constant must have at least one more digit and must not contain any decimal point. It may contain either + or – sing. A number with no sing is assumed to be positive. Commas cannot appear in an integer constant.
Java allows three types of integer literals:
  • An integer literal consisting of a sequence of digit is taken to be decimal integer constant unless it begins with 0(digit zero). For instance, 1234, 41, +97,-17 are decimal integer literals.
  • A sequence of digit starting with 0(digit zero) is taken to be an octal integer. For instance decimal integer 8 will be written as 010 as octal integer (810 =108) and decimal integer 12 will be written as 014 as octal integer (1210 = 1410). But make sure that when an integer begins with 0, it must not contain 8 and 9 as these are invalid octal digits.
  • A sequence of digit preceded by 0x or OX is taken to be a hexadecimal integer. For instance decimal 12 will be written as 0XC as hexadecimal integer. But with Hexadecimal constants only 0-9 and A-F can be used. All other letters are illegal.

Floating Literals

Floating literals are also called real literals. Real literals are numbers having fractional parts. These may be written in one of the two forms called fractional form or the exponent form.

A real literal in fraction form consist of signed or unsigned digits including a decimal point between digits. The rule for writing a real constant in fraction from is given below:
A real literal in fraction form must have at least one digit before a decimal point and at last one digit after decimal point. It may also have either + or – sign preceding it. A real literal with no sign is assumed to be positive.        
Valid real literals in fraction form contains 2.0, 17.5, -13.0, -0.00625
Invalid real constants contains 7, (7.), +17/2, 250.26.2, (17,250.262)

A real literals in exponent form consists of two parts: mantissa and exponent. For instance 5.8 can be written as 0.58 X 10 = o.58E01 where mantissa part is 0.58 (the part appearing before E) and exponent part is 1(the part appearing after E). E01 represent 10 1 . The rule for writing a real literal in exponent from is given below:
A real literal in exponent from has two parts: a mantissa and an exponent. The mantissa must be either must be an integer or a proper real literal. The mantissa is followed by a letter E or e and the exponent. The exponent must be an integer.
Valid real literals in exponent form: 152E05, 1.52E07, 0,152E08, 152.0E08, 152E+8, 1520E04

Invalid real literals in exponent from:
      (i)  172.E5                    (at least a digit must follow the decimal point)
      (ii) 1.7E                         (no digit specified for exponent)
      (iii) 0.17E2.3                (exponent cannot have fraction part)
      (iv) 17,225E02             (no comma allowed)
      (v) .25E-7                      (no preceding digits before decimal point)

Continue...

Identifiers and its Naming Conventions in NetBeans: Java

In Java Programming, Identifiers are fundamental building blocks of a program and are used as the general terminology for the names given to different parts of the program viz. variables, objects, classes, function, arrays etc.

Identifier forming rules of Java state the following:

  • Identifiers can have alphabets, digits and underscores and dollar sign characters.
  • They must not be a keyword or Boolean literal or null literal.
  • They must not begin with a digit.
  • They can be any of length.
  • Java is case sensitive i.e., upper-case letters and lower-case letters are treated differently.    


The following are some valid identifiers:

Myfile                 DATE9_7_77        ZT0Z9          A_to_Z
MYFILE                _DS                  _HJI3_JK     isLetterorDIgit
_CHK                   FILE13                 αρετη         $1_to_$10

The following are some invalid identifiers:

DATA_REC             contains special character _ (other than A - Z, a – z and _or )$
29CLCT                   starting with digit
break                      reserved keyword
My.file                   contain special character.

Identifier Naming Conventions:

While making identifier names, certain convention are followed. These are:


  • The names of public methods and instance variables should begin with a lower case letter e.g. Maximum sum
  • For names having multiple words, second and subsequent words beginning character is made capital so as to enhance readability e.g. avgSalaryofEmployees, dateofBirth
  • Private and local variable should use lower case letter e.g. Width, result, final_score
  • The class names and interface names begin with an upper case letter e.g. InitialClass, Employee, and Student
  • The constant should be named using all capital letters and underscores e.g. MAX_VALUE, MAX_MARKS, SPECIAL_SALARY, and TOTAL


Sunday, January 19, 2014

About the Folders in MVC Web Application in Visual Studio: Part 2

Models folder represents the application model for your MVC application, may be called a template for the views. The classes, defined in this folder, are used to define validations of the respective field. For example username is required and password is of some length.

By default MVC application contains a single model i.e. AccountModel, having all the relative classes usable in account management. These classes may be for login, register, change password etc. A brief look about the login model is:

public class LoginModel
    {
        [Required]
        [Display(Name = "User name")]
        public string UserName { get; set; }

        [Required]
        [DataType(DataType.Password)]
        [Display(Name = "Password")]
        public string Password { get; set; }

        [Display(Name = "Remember me?")]
        public bool RememberMe { get; set; }
    }

In this class, look out the first field i.e. UserName having some validation i.e. required and display. User have to set some value to username before submit, because it is required and on the view it will be displayed as the string defined.

The second field Password, also a required field and a data type have also been defined for it. The datatype of this field is password means entered string will not be readable. Same as this model, there are register model, change password model are defined with changed fields.

Programmer can write its own models and create their views with respective validation if any. All these models will be placed in the model folder.

Tokens and its Types used in NetBeans: Java

In a passage of text, individual words and punctuation marks are called tokens. In fact, every unit that makes a sentence in Java programming is a token.
The smallest individual unit in a program is known as a Token.
Java has the following types of tokens:

Keywords

Keywords are the words that convey a special meaning to the language complier. These are reserved for special purpose and must not be used as normal identifier names.

The following character sequence, formed from ASCII letters, are reserved for use as keywords and cannot be used as identifiers:
Keywords and its Types used in NetBeans: Java
The keywords const and goto are reserved, even though they are not currently used. This may allow a Java complier to produce better error message if these Java keywords incorrectly appear in programs.

While true and false might appear to be keywords, they are technically Boolean literals. Similarly, while null might appear to be keywords, it is technically the null literal. Thus true, false and null are not keywords but reserved words.

Character Set used in NetBeans: Java Programming

Java programming have its own character set that is used by the programmers to write code easily. Character set is composed of valid characters in a language that may be any letter, digit etc.

In any language, there are some fundamentals that you need to know before you can write even the most elementary programs. This article introduce Java fundamentals to you so that you may start writing efficient code for your GUI applications.

Character set is a set of valid characters that a language can recognize. A character represent any letter, digit or any other sign. Java uses Unicode character set. Unicode is two-byte character code set that has character representing almost all character in almost all language and writing systems around the world including English, Arabic, Chinese and many more.

The first 128 character in the Unicode character set are identical to common ASCII character set. The second 128 characters are identical to the upper 128 characters of the ISOLaptin-1 extended SCII character set. Its next 65,280 that are capable of representing character of nearly all recognized of the world.

You can refer to a particular Unicode character by using the escape sequence \u followed by a four digit hexadecimal.
For example
\u00AE         ©       The copyright Symbol
\u0022          “        The double quote
\u00BD        ½        The fraction ½
\u0394        ∆         The capital Greek letter delta

You can even use the full Unicode character sequence to name your variables. However, chances are your text editor won’t be able to handle more than basic ASCII very well.

© Copyright 2013 Computer Programming | All Right Reserved