Be yourself; Everyone else is already taken.
— Oscar Wilde.
This is the first post on my new blog. I’m just getting this new blog going, so stay tuned for more. Subscribe below to get notified when I post new updates.
Be yourself; Everyone else is already taken.
— Oscar Wilde.
This is the first post on my new blog. I’m just getting this new blog going, so stay tuned for more. Subscribe below to get notified when I post new updates.
Today we are going to learn about Constructor.
What is Constructor?
Constructor is used for Initializing instance specific Information in a block and it will named as Constructor because it will construct the entire class.
How is Constructor looks?
I.Constructor has a class name but it is not class because it doesn’t have the keyword class. Note – Constructor is given a class name to shows it important.
II. It looks like method but it is not a method because there is no void keyword and no return type.
Example:
public class Sslcmarkcalculator {
public Sslcmarkcalculator(int i, int j) {
// TODO Auto-generated constructor stub
}
When the Constructor will be created?
Every time we create a Instance method Constructor will be automatically called.
Constructor will be called as Default and Parameterised constructor.
Default Constructor:
Every time we create a Instance method Constructor will be automatically called that is why we called it as Default Constructor.. But it is Invisible or hidden . Until we Pass any arguments to the Instance.
Parameterised constructor:
When we create a Instance method default constructor is already there but once we passed the inputs in the constructor it will became parameterised constructor and it is visible.
Depending upon the inputs we can create many constructor. From that we can understand constructor can be overloading.
Example:
public class Sslcmarkcalculator {
public Sslcmarkcalculator(int i, int j) {
// TODO Auto-generated constructor stub
}
public Sslcmarkcalculator(int i, int j, String string) {
// TODO Auto-generated constructor stub
}
public static void main(String[] args) {
Sslcmarkcalculator sslcobj=new Sslcmarkcalculator(90,30);
int total=sslcobj.calculatemarks();
total=sslcobj.calculategrade (total);
Sslcmarkcalculator sslcobj1=new Sslcmarkcalculator(90,30,"age");
// TODO Auto-generated method stub
}
Keyword Word- This:
This- keyword is used to indicate the Global level access for Instance variables .
Keyword – Static:
Static keyword is associated with the class level state and behavior . We can say static as common or stable (it can be changed).
Once we give static keyword in front a variable it is common for the entire class.
Example:
public class Bank {
static String Bankname= “BoB”;
static String Branchname=”Royapuram”;
String name,pancard ;
int age;
public Bank(String name, int age, String pancard) {
this.name=name;
this.age=age;
this.pancard=pancard;
}
We can also create a Static Method.
What is public static void main(String[] args)?
public static void main(String[] args) is a starting point in java.
Keyword Public- Public is a access modifier this keyword decide who can access it and form where it can be accessed it will allow the jvm to call the method even from the other class .
we already discussed Static keyword it is used for declare a variable globally.
Void:
Void means empty or nothing . Without Void method can do activity but Return something .if void is removed error shows (Return type for the method is missing ) . Keyword void can be replaced by the datatype.
Example:
public static int main(String[] args) {
System.out.println(“Please tell me no.of Subjects”);
Scanner scannerobj= new Scanner(System.in);
int no1=scannerobj.nextInt();
int no2=scannerobj.nextInt();
CCalculator calc= new CCalculator();
int result=calc.add(98,99,89,98,99);
System.out.println(“result is”+result);
return result;
Main:
Main method is a starting point of the java program.
public class Bank{
public static void main(String args[]) {
System.out.println(“Hello world”);
}
}
Today, we are going to do some pattern programs.
public static void main(String[] args) {
for(int no=1;no<=3;no++) {
for(int col=1;col<=3;col++) {
System.out.print(no);
}
System.out.println();
}
// TODO Auto-generated method stub
}}
Output:
111
222
333
public static void main(String[] args) {
for(int no=1;no<=3;no++) {
for(int col=1;col<=no;col++) {
System.out.print(no);
}
System.out.println();
}
// TODO Auto-generated method stub
}}
output:
1
22
333
public static void main(String[] args) {
for(int no=3;no>=1;no–) {
for(int col=1;col<=no;col++) {
System.out.print(no);
}
System.out.println();
}
// TODO Auto-generated method stub
}}
Output:
333
22
1
From the above Programs we can see that when we change the values differently we’ll get the output in different ways.
Hello everyone,
Today i’m gone do some basic programs in java using looping and also explain what is looping and why is it used.
Looping:
while(count<=5) {
System.out.println(a);
a=a*11;
count++;
}
In the above Program a same method is running again and again for three times. So whenever a repeated process is going on we can use Looping .
Looping is useful for time consumption and Without looping depending upon the programs we need to write lot of blocks which will do the same work using looping we can avoid that.
In Looping we have three types:
While Loop, For Loop, and Do While Loop.
While and For Loops are Entry level check whereas Do While Loop is exit level check .
while and For loops will execute only if the given conditional statement is true.
Do While it will execute the method definitely for one time and then check the conditional statement true or false to do the process again.
1.Print one,Eleven, One twenty one.(While Loop)
public class PrintOneElevanonetwentyone {
public static void main(String[] args) {
int a=1,count=1;
while(count<=5) {
System.out.println(a);
a=a*11;
count++;
}
// TODO Auto-generated method stub
}
Example Program for Do While loop;
public class Factorial54321 {
public static void main(String[] args) {
int given=5;
do {
int fact=1,no=1;
while(no<=given)
{
fact=fact*no;
no++;
}
System.out.println(fact);
given=given-1;
} while(given>0);
}
// TODO Auto-generated method stub
}
Example Program for For loop;
public class ForloopEvenno {
public static void main(String[] args) {
int no;
for(no=2;no<=10;no+=2) {
System.out.println(no);
}
// TODO Auto-generated method stub
}
}
Hello Everyone,
This is my first time in WordPress and I am quite excited about this. My first post is about basic java programs and I hope it is useful for the basic java learners.
So,lets starts Programming,
public class Oneprinted5times {
public static void main(String[] args) {
int count=1,a=1;
while(count<=5) {
System.out.println(a);
count++;
}
// TODO Auto-generated method stub
}
2.The Second Programm is about how to Print from 1 to 5 using looping method.
public class Print1to5 {
public static void main(String[] args) {
int a=1;
while(a<=5) {
System.out.println(a);
a++;
}
// TODO Auto-generated method stub
}
}
3.Now, we are going to do Program with Even numbers with Looping Method.
public class Evenno {
public static void main(String[] args) {
int no=2;
while(no<=10) {
System.out.println(no);
no+=2;
}
// TODO Auto-generated method stub
}
}
4. Done with Even number so we moved to odd numbers.
public class Oddno {
public static void main(String[] args) {
int no=1;
while(no<=10)
{
System.out.println(no);
no+=2;
}
}
}
5. Now we going Print odd and even numbers continuously.
public class Oddeven {
public static void main(String[] args) {
int no=1;
while(no<=10) {
System.out.println(no);
no+=2;
if(no==11) {
no=2;
}
}
// TODO Auto-generated method stub
}
}
This is an example post, originally published as part of Blogging University. Enroll in one of our ten programs, and start your blog right.
You’re going to publish a post today. Don’t worry about how your blog looks. Don’t worry if you haven’t given it a name yet, or you’re feeling overwhelmed. Just click the “New Post” button, and tell us why you’re here.
Why do this?
The post can be short or long, a personal intro to your life or a bloggy mission statement, a manifesto for the future or a simple outline of your the types of things you hope to publish.
To help you get started, here are a few questions:
You’re not locked into any of this; one of the wonderful things about blogs is how they constantly evolve as we learn, grow, and interact with one another — but it’s good to know where and why you started, and articulating your goals may just give you a few other post ideas.
Can’t think how to get started? Just write the first thing that pops into your head. Anne Lamott, author of a book on writing we love, says that you need to give yourself permission to write a “crappy first draft”. Anne makes a great point — just start writing, and worry about editing it later.
When you’re ready to publish, give your post three to five tags that describe your blog’s focus — writing, photography, fiction, parenting, food, cars, movies, sports, whatever. These tags will help others who care about your topics find you in the Reader. Make sure one of the tags is “zerotohero,” so other new bloggers can find you, too.