Declaring Class Variables as private and Methods as public
You should declare all the class variables as private because data should always remain hidden from objects of other classes. Methods should be declared as public because the methods provide an access to the objects of the other classes.
Declaring Arrays?
Arrays can range from a higher minimum number to a higher maximum number, such as 45 to 90. It is more efficient to begin arrays with an element 0 because it takes up less memory for the compiler to store arrays that begin with 0.
If you write a Java program having the for loop that starts from array element 45 to element 90, compiler will still allocate the memory to the array starting from elements 0 to array element 45
Declaring Class Variables
You can follow Hungarian notation to declare variables in Java. The conventions followed in the Hungarian notation are as follows:
The first letter of the variable should indicate the data type used. You can use the letters, b to indicate an integer, float, or a boolean variable. For example, iAge, fPrlce, and bRest
The variable name should be meaningful. For example, iAge is an integer variable to store age of a student.
In case the variable name consists of multiple words, the first letter of each word should capital, for example iTotalMarks and fPriceOfCommodity.
Some Tips and Tricks
Displaying Text in a Java Program
You can also use the drawstring() method to display text in addition to the System.out.println method in Java. The drawstring () method require 3 arguments. The first argument represents string to be displayed on an applet. The second and third arguments represent the x and y coordinates where the string is to be displayed.
Setting CLASSPATH
Classpath is an environment variable that enables the Java compilerjavac.exe to locate class imported. You can use the set classpath= to set the classpath variable. The following syntax shows how to set classpath in Java:
set classpath= c:jdk1.5in
General Questions asked by users
Why Java is considered ideal for network communication?
Java is considered ideal for network communication because it is a platform wide pendent I Java enables an application to be executed on any network. The built-in classes of Java and TCP/IP and UDP protocols are used for network communication. Java supports the Client-Server architecture.
What will happen if the data type of a variable and the value assigned to the variable are different?
If the data type of a variable and the value assigned to the variable are different then compilation error occurs. If an Integer variable is assigned a character value, the ASCII value of the assigned character is displayed as an output. The following code shows assigning a character value to an Integer variable.
Class datatype
{
public static void main(String a[])
{
int x='b';
System.out.println (x);
}
In the preceding code, the ASCII value of the character b is displayed as 98. Similarly, if you assign a float or a double value to a character variable, an error message is displayed. The following code shows assigning a double value to a character variable:
Class datatype
{
public static void main(String a[])
{
char X= 5.5;
System.out.print(x);
}
Java is a strongly typed language and it allows the values of the specific data types, which are compatible with the type of variable.
Is it correct that all arguments sent to Java application have to be strings?
Yes, all the arguments sent to a Java application have to be string. If you use some other data type, such as int, you need to convert the value to string.
Can two variables have the same letters but different capitalization, as In varlableName and VarlableName ?
No, Java is a case-sensitive language. It differentiates the two variables, variableName and VariableName.
Published by Harsh Gupta - Tech Writer
I am a part time freelancer and writing is my hobby Some of my websites: http://www.GenericArticles.com http://www.JailBreakingiPhone.com View profile
- Java Compared to Other Computer LanguagesThis article compares the Java programming language to other programming language.
Where to Find a Technical or Community College in Orlando, FloridaIf you're interesting in getting your Associate's degree or taking evening classes in Orlando, you have a few choices for technical and community colleges in the area. Here's w...- History of Advertising and It's Affect on Popular CultureRead this and see for yourself. Do you think that America's Popular Culture is dictated by our advertising? Or just the opposite?
- Google's Keyword Tool and More Search TipsYou can use Google's Keyword Tool to find keywords related to your topic. Always remember, though, that stuffing your articles or your content with keywords is a good way to be quickly ignored by a quality search engi...
- JAVA - What You Need to Know About ItJava is the first pure object oriented language that takes into account the object oriented theory. The best feature of Java is that it is platform independent. Java programs can run on mobile phone, computers, chips,...
- How to Win Runescape Part 2: Combat Tips and Tricks
- Judge's Ruling About Warrant-less Wiretapping Mostly for Show
- A Short Introduction to Java Programming Language
- How to Take No-Cost College Classes
- The British Colonial Legacy in Modern Singapore
- Improving Home Office Technology: How to Become a Tech-savvy Person's Guide
- Courses in Applied Mathematics Can Be Found at the Boulder University of Colorado
- Java is case-sensitive language. It differentiates the two variables, variableName and VariableName
- You can also use the drawstring() method to display text in addition to the System.out.print method



