473,387 Members | 1,300 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

how to check empty condition for int field in class of java

class A
{
int k;
public void setK(int k) {
this.k = k;
}

public int getK() {
return k;
}



public static void main(String arg[])
{
int i;
A r=new A();
System.out.println(r.getK());
//output will be 0 but i want answer null becoz till now //i did not set value of int field k

}

}

i want to check that k field is set or not bt int feild in class in java is intialised by 0,so how i check that int feild is set or not???


Plzz helpppppppppp
Mar 21 '11 #1
1 5707
Dheeraj Joshi
1,123 Expert 1GB
It depends, If you are not setting k with 0 at anytime. You can write a check method which returns boolean vale. It k is equal to zero return true else return false;

Expand|Select|Wrap|Line Numbers
  1. public boolean doCheck(){
  2.       if(k == 0)
  3.           return true;
  4.       else
  5.           return false;
  6. }
  7.  
Regards
Dheeraj Joshi
Mar 21 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: linux newbie | last post by:
is there any java expert could tell me what the problem below and explain the code to me, your explanation is greatly appreciated :) static Class class$java$awt$event$ActionListener; ...
6
by: Xerxes | last post by:
Hi, how can I check if an input field in a form is defined? I create the field dynamically, so it could or could not be in the form. TIA.
4
by: Brian | last post by:
I'm pulling what's left of my hair out. I'm trying to check a memo field on opening a report. If the field has "value", I'd like to change the fields back color. If it's "Empty", I'd like to...
1
by: son | last post by:
i need some help with my database i'v got a qyery with a field orderdate from a table orders with a condition date, when a user opens a rapport from this query a popupbox is asking for the date of...
1
by: Shapper | last post by:
Hello, I need to check if a datareader field is empty. My Datareader field is given by: drProduct.Item("image02_url") How can I do this? Using drProduct.Item("image02_url") = "" is not...
3
by: AAJ | last post by:
Hi all A quick question on Datasets..... I populate a dataset from a SQL SERVER 2000 database via a data adapter. I then use the dataset to populate member variables of my class. I know the...
1
by: ahmed222too | last post by:
how can i check if a field is null using VB6 these codes donot work: If rs("lemmaid").Value is null If rs("lemmaid").Value = null If rs("lemmaid").Value =""
10
Dököll
by: Dököll | last post by:
Me again! I have been battling this one for months. Wrote below to aid in getting certain subforms to hide once checkbox named Active is clicked. I am hoping to make the code work for Date...
4
by: emtech | last post by:
In Class java.lang.VMSystem there are native methods ,can any body tell me where can I get source code for these native methods? Thanks in advance.
5
by: omar999 | last post by:
I have a CMS which displays some flight routes, alongside prices, dates which is using asp and sql server 05. works well - i.e an update on the CMS page populates the sql table and then the asp...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.