Posted on August 30, 2008 by Narayan
import javax.swing.*;
public class HelloJava {
public static void main( String[] args ) {
JFrame frame = new JFrame( “Hello Narayan!” );
JLabel label = new JLabel(“Hello Narayan!”, JLabel.CENTER );
frame.getContentPane( ).add( label );
frame.setSize( 500, 300 );
frame.setVisible( true );
}
}
Filed under: Applet | Tagged: Applet, java, javanepal | Leave a Comment »
Posted on August 30, 2008 by Narayan
public class Grading {
//attribute
private int marks;
String division;
public Grading(int marks) {
//inputing valueof marks
this.setMarks(marks);
}
//accessor methods
public void setMarks(int sm){
this.marks = sm;
}
public int getMarks(){
return marks;
}
public void setDiv(String div){
this.division = div;
}
public String getDiv(){
return this.division;
}
//now initializing the division
public void test(){
//looping for using switch
for (int x = 1; x<=5; x++){
//switch method
switch(x){
case 1:
[...]
Filed under: ABC of Object | Tagged: java, javanepal, switch, Switch method | 2 Comments »
Posted on August 23, 2008 by Narayan
public static void main(String[] args) {
int binary = 4;
int hexadecimal = 43;
//Convert the integer to binary. Stored in String.
String bin = Integer.toBinaryString(binary);
System.out.println(binary + ” as binary: ” + bin);
//Convert the second integer into hex. Stored in String.
String hex = Integer.toHexString(hexadecimal);
System.out.println(hexadecimal + ” as hex: ” + hex);
Filed under: ABC of Object | Tagged: Java Converting Number System | Leave a Comment »
Posted on August 19, 2008 by Narayan
Problem:
import java.util.*;
public class Test{
public static void main(String[] args){
ArrayList<Student> x = new ArrayList<Student>();
x.add(new Student(“Naray”));
x.add(new Student(“Gopal”));
}
}
//in student.java
public class Student {
public Student() {
}
}
Error:
Test.java . 16 cannot find symbol
symbol: constructor Student(java.lang.String)
location: class Student
x.add(new Student(“Naray”)); Test.java . 17 cannot find symbol
symbol: constructor Student(java.lang.String)
location: class Student
x.add(new Student(“Gopal”));
Solution:
make a only string accepting parameter in student constructor
Filed under: ABC of Object | Tagged: Add new tag, arraylist | 1 Comment »