Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Java programs

public class Hello


{
public static void main(String[] args)
{
System.out.println("Hello Java");
}
}
Variable Data Types
class DataTypes
{
public static void main(String args[])
{
byte byteVar = 5;
short shortVar = 20;
int intVar = 30;
long longVar = 60;
float floatVar = 20;
double doubleVar = 20.123;
boolean booleanVar = true; char charVar ='W';
System.out.println("Value Of byte Variable is " + byteVar);
System.out.println("Value Of short Variable is " + shortVar);
System.out.println("Value Of int Variable is " + intVar);
System.out.println("Value Of long Variable is " + longVar);
System.out.println("Value Of float Variable is " + floatVar);
System.out.println("Value Of double Variable is " + doubleVar);
System.out.println("Value Of boolean Variable is " + booleanVar);
System.out.println("Value Of char Variable is " + charVar); } }
Program 1

class Phone {
final int PRICE_MIN = 999;
final int PRICE_MAX = 5600; //final variable
final void display() //final method
{
System.out.println("Min Price is" + PRICE_MIN);
System.out.println("Max Price is" + PRICE_MAX ); } }

Program 2
public class Sample
{
public static void main(String args[])
{
int a=20, b=30;
if(b>a)
System.out.println("b is greater"); } }

Program 3
public class Sample
{
public static void main(String args[])
{
int a = 80, b = 30;
if (b > a)
{
System.out.println("b is greater");
}
else
{
System.out.println("a is greater"); } } }

You might also like