0% found this document useful (0 votes)
32 views7 pages

Java All Codes

Uploaded by

JADEN JOSEPH
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views7 pages

Java All Codes

Uploaded by

JADEN JOSEPH
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Name: Shelton Picardo

Branch: Comp b
Roll No: 1021269

To Execute Java Program for different Input Methods.

Input:
import java.util.Scanner;
class main
{
public static void main(String[] args)
{
Scanner obj=new Scanner(System.in);
System.out.println("Enter Name,Age and Salary of Employee:");
String N=obj.nextLine();
int A=obj.nextInt();
double S=obj.nextDouble();
System.out.println("Employee Name:"+N);
System.out.println("Employee Age:"+A);
System.out.println("Employee Salary:"+S);
}
}

Output:
Name: Shelton Picardo
Branch: Comp b
Roll No: 1021269
• Program to Implement Class and Objects.
import java.util.*;
class student
{
String Name;
int rollNo;
void printName(String Name, int rollNo)
{
System.out.println("Student's Name is :"+Name);
System.out.println("Roll No : " +rollNo);
}
}
class teacher
{
String tName;
void printTName(String tName)
{
System.out.println("Teacher's Name is :"+ tName);
}
}
class stud
{
public static void main(String args[])
{
student s1 = new student();
s1.printName("Pranav Chaudhari", 1021167);
teacher t1 = new teacher();
t1.printTName("Bhakti Mam");
}
}

Output:
Name: Shelton Picardo
Branch: Comp b
Roll No: 1021269
• Program to Implement Method Overloading
import java.util.*;
class methodoverloading
{
static int add(int a,int b)
{
return a+b;
}
static int add(int a,int b,int c)
{
return a+b+c;
}
}
class overloading
{
public static void main(String[] args)
{
System.out.println(methodoverloading.add(23,25));
System.out.println(methodoverloading.add(20,10,20));
}
}
Name: Shelton Picardo
Branch: Comp b
Roll No: 1021269
• Program to Implement the Concept of Inheritance.
import java.util.*;
class parent
{
public void printa()
{
System.out.println("You are in Parent Class..!!");
}
}
class child extends parent
{
public void printb()
{
System.out.println("So now,You are in Child Class..!!");
}
}
class inheritance
{
public static void main(String[]args)
{
child c1=new child();
c1.printa();
c1.printb();
}
}

Output:
Name: Shelton Picardo
Branch: Comp b
Roll No: 1021269
• Program to Implement String Functions.
public class strlen
{
public static void main(String args[])
{
String s1="Pranav Chaudhari";
System.out.println("String length is: "+s1);
System.out.println("String length is: "+s1.length());
}
}

Output:
Name: Shelton Picardo
Branch: Comp b
Roll No: 1021269

• Program to Implement Various AWT Components.


import java.awt.*;
public class AwtApp extends Frame
{
AwtApp()
{
Label firstName = new Label("First Name");
firstName.setBounds(20, 50, 80, 20);
Label lastName = new Label("Last Name");
lastName.setBounds(20, 80, 80, 20);
TextField firstNameTF = new TextField();
firstNameTF.setBounds(120, 50, 100, 20);
TextField lastNameTF = new TextField();
lastNameTF.setBounds(120, 80, 100, 20);
Button sbmt = new Button("Submit");
sbmt.setBounds(20, 160, 100, 30);
add(firstName);
add(lastName);
add(firstNameTF);
add(lastNameTF);
add(sbmt);
setSize(300,300);
setLayout(null);
setVisible(true);
}
public static void main(String[] args)
{
AwtApp awt = new AwtApp();
}
}

Output:

You might also like