0% found this document useful (0 votes)
8 views19 pages

Java Test 1

Uploaded by

niktamahadik2507
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)
8 views19 pages

Java Test 1

Uploaded by

niktamahadik2507
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

What is command line arguments

• The java command-line argument is an argument i.e. passed at the time


of running the java program.
• The arguments passed from the console can be received in the java
program and it can be used as an input.
• We need to pass the arguments as space-separated values during
running the java program
• Ex:- java add 10 20
• Class add
{
public static void main(String args[])
{
int a,b,c;
a=Integer.parseInt(args[0]);
b=Integer.parseInt(args[1]);
c=a+b;
System.out.println(“add=“+c);
}
}
Vector and its constructor
• Java Vector
• Vector is like the dynamic array which can grow or shrink its size. Unlike
array, we can store n-number of elements in it as there is no size limit.
• It is recommended to use the Vector class in the thread-safe
implementation only.
• If you don't need to use the thread-safe implementation, you should use
the ArrayList, the ArrayList will perform better in such case.
• It is similar to the ArrayList, but with two differences-
i. Vector is synchronized.
ii. Java Vector contains many legacy methods that are not the part of a
collections framework.

Syntax:-
vector vectorname= new vector();
Ex:-
vector x= new vector();
Vector and its constructor
The vector class has three constructor :
(i) public Vector():
It creates an empty vector.

(ii) public Vector(int size):

It creates a vector whose initial size is specified by


InitialCapacity.

(iii) public Vector(int size, int incr):

It creates a vector whose initial size is specified by size and


whenever it needs to grow, it grows by value specified by incr.
String and String Buffer class
Constructor overloading
public class constr
{
int a,b,c;
constr()
{
a=10;
b=20;
}
constr(int x,int y)
{
a=x;
b=y;
}
void display()
{
System.out.println("add="+(a+b));
}
public static void main(String args[])
{
constr op1,op2;
op1=new constr();
op2=new constr(20,20);
op1.display();
op2.display();
}
}
Single level Inheritance
//single inheritance
import java.util.*;
class add
{
int a,b;
Scanner s=new Scanner(System.in);
void getdata()
{
System.out.println("enter two number");
a=s.nextInt();
b=s.nextInt();
}
}
class out extends add
{
int c;
void display()
{
c=a+b;
System.out.println("add="+c);
}}
class final1
{
public static void main(String[] args)
{
out A=new out();
A.getdata();
A.display();
}
}
Multi level Inheritance
Features of Java
• Simple
• Object-Oriented
• Portable
• Platform independent
• Secured
• Robust
• Architecture neutral
• Interpreted
• High Performance
• Multithreaded
• Distributed
• Dynamic
Features of Java
What is JVM
• When we compile a .java file, .class files(contains
byte-code) with the same class names present
in .java file are generated by the Java compiler.
• -it is virtual machine that execute byte code
• JVM is a part of JRE(Java Runtime Environment).
• Java applications are called WORA (Write Once Run
Anywhere).
• Byte code are hardware/OS independent
• Use of BYTE CODE allow to run anywhere java
progran
• Every supported OS have

What is JVM
• Packages in Java are a mechanism that encapsulates a
group of classes, sub-packages, and interfaces.
Packages are used for:
• Prevent naming conflicts by allowing classes with the same
name to exist in different packages,
• They make it easier to organize, locate, and use classes,
interfaces, and other components.
• Packages also provide controlled access for Protected
members that are accessible within the same package and
by subclasses.
• Also for default members (no access specifier) that are
accessible only within the same package.
• Types of Java Packages
• Built-in Packages
• User-defined Packages
What is JVM
A. Inbuild package:-
• java.lang: Contains language support classes(e.g classes
which defines primitive data types, math operations). This
package is automatically imported.
• java.io: Contains classes for supporting input / output
operations.
• java.util: Contains utility classes which implement data
structures like Linked List, Dictionary and support ; for Date
/ Time operations.
• java.applet: Contains classes for creating Applets.
• java.awt: Contain classes for implementing the
components for graphical user interfaces (like button ,
;menus etc). 6)
• java.net: Contain classes for supporting networking
operations.
What is JVM
A. Inbuild package:-
• java.lang: Contains language support classes(e.g classes
which defines primitive data types, math operations). This
package is automatically imported.
• java.io: Contains classes for supporting input / output
operations.
• java.util: Contains utility classes which implement data
structures like Linked List, Dictionary and support ; for Date
/ Time operations.
• java.applet: Contains classes for creating Applets.
• java.awt: Contain classes for implementing the
components for graphical user interfaces (like button ,
;menus etc). 6)
• java.net: Contain classes for supporting networking
operations.
What is JVM
B.User Defined Package:-
How to create package in Java
Step 1:- First create a directory within name of
package.For ex:- my pack
Step 2:-Create a java file in newly created directory.
In this java file you must specify the package name with
the help of package keyword.
Package mypack;
Public class area{}
Save this file with same name of public class
area.java
Step 3:- Now we can use this package in your program
Import mypack.*;
abstract
• abstract is a non-access modifier in java applicable
for classes, and methods but not variables.
• It is used to achieve abstraction which is one of
the pillars of Object Oriented
Programming(OOP).
Characteristics of Java Abstract Keyword
i. Abstract classes can contain instance variables
ii. Abstract methods do not have a body
iii. Abstract classes can have constructors
iv. Abstract classes can implement interfaces:
abstract
thread
• “thread is smallest sub process/smallest unit of process”
• New State:-
- Thread is created
- Not alive
• Runnable State:-
-Calling start() method
-controlled passed to the scheduler to finish its execution.
• Running:-
- Small amount of processor time called a quantum time or slice time
- Assign thread to Processor.
• Blocked /Waiting State
-wait():- waiting for the other thread
-Sleep():- sleep for particular duration, after sleep again start excution
-wait for Hw /SW and other resources
• Dead state
-after successfully completed execution it enters into dead state.
-not alive
Not restart again
Return resources.
thread

You might also like